Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:51:03+00:00 2026-06-11T18:51:03+00:00

I have a following usecase. A process serializes certain objects to a file using

  • 0

I have a following usecase.

  • A process serializes certain objects to a file using BufferedOutputStream.
  • After writing each object, process invokes flush()
  • The use case is that if the process crashes while writing an object, I want to recover the file upto the previous object that has been written successfully.

How can I deserialize such file? How will Java behave while deserializing such file.

  • Will it successfully deserialize upto the object that were written successfully before crash?
  • While reading the last partially written object, what will be the behavior. How can I detect that?

Update1 –

  • I have tried to simulate process crash via manually killing the process while objects are being written. I have tried around 10-15 times.Each time i am able to deserialize the file and file does not has any partial object.

I am not sure if my test is exhaustive enough and therefore need further advice.

Update2 – Adam had pointed a way which could simulate such test using truncating the file randomly.
Following is the behavior observed for trying out around 100 iterations –

  • From the truncated file ( which should be equivalent to the condition of file when a process crashes), Java can read upto last complete object successfully.
  • Upon reaching the last partially written object, Java does not throw any StreamCorruptedException or IOException. It simply throws EOFException indicated EOF and ignores the partial object.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:51:05+00:00Added an answer on June 11, 2026 at 6:51 pm

    Yeah, testing such scenario manually (by killing the process) may be difficult. I would suggest writing a test case, where you :

    1. Serialize a set of objects and write them to a file .
    2. Open the file and basically truncate it at random position.
    3. Try to load and deserialize (and see what happens)
    4. Repeat 1. to 3. with several other truncate positions.

    This way you are sure that you are loading a broken file and that your code handles it properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following nested objects. I am using @Valid for validation in my controller.
Using Eclipselink/MOXy 2.3 i have following usecase in marshalling to XML: abstract class MyAbstract
I have the following usecase: A div with some buttons When the user clicks
I have the following use case: I need to process a big number of
I have the following usecase: I have a java project (myProj) which uses a
Imagine a following use case: I have a dictionary of report templates. Each report
i am using requires.js 2.0. I have the following simplified use case: my HTML
I have the following use case, my file contents look like this a b
I have following use-case for marshalling a POJO to XML using Eclipselink MOXy 2.3:
I'm using JQuery-UI to display radio buttons like here . I have the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.