### Question:
StreamReader implements Reader { public String readStreamIntoString(Charset charset) throws IOException { ByteBuffer buf = readStreamIntoBuffer(); return new String(buf.array(), 0, buf.limit(), charset); } StreamReader(InputStream stream);  StreamReader(InputStream stream, int contentLength);  StreamReader(InputStream stream, int estimatedContentLength, int maxContentLength); InputStream copyStream(OutputStream outStream); @Override ByteBuffer readStreamIntoBuffer(); @Override ByteBuffer readStreamIntoBuffer(ByteBuffer buffer); String readStreamIntoString(Charset charset); void readStreamToOutputStream(OutputStream outStream);  }### Answer:
@Test public void testReadStreamIntoString() throws IOException { String testString = "I know what I am and I'm glad I'm a man, and so is Lola."; final byte[] bytes = testString.getBytes(StringUtilities.DEFAULT_CHARSET); InputStream is = new InputStream() { private int myPosition; @Override public int read() throws IOException { if (myPosition == bytes.length) { return -1; } return bytes[myPosition++]; } @Override public synchronized void reset() throws IOException { myPosition = 0; } }; Assert.assertEquals(testString, new StreamReader(is).readStreamIntoString(StringUtilities.DEFAULT_CHARSET)); is.reset(); Assert.assertEquals(testString, new StreamReader(is, 1, -1).readStreamIntoString(StringUtilities.DEFAULT_CHARSET)); is.reset(); Assert.assertEquals(testString, new StreamReader(is, testString.length() - 1, -1).readStreamIntoString(StringUtilities.DEFAULT_CHARSET)); is.reset(); Assert.assertEquals(testString, new StreamReader(is, testString.length(), -1).readStreamIntoString(StringUtilities.DEFAULT_CHARSET)); is.reset(); Assert.assertEquals(testString, new StreamReader(is, testString.length() + 1, -1).readStreamIntoString(StringUtilities.DEFAULT_CHARSET)); }