File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Outputstream, IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Outputstream, IllegalStateException" Watch "Outputstream, IllegalStateException" New topic
Author

Outputstream, IllegalStateException

Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hello,
I am downloading a file from the server and saving it to the client disk.
He makes it but gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"
I don't know what's the problem since i close it.
Here is the code
"FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();"
Can you help me?
Thanks
Claudia
S.Hamid
Greenhorn

Joined: Dec 28, 2001
Posts: 4
Originally posted by Claudia Vaz:
Hello,
I am downloading a file from the server and saving it to the client disk.
He makes it but gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"
I don't know what's the problem since i close it.
Here is the code
"FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();"
Can you help me?
Thanks
Claudia

Hi
If u write
FileOutputStream output=new FileOutputStream();instead of OutputStream outStream = res.getOutputStream();

Your problem maybe solved

No Path of Flowers Lead to Glory
Jerome Lumpkin
Greenhorn

Joined: Aug 28, 2001
Posts: 10
Isn't this really caused by trying to get another output stream long after the JSP (compiled servlet) has already allocated an output stream.
The solution would be to use the "out" object to download your data or code this as a servlet where you have control of where and how the output stream is instantiated.
Jerome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Outputstream, IllegalStateException