java.io.StreamCorruptedException: invalid stream header

Discussion in 'Java' started by SubbaRao Karanam, Feb 26, 2004.

  1. 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();
    --------------------------------------------------------------
     
    SubbaRao Karanam, Feb 26, 2004
    #1
    1. Advertising

  2. SubbaRao  Karanam

    ak Guest

    > 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.
     
    ak, Feb 26, 2004
    #2
    1. Advertising

  3. SubbaRao  Karanam

    Ryan Stewart Guest

    "ak" <> wrote in message news:c1llbe$6ku$...
    > > 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_.
    >

    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.
     
    Ryan Stewart, Feb 27, 2004
    #3
  4. Ryan Stewart wrote:
    > 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.

    --
    Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Feb 27, 2004
    #4
  5. SubbaRao  Karanam

    ak Guest

    --

    ____________

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

    "Ryan Stewart" <> schrieb im Newsbeitrag
    news:...
    > "ak" <> wrote in message news:c1llbe$6ku$...
    > > > 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_.
    > >

    > 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.
    >
    >
     
    ak, Feb 27, 2004
    #5
  6. SubbaRao  Karanam

    ak Guest

    > 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.
     
    ak, Feb 27, 2004
    #6
  7. SubbaRao  Karanam

    Ryan Stewart Guest

    "Lee Fesperman" <> wrote in message
    news:...
    > Ryan Stewart wrote:
    > > 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.
    >

    I know that, but if he posted to it, how could his server not carry it?
     
    Ryan Stewart, Feb 27, 2004
    #7
  8. SubbaRao  Karanam

    Ryan Stewart Guest

    "ak" <> wrote in message news:c1n7g4$60g$...
    > > 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.
    >

    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.
     
    Ryan Stewart, Feb 27, 2004
    #8
  9. SubbaRao  Karanam

    ak Guest

    > 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.
     
    ak, Feb 28, 2004
    #9
  10. SubbaRao  Karanam

    ak Guest

    > > 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.


    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.
     
    ak, Feb 28, 2004
    #10
  11. Ryan Stewart wrote:
    >
    > "Lee Fesperman" <> wrote in message
    > news:..
    > > Ryan Stewart wrote:
    > > > 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.
    > >

    > 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.

    --
    Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Feb 28, 2004
    #11
  12. SubbaRao  Karanam

    Ryan Stewart Guest

    "Lee Fesperman" <> wrote in message
    news:...
    > Ryan Stewart wrote:
    > >
    > > "Lee Fesperman" <> wrote in message
    > > news:..
    > > > Ryan Stewart wrote:
    > > > > 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.
    > > >

    > > 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.
    >

    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.
     
    Ryan Stewart, Feb 28, 2004
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nigel Wade
    Replies:
    10
    Views:
    849
    P.Hill
    Nov 24, 2003
  2. Bryan R. Meyer
    Replies:
    0
    Views:
    441
    Bryan R. Meyer
    Nov 22, 2003
  3. anna
    Replies:
    0
    Views:
    1,209
  4. Flavio Castelli
    Replies:
    3
    Views:
    2,942
    Roedy Green
    Jul 30, 2007
  5. tukker
    Replies:
    2
    Views:
    2,348
    Arne Vajhøj
    May 9, 2010
Loading...

Share This Page