File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java.io. NotSerializableException:  java.io.ByteArrayOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java.io. NotSerializableException:  java.io.ByteArrayOutputStream" Watch "java.io. NotSerializableException:  java.io.ByteArrayOutputStream" New topic
Author

java.io. NotSerializableException: java.io.ByteArrayOutputStream

S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
Hi all,

I am doing an RMI call from my Servlet and in the backend i prepare all the data into am ByteArrayOutputStream and add it into a vector and send it back.

It gives my an " java. io.NotSerializableException: java.io.ByteArrayOutput Stream"
I found out that the ByteArrayOutputStream must be serialized before putting into my vector.

I tried browsing on the internet but could'nt get it right.

Please let me know on how to do it.

**********My code in the servlet*******
serverData = remoteServiceObject. doRemoteRequestProcess(clientRequest); System.err.println("serverData>>>>"+serverData.size());
ByteArrayOutputStream pdfReportStream = (ByteArrayOutputStream)serverData.get(0);
***********************************

************MY backend Code****************
public Vector processClientRqst(Vector eClientRequest)
throws Exception {
int methodID = Integer.parseInt (eClientRequest.elementAt(1).toString().trim());
Vector responseData = new Vector();
switch (methodID) {
case SRSConstant.GET_REPORT:
System.err.println("INSIDE DBIS>>>>>>>>>>>");
responseData = getTBQReport(eClientRequest);
break;
}

return (responseData);
}

public Vector getTBQReport(Vector clientData) throws Exception {
String sql;
plantID = clientData.elementAt(2).toString();
issueID = clientData.elementAt(3).toString();
modelYear = clientData.elementAt(4).toString();

Vector serverData = new Vector();

TAVReportGenerator reportGenerator = new TAVReportGenerator(dbConn,srCommMethods);
ByteArrayOutputStream pdfReportStream = reportGenerator.generatePDF(issueID, modelYear, plantID);

serverData.add(pdfReportStream);

return serverData;
}
**************************************

Thanks,

With Regards,
Vivek Raju
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
That class does not implement the Serializable interface, like all IO classes that I know of. Which does make sense.

The bottom line is you can not serialize it. You can mark it as transient so when you serialize the object, the JVM doesn't complain. You will have to handle restoring it after it is deserialized.


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Since you can't possibly serialize an OutputStream, I'm guessing that what you would want to do here is get the data that's been written to the OutputStream. Since you've got a ByteArrayOutputStream, you can just close() the stream and then call toByteArray() - which gives you , surprise, a byte[] array. You should probably do this inside the generatePDF() method, and return the byte[] from that method. Then you can put the byte[] into your Vector, and serialize it.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io. NotSerializableException: java.io.ByteArrayOutputStream
 
Similar Threads
Jakarta Commons FileUpload and Servlets
Design Question?
Issue with BatchExection of CallableStatement with StoredProcedures in DB2
list empty using s:select tag with Struts 2
Problem in writing concatenated byteArray to a PDF file