• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

OptionalDataException....???

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I was trying to read an arraylist from an inputstream... which was sent by servlet to my swing client... During this it threw a OptionalDataException on my Tomcat console.. I know that When I am try to read the object when the next element in the stream is premitive data type then this excepion is generates.. But I don't get exact idea that why this is happening b'cz I am only trying to read an arraylist .. and there is no premitive data type..

Waiting for your reply,
Regards,
Siddharth
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's two reasons for this exception:


# An attempt was made to read an object when the next element in the stream is primitive data. In this case, the OptionalDataException's length field is set to the number of bytes of primitive data immediately readable from the stream, and the eof field is set to false.
# An attempt was made to read past the end of data consumable by a class-defined readObject or readExternal method. In this case, the OptionalDataException's eof field is set to true, and the length field is set to 0.


Java Doc for OptionalDataException
So if you want to check for the particular cause, you can examine the eof and length fields.
Are you reading the array list with a single readObject() call?
 
Siddharth Ramavat
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply,

Yes, you are right then I am using single readObject() to read the arraylist. But actually what happned that before reading the arraylist I was reading the boolean value from the stream.. so now after reading it I want to clear the input sream . so is there any method like flush() or something with the inputstream so I can flush out the boolean value and then going for reading array list..

Waiting for your reply,

Regards,
Siddharth
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no "flush" for incoming data. Once you read it, it's gone.
Are you reading a Boolean or a boolean?
Did you try checking the length and eof fields of the exception?
reply
    Bookmark Topic Watch Topic
  • New Topic