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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:13:17+00:00 2026-06-13T03:13:17+00:00

I have a file containing java objects , wrote with this code: from(somewhere).process(new Processor()

  • 0

I have a file containing java objects, wrote with this code:

     from(somewhere).process(new Processor() {

          @Override
          public void process(final Exchange exchange) {
              ...
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ObjectOutput out = new ObjectOutputStream(bos);
              out.writeObject(myObject);
              exchange.getOut().setBody(bos.toByteArray());
          }
     }).to("file://pathFile");

And now, I want read them fastly. I don’t know how can I do that, something like the following code I gess.

from("file://pathFile").convertBodyTo(String.class)

.split(body().tokenize("???")) // How can I tokenize my file ?

.streaming().threads(2)

.process(new Processor() {

      @Override
      public void process(final Exchange exchange) {
        String filePath = (String) exchange.getIn().getHeader(Exchange.FILE_PATH);
        File file = new File(filePath);
        MyObject myObject = null;
        try {
          FileInputStream fis = new FileInputStream(file);
          InputStream buffer = new BufferedInputStream(fis);
          ObjectInput input = new ObjectInputStream(buffer);

          Object obj = null;
          while ((obj = input.readObject()) != null) {
              // Do something
              myObject = obj;
          }

        } catch (Exception e) {
            ...
        } finally {
          ...
        }
        exchange.getIn().setBody(myObject);
      }
}).to(somewhere);

EDIT: I edit my way to read object. There is still a problem with that code, we can’t append to an ObjectOutputStream. That will corrupt the stream. There is a solution [here] for this problem. We can only write the stream header one time.

But If I do that, I wont be able to split and read my file with multiple threads. So can I split or access my file on ObjectOutputStream header ?

  • 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-13T03:13:17+00:00Added an answer on June 13, 2026 at 3:13 am

    you just converted it to a String using convertBodyTo(String.class), therefore you have a String in the body rather than an InputStream….

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

Sidebar

Related Questions

I have a file containing some lines of code followed by a string pattern.
I have a file containing some data (for example, 00927E2B112DB958......). This data is a
I have a java properties file containing a key/value pair of country names and
I have a simple jar file containing class A : public class A {}
I have seen examples containing things like this: mountSharedResource(/images/logo.gif, new ResourceReference(ImageScope.class, logo.gif).getSharedResourceKey()); mountSharedResource(/resource, Application.class.getName()
I have a java file containing more than one class, out of which one
ANyone know whats wrong with this code for creating a zip file containing a
I have a sql-file containing several statements like this: create table user ( name
Say I have a binary file (generated with Java) containing a 32 bit int
I have 1 text file containing Ips .Like this iptextfile.txt 10.0.0.1 192.168.1.1 123.123.123.123 And

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.