• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ObjectOutputStream appending to a file overiding ObjectOutputStream  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi as i can see there are lot of post on the same . still i am not able to achive the Appending of objects in a file . i want to Append objects to a single file . It cannot be done in the same session.(same OOS object ) i have tried Overriding writeheader method of the class ObjectOutputStream still facing the same error . you guys look at the code and figure out where i am Amiss ..
Also i want to know how the object is written to file ?
--header
Object
--footer(EOF)
because if a footer exists appending an object should be done before EOF?

first iteration i get java.io.EOFException while reading
second itertaion( writing and reading again )
I am called
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at ProductHelper.getProductsByID(ProductHelper.java:31)
at ProductHelper.getAllProducts(ProductHelper.java:19)
at HomeLoad.doGet(HomeLoad.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)



Ankit
 
Ranch Hand
Posts: 3091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My quick guess is that you are breaking writeStreamHeader() by overriding it to do nothing useful. It does have a job to to, and you are telling it to forget about that job, and do something else. Try this instead:

 
Ankit Sood
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike : the reason I have overriden the function is that I do not want the header to be written again(when file is alredy existing ) .. If we are calling super method only then no need to override in first place.
 
Marshal
Posts: 60163
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Mike Simmons has good reasons for making that suggestion. Please try it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!