Expose underlying inputstream and reader from httpmessage
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
@@ -126,6 +128,10 @@ public void setContent(InputStream toStreamFrom) {
this.content = toStreamFrom;
}
+ /**
+ * @deprecated There is an expectation that this class caches all input, which leads to leaks.
+ */
+ @Deprecated
public byte[] getContent() {
if (readContent == null) {
synchronized (this) {
@@ -146,6 +152,14 @@ public String getContentString() {
return new String(getContent(), getContentEncoding());
}
+ public Reader getContentReader() {
+ return new InputStreamReader(getContentStream(), getContentEncoding());
+ }
+
+ public InputStream getContentStream() {
+ return new ByteArrayInputStream(getContent());
+ }
+
/**
* Get the underlying content stream, bypassing the caching mechanisms that allow it to be read
* again.
