• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

java.io. NotSerializableException: java.io.ByteArrayOutputStream

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic