By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

java.io.StreamCorruptedException: invalid stream header

P: n/a
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(P IPReport.java:562)
at com.kbs.framework.client.gui.PIPReport.actionPerfo rmed(PIPReport.java:508)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(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(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn 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.pumpOneEventForHierar chy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(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.getOutputStre am());
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();
--------------------------------------------------------------
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"SubbaRao Karanam" <su************@yahoo.com> wrote in message
news:5d**************************@posting.google.c om...
What does this error for the Code below
java.io.StreamCorruptedException: invalid stream header *snip stacktrace*

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.Repor
tServlet");
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-strea
m");
ObjectOutputStream outStream =
new ObjectOutputStream(servletConnection.getOutputStre am());
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();
--------------------------------------------------------------


Compilable code is preferable. For tips on future posts, see:
http://www.physci.org/codes/sscce.jsp

From what you provided, I would assume you're attempting to use an
ObjectInputStream to receive data from a PrintWriter. How do you expect that
to work? You're getting a StreamCorruptedException because an
ObjectInputStream expects to read an object stream, i.e. the other end of an
ObjectOutputStream.
Jul 17 '05 #2

P: 1
Hi
I am trying to call the servlet's dopost method through my java program. I am supposed to give a file through my java program to the servlet and servlet has to save the same in the specified location. I was searching for the code, I found you are also trying to do the same. Please let me know whether you got any solution for your problem. Can you please post your code.

thanks in advance.

regards
Mar 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.