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

  • Home
  • SEARCH
  • 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 8821827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:56:59+00:00 2026-06-14T05:56:59+00:00

I am trying to test a program and for that I need to access

  • 0

I am trying to test a program and for that I need to access ReadExternal function but I am getting StreamCorrupted exception on ObjectInputStream.
I know I need to use the object written by WriteObject but dont know how to do it…

ObjectOutputStream out=new ObjectOutputStream(new ByteArrayOutputStream());
    out.writeObject(ss3); 
    ss3.writeExternal(out);
    try{
         ByteInputStream bi=new ByteInputStream();
         bi.setBuf(bb);
         out.write(bb);
         ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bb));
         String s1=(String) in.readObject();
        }
        catch(Exception e){
            e.printStackTrace();
        }
  • 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-14T05:57:00+00:00Added an answer on June 14, 2026 at 5:57 am

    Apparently, you are trying to write the same object twice to the output stream:

    out.writeObject(ss3); 
    ss3.writeExternal(out); // <-- Remove this!
    

    The second write makes wrong use of the writeExternal() method, which should never be called explicitly but will be called by the ObjectOutputStream.

    And: out.write(bb); tries to write the content of bb to the ObjectOutputStream. That’s probably not what you want.

    Try it like this:

    // Create a buffer for the data generated:
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    
    ObjectOutputStream out=new ObjectOutputStream( bos );
    
    out.writeObject(ss3);
    
    // This makes sure the stream is written completely ('flushed'):
    out.close();
    
    // Retrieve the raw data written through the ObjectOutputStream:
    byte[] data = bos.toByteArray();
    
    // Wrap the raw data in an ObjectInputStream to read from:
    ByteArrayInputStream bis = new ByteArrayInputStream( data );
    ObjectInputStream in = new ObjectInputStream( bis );
    
    // Read object(s) re-created from the raw data:
    SomeClass obj = (SomeClass) in.readObject();
    
    assert obj.equals( ss3 ); // optional ;-)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to build a simple test program that uses atomic operations, I get
My program is trying to create an key on the HKLM\Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\ but instead
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I am just trying to compile and run a very simple test program, but
I'm writing this program that will need to access the registry to pull some
I'm writing a test program that use a Tab Controller with multiple tab views.
I know that there are similar threads but after spending an hour trying to
I am trying to test whether a c program has compiled and executed correctly
I'm trying to write a program to test student code against a good implementation.

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.