java.io.StreamCorruptedException: invalid stream header

S

SubbaRao Karanam

What does this error for the Code below
----------------------------------------------------------------------
java.io.StreamCorruptedException: invalid stream header
at java.io_ObjectInputStream.readStreamHeader(Unknown Source)
at java.io_ObjectInputStream.<init>(Unknown Source)
at com.kbs.framework.client.gui.PIPReport.doProcess(PIPReport.java:562)
at com.kbs.framework.client.gui.PIPReport.actionPerformed(PIPReport.java:508)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

When I click the Button in Applet , I want it open a Dialog asking for
the excel to open/save etc... It doesnt happen why...

Though I'm writing the contents to excel , Now it doesnt create the
excel file Why....

My Applet code is
------------------------------------------------------------------------------
URL url =new URL("http://localhost:8080/portal/servlet/com.kbs.framework.client.gui.ReportServlet");

HttpURLConnection servletConnection =
(HttpURLConnection)url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);

servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestMethod("POST");
servletConnection.setRequestProperty("Content-type","application/octet-stream");

ObjectOutputStream outStream =
new ObjectOutputStream(servletConnection.getOutputStream());
outStream.writeObject(command);
outStream.flush();
outStream.close();

System.out.println("MY RESULT IN APPLET");
InputStream instr = servletConnection.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
------------------------------------------------------------------

SERVLET CODE
--------------------------------------------------------------------
public void performTask(javax.servlet.http.HttpServletRequest
request,javax.servlet.http.HttpServletResponse response)
{
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
String fileName = "temp" + Long.toString(System.currentTimeMillis())
+ ".xls";
response.addHeader("Content-Disposition", "inline; filename=\"" +
fileName
+ "\"");
InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String command = (String) inputFromApplet.readObject();
String result = submitQuery(command);
System.out.println("RESULT" + result);
out.println(command);
out.close();
--------------------------------------------------------------
 
A

ak

ObjectOutputStream outStream =
new ObjectOutputStream(servletConnection.getOutputStream());
outStream.writeObject(command);
InputStream instr = servletConnection.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
I am sure that exception is thrown here

InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String command = (String) inputFromApplet.readObject();
String result = submitQuery(command);
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
out.println(command);

applet send 'command' to servlet _as_object_,
servlet read this object and send it back _as_simple_string_,
then your applet tryes to read it _as_object_.

____________

http://reader.imagero.com the best java image reader.
 
R

Ryan Stewart

ak said:
I am sure that exception is thrown here




applet send 'command' to servlet _as_object_,
servlet read this object and send it back _as_simple_string_,
then your applet tryes to read it _as_object_.
No, that wouldn't cause a problem because a String *is* an Object. If he had
crossposted instead of multiposting, you would have seen my answer posted in
comp.lang.java. His problem is attempting to use an ObjectInputStream in his
Applet to read the output of a PrintWriter in his servlet.
 
L

Lee Fesperman

Ryan said:
No, that wouldn't cause a problem because a String *is* an Object. If he had
crossposted instead of multiposting, you would have seen my answer posted in
comp.lang.java. ...

He may not have seen it anyway. comp.lang.java is not a valid newsgroup and is not
carried by many servers.
 
A

ak

No, that wouldn't cause a problem because a String *is* an Object.

Sorry, but I didn't said "String" i said "string". String is Object and
string is just one or more chars.

____________

http://reader.imagero.com the best java image reader.
 
R

Ryan Stewart

Lee Fesperman said:
He may not have seen it anyway. comp.lang.java is not a valid newsgroup and is not
carried by many servers.
I know that, but if he posted to it, how could his server not carry it?
 
R

Ryan Stewart

ak said:
Sorry, but I didn't said "String" i said "string". String is Object and
string is just one or more chars.
Say what? You'll have to clarify. A String is a string is a String. The only
thing having to do with multiple chars without being a String would be a
char array, and that's an Object as well.
 
A

ak

Say what? You'll have to clarify. A String is a string is a String. The
only
thing having to do with multiple chars without being a String would be a
char array, and that's an Object as well.

there is difference between serializing of String object and writing some
characters to stream.

try following programm:

public class StringTest {

public static void main(String[] args) throws IOException {
String s = "1234567890";

File f1 = new File("chars");
File f2 = new File("object");

System.out.println(f1.getAbsolutePath());
System.out.println(f2.getAbsolutePath());

FileOutputStream out1 = new FileOutputStream(f1);
FileOutputStream out2 = new FileOutputStream(f2);

PrintWriter pw = new PrintWriter(out1);
ObjectOutputStream oos = new ObjectOutputStream(out2);

pw.write(s);
pw.flush();
pw.close();

oos.writeObject(s);
oos.flush();
oos.close();
}
}

content of 'chars'
1234567890

content of 'object'
’ t
1234567890

____________

http://reader.imagero.com the best java image reader.
 
A

ak

applet send 'command' to servlet _as_object_,
No, that wouldn't cause a problem because a String *is* an Object. If he had
crossposted instead of multiposting, you would have seen my answer posted in
comp.lang.java. His problem is attempting to use an ObjectInputStream in his
Applet to read the output of a PrintWriter in his servlet.

we said the same thing, but you said it better, cos my english is not the
best....

____________

http://reader.imagero.com the best java image reader.
 
L

Lee Fesperman

Ryan said:
I know that, but if he posted to it, how could his server not carry it?

Now I'm sorry I didn't give more context, but didn't the 'you' in your posting refer to
"ak" instead of the OP (SubbaRao Karanam)? Note: I don't bother with comp.lang.java, so
I don't know if "ak" posted there or not.

Of course, the OP is doubly wrong in 1) multiposting and 2) using comp.lang.java.

However, I would ask that if you aware of this and post on comp.lang.java you should
include a note about comp.lang.java being invalid (maybe you do; I'm just guessing).
c.l.j just causes extra work on valid newsgroups, like c.l.j.p.
 
R

Ryan Stewart

Lee Fesperman said:
Now I'm sorry I didn't give more context, but didn't the 'you' in your posting refer to
"ak" instead of the OP (SubbaRao Karanam)? Note: I don't bother with comp.lang.java, so
I don't know if "ak" posted there or not.
Okay, I see what you're saying. It was the OP who posted in c.l.j. ak did
not. What I was saying is that if the OP had crossposted, then my reply to
his post would have shown up here as well.
Of course, the OP is doubly wrong in 1) multiposting and 2) using comp.lang.java.

However, I would ask that if you aware of this and post on comp.lang.java you should
include a note about comp.lang.java being invalid (maybe you do; I'm just guessing).
c.l.j just causes extra work on valid newsgroups, like c.l.j.p.
No, I don't do that. Maybe I will, but I don't see that it will make any
difference. The majority of posters in c.l.j seem to be new posters who
don't know any different. There will never be a shortage of those.
Therefore, the two best choices would be 1) someone contact as many news
server administrators as possible and have them remove the group from their
server or 2) post a message every hour or half hour to the group saying not
to use the group and directing people to appropriate groups.
 

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

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top