How to read from a ServletOutputstream?

T

Timo Nentwig

Timo said:
How can I read what I just wrote to a ServletOutputStream?

Or, in other word, why does the following snipped print
"??????????????????????????????" to my browser and what about binary data:

Reader rr = new StringReader( resp.getWriter().toString() );
Writer w = resp.getWriter();
for( int c = -1; rr.read() != -1; ) w.write( c );
 
T

Tor Iver Wilhelmsen

Timo Nentwig said:
for( int c = -1; rr.read() != -1; ) w.write( c );

This writes a -1 for each character read. Are you sure you don't want
to assign to c?

for( int c = -1; (c = rr.read()) != -1; ) w.write( c );
 
T

Timo Nentwig

Tor said:
This writes a -1 for each character read. Are you sure you don't want
to assign to c?

for( int c = -1; (c = rr.read()) != -1; ) w.write( c );

Good point :) But this doesn't solve the problem anyway.
 
K

Kerry Sanders

This writes a -1 for each character read. Are you sure you don't want
to assign to c?

for( int c = -1; (c = rr.read()) != -1; ) w.write( c );


He wouldn't want to do that, would he? That would blow the increment variable
used in the for loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top