java.io.StreamCorruptedException: invalid stream header

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SubbaRao  Karanam

    #1

    java.io.StreamCorruptedException: invalid stream header

    What does this error for the Code below
    java.io.StreamC orruptedExcepti on: invalid stream header
    at java.io.ObjectI nputStream.read StreamHeader(Un known Source)
    at java.io.ObjectI nputStream.<ini t>(Unknown Source)
    at com.kbs.framewo rk.client.gui.P IPReport.doProc ess(PIPReport.j ava:562)
    at com.kbs.framewo rk.client.gui.P IPReport.action Performed(PIPRe port.java:508)
    at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
    at javax.swing.Abs tractButton$For wardActionEvent s.actionPerform ed(Unknown
    Source)
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown
    Source)
    at java.awt.Compon ent.processMous eEvent(Unknown Source)
    at java.awt.Compon ent.processEven t(Unknown Source)
    at java.awt.Contai ner.processEven t(Unknown Source)
    at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
    at java.awt.EventD ispatchThread.p umpOneEventForH ierarchy(Unknow n
    Source)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.r un(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.framewo rk.client.gui.R eportServlet");

    HttpURLConnecti on servletConnecti on =
    (HttpURLConnect ion)url.openCon nection();
    servletConnecti on.setDoInput(t rue);
    servletConnecti on.setDoOutput( true);

    servletConnecti on.setUseCaches (false);
    servletConnecti on.setDefaultUs eCaches(false);
    servletConnecti on.setRequestMe thod("POST");
    servletConnecti on.setRequestPr operty("Content-type","applicat ion/octet-stream");

    ObjectOutputStr eam outStream =
    new ObjectOutputStr eam(servletConn ection.getOutpu tStream());
    outStream.write Object(command) ;
    outStream.flush ();
    outStream.close ();

    System.out.prin tln("MY RESULT IN APPLET");
    InputStream instr = servletConnecti on.getInputStre am();
    ObjectInputStre am inputFromServle t = new ObjectInputStre am(instr);
    String result = (String) inputFromServle t.readObject();
    inputFromServle t.close();
    instr.close();
    ------------------------------------------------------------------

    SERVLET CODE
    --------------------------------------------------------------------
    public void performTask(jav ax.servlet.http .HttpServletReq uest
    request,javax.s ervlet.http.Htt pServletRespons e response)
    {
    response.setCon tentType("appli cation/vnd.ms-excel");
    PrintWriter out = response.getWri ter();
    String fileName = "temp" + Long.toString(S ystem.currentTi meMillis())
    + ".xls";
    response.addHea der("Content-Disposition", "inline; filename=\"" +
    fileName
    + "\"");
    InputStream in = request.getInpu tStream();
    ObjectInputStre am inputFromApplet = new ObjectInputStre am(in);
    String command = (String) inputFromApplet .readObject();
    String result = submitQuery(com mand);
    System.out.prin tln("RESULT" + result);
    out.println(com mand);
    out.close();
    --------------------------------------------------------------
  • Ryan Stewart

    #2
    Re: java.io.StreamC orruptedExcepti on: invalid stream header

    "SubbaRao Karanam" <subbarao_india @yahoo.com> wrote in message
    news:5d88580c.0 402252117.2849f 069@posting.goo gle.com...[color=blue]
    > What does this error for the Code below
    > java.io.StreamC orruptedExcepti on: invalid stream header[/color]
    *snip stacktrace*[color=blue]
    >
    >
    > 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
    > --------------------------------------------------------------------------[/color]
    ----[color=blue]
    > URL url =new[/color]
    URL("http://localhost:8080/portal/servlet/com.kbs.framewo rk.client.gui.R epor
    tServlet");[color=blue]
    >
    > HttpURLConnecti on servletConnecti on =
    > (HttpURLConnect ion)url.openCon nection();
    > servletConnecti on.setDoInput(t rue);
    > servletConnecti on.setDoOutput( true);
    >
    > servletConnecti on.setUseCaches (false);
    > servletConnecti on.setDefaultUs eCaches(false);
    > servletConnecti on.setRequestMe thod("POST");
    >[/color]
    servletConnecti on.setRequestPr operty("Content-type","applicat ion/octet-strea
    m");[color=blue]
    >
    > ObjectOutputStr eam outStream =
    > new ObjectOutputStr eam(servletConn ection.getOutpu tStream());
    > outStream.write Object(command) ;
    > outStream.flush ();
    > outStream.close ();
    >
    > System.out.prin tln("MY RESULT IN APPLET");
    > InputStream instr = servletConnecti on.getInputStre am();
    > ObjectInputStre am inputFromServle t = new ObjectInputStre am(instr);
    > String result = (String) inputFromServle t.readObject();
    > inputFromServle t.close();
    > instr.close();
    > ------------------------------------------------------------------
    >
    > SERVLET CODE
    > --------------------------------------------------------------------
    > public void performTask(jav ax.servlet.http .HttpServletReq uest
    > request,javax.s ervlet.http.Htt pServletRespons e response)
    > {
    > response.setCon tentType("appli cation/vnd.ms-excel");
    > PrintWriter out = response.getWri ter();
    > String fileName = "temp" + Long.toString(S ystem.currentTi meMillis())
    > + ".xls";
    > response.addHea der("Content-Disposition", "inline; filename=\"" +
    > fileName
    > + "\"");
    > InputStream in = request.getInpu tStream();
    > ObjectInputStre am inputFromApplet = new ObjectInputStre am(in);
    > String command = (String) inputFromApplet .readObject();
    > String result = submitQuery(com mand);
    > System.out.prin tln("RESULT" + result);
    > out.println(com mand);
    > out.close();
    > --------------------------------------------------------------[/color]

    Compilable code is preferable. For tips on future posts, see:


    From what you provided, I would assume you're attempting to use an
    ObjectInputStre am to receive data from a PrintWriter. How do you expect that
    to work? You're getting a StreamCorrupted Exception because an
    ObjectInputStre am expects to read an object stream, i.e. the other end of an
    ObjectOutputStr eam.


    Comment

    • meena
      New Member
      • Mar 2006
      • 1

      #3
      Solution

      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

      Comment

      Working...