Results 1 to 12 of 12
  1. #1
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Red face StreamCorruptedException

    Hi,

    I'm getting StreamCorruptedException while running the following code :(
    What can be the reason?Any help....

    stream = new FileInputStream(copyName);
    copy = new ObjectInputStream(stream);
    Object o = copy.readObject();//this line throwing the exception
    copy.close();
    stream.close();
    return o;
    Cristo Haris :)

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    This has to do with not flushing the stream I believe. That or appending your input stream.

    Try to stream.flush() and copy.flush() before you call readObject()
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you were able to flush an input stream you'll throw away all the data. Flushing is for output streams.

    The answer is simply that the stream is corrupted. Whatever copyName refers to, it is not a valid ObjectInputStream. If it is the target of an ObjectOutputStream then something has happened to corrupt it before you read it - a file system error or a lost packet perhaps.

    Also, as stream and copy represent the same stream, you don't need to call stream.close() after calling copy.close().
    Last edited by OrangeDog; 04-16-2009 at 02:41 PM.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  4. #4
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    The mistake will probably be in the code that's writing the object at the other end.

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    By the way-- I forgot to say, don't forget to use a BufferedInputStream-- performance of object streams is terrible otherwise.

  6. #6
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Hi,

    Quote Originally Posted by xcallmejudasx View Post
    This has to do with not flushing the stream I believe. That or appending your input stream.

    Try to stream.flush() and copy.flush() before you call readObject()
    There is no flush() method for FileInputStream & ObjectInputStream :(
    Cristo Haris :)

  7. #7
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Question StreamCorruptedException : Eclipse Ganymede(Backup and Restore)

    Hi,

    Quote Originally Posted by OrangeDog View Post
    If you flush an input stream you'll throw away all the data. Flushing is for output streams.

    The answer is simply that the stream is corrupted. Whatever copyName refers to, it is not a valid ObjectInputStream. If it is the target of an ObjectOutputStream then something has happened to corrupt it before you read it - a file system error or a lost packet perhaps.

    Also, as stream and copy represent the same stream, you don't need to call stream.close() after calling copy.close().
    Yes I agree that the stream is corrupted, but what can be the root cause for it and also a proper solution to fix it

    Let me explain the scenario which end up this exception...

    I have developed an RCP application (Using eclipse 3.3) which have backup and restore functionality. And this code was working fine.
    But recently that application was migrated to eclipse 3.4.1 (Eclipse Ganymede) and then it is throwing this exception while restoring the backups created from Eclipse 3.3 version but working fine while restoring the backups generated from Eclipse Ganymede
    Cristo Haris :)

  8. #8
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    I'm guessing that eclipse changed their classes between the versions, rendering the old backups incompatible. Serialized objects aren't guaranteed to still work if the class definitions change - you want JavaBeans for that. Possibly they didn't use or change serialVersionIDs properly. Doesn't look like there's much you can do - maybe try asking the eclipse developers?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  9. #9
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Ok... let me try with the eclipse developers...
    Cristo Haris :)

  10. #10
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by OrangeDog View Post
    I'm guessing that eclipse changed their classes between the versions, rendering the old backups incompatible. Serialized objects aren't guaranteed to still work if the class definitions change - you want JavaBeans for that. Possibly they didn't use or change serialVersionIDs properly. Doesn't look like there's much you can do - maybe try asking the eclipse developers?
    This was the reply I got from eclipse developers

    "You are using only java.io.....
    Maybe you are using a different version of java as well?
    Try to ask about this problem on the runtime newsgroup.
    Closing as not eclipse
    "

    What to do :confused:
    Cristo Haris :)

  11. #11
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    What exactly is it that you are serializing?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  12. #12
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by OrangeDog View Post
    What exactly is it that you are serializing?
    Hi,

    My issue fixed !!!!!!

    The file I was expecting was an obfustigated one, but due to some issues it was not obfustigated, found out the root cause and fixed it,

    Thank God :)

    And also thanks for all of you who have responded to this issue prombly...

    Thanks Again
    Cristo Haris :)

Similar Threads

  1. Replies: 8
    Last Post: 11-05-2010, 11:26 PM
  2. StreamCorruptedException and Casting troubles
    By Wassa in forum Networking
    Replies: 2
    Last Post: 02-18-2009, 04:07 PM
  3. java.io.StreamCorruptedException
    By elizabeth in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 07:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •