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 6336343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:02:19+00:00 2026-05-24T19:02:19+00:00

Consider these two functions: Function A takes inputStream as parameter. public void processStream(InputStream stream)

  • 0

Consider these two functions:

Function A takes inputStream as parameter.

public void processStream(InputStream stream)
{
  //Do process routine
}

Function B loads a file content to pass it to Function A as InputStream.

pulic void loadFile()
{
 File file =new File("c:\\file.txt");
 //Pass file as InputStream
}

How can I pass file from Function B to Function A as InputStream without reading it on first hand?

I did something like this:

File file = new File("c:\\file.txt");
DataInputStream stream= new DataInputStream(new FileInputStream(file));

This generated the exception below:

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.io.DataInputStream

EDIT:

loadFile() is passing the InputStream as RMI response.

  • 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-05-24T19:02:21+00:00Added an answer on May 24, 2026 at 7:02 pm

    The following should work just fine

    processStream(new FileInputStream(file));
    

    You should only not attempt to serialize an InputStream instance by ObjectOutputStream like as

    objectOutputStream.writeObject(inputStream);
    

    which you’re apparently doing in processStream() method. That’s namely exactly what the exception is trying to tell you. How to solve it properly depends on the sole functional requirement which you omitted from the question.


    Update as per the comment

    I am passing the InputStream as an RMI response.

    There’s the problem. You cannot pass non-serializable objects around as RMI response, let alone unread streams. You need to read the InputStream into a ByteArrayOutputStream the usual IO way and then use its toByteArray() to get a byte[] out of it and pass that instead. Something like:

    InputStream input = new FileInputStream(file); 
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    byte[] buffer = new byte[8192];
    
    for (int length = 0; (length = input.read(buffer)) > 0;) {
        output.write(buffer, 0, length);
    }
    
    byte[] bytes = output.toByteArray(); // Pass that instead to RMI response.
    

    Be careful with large files though. Every byte of a byte[] eats one byte of JVM’s memory.

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

Sidebar

Related Questions

Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider these two classes mapped to the same table. One is readonly via mutable=false.
I ran across a compilation issue today that baffled me. Consider these two container
Consider these classes. class Base { ... }; class Derived : public Base {
I have created two arrays. I wanna pass these two array to any function.
Consider these two table: <table id=prototype style=display:none;> <tr> <td></td> <td><input type=text ></td> <td><?php echo
Consider the following method that stops a service: Public Function StopService(ByVal serviceName As String,
So here I am with this simple question Consider these two for cycles and
Consider the following: template <typename T> class testString { public: typedef T* iterator; void
Consider these 3 table structures. Which will perform these queries the best. Structure 1

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.