}
public void testViewHandlerResponseWrapperStreamIO() throws Exception {
ViewHandlerResponseWrapper w1 =
new ViewHandlerResponseWrapper(getResponse());
ServletOutputStream os = w1.getOutputStream();
os.write('1');
try {
w1.getWriter();
assertTrue(false);
} catch (IllegalStateException ise) {
// expected
}
os.flush();
os.close();
PrintWriter writer = null;
try {
writer = w1.getWriter();
} catch (IllegalStateException ise) {
assertTrue(false);
}
// we've closed the stream - and should have a fake
// writer. Ensure writing to it doesn't impact the result;
writer.print("Some junk");
StringWriter buf = new StringWriter();
w1.flushToWriter(buf, "ISO-8859-1");
assertTrue(!buf.toString().contains("Some junk"));
// ensure that the content that was written to the stream is
// present
assertTrue("1".equals(buf.toString()));
w1 = new ViewHandlerResponseWrapper(getResponse());
os = w1.getOutputStream();
// flushBuffer should commit the response so getWriter()
// should throw no Exception
w1.flushBuffer();
try {
w1.getWriter();
} catch (IllegalStateException ise) {
assertTrue(false);
}
}