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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:40:44+00:00 2026-05-12T08:40:44+00:00

This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other

  • 0

This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream
describes how to create an InputStream from OutputStream:

new ByteArrayInputStream(out.toByteArray())

Other alternatives are to use PipedStreams and new threads which is cumbersome.

I do not like the idea of copying many megabytes to new in memory byte array.
Is there a library that does this more efficiently?

EDIT:

By advice from Laurence Gonsalves, i tried PipedStreams and it turned out they are not that hard to deal with.
Here’s the sample code in clojure:

(defn #^PipedInputStream create-pdf-stream [pdf-info]
  (let [in-stream (new PipedInputStream)
        out-stream (PipedOutputStream. in-stream)]
    (.start (Thread. #(;Here you write into out-stream)))
    in-stream))
  • 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-12T08:40:45+00:00Added an answer on May 12, 2026 at 8:40 am

    If you don’t want to copy all of the data into an in-memory buffer all at once then you’re going to have to have your code that uses the OutputStream (the producer) and the code that uses the InputStream (the consumer) either alternate in the same thread, or operate concurrently in two separate threads. Having them operate in the same thread is probably much more complicated that using two separate threads, is much more error prone (you’ll need to make sure that the consumer never blocks waiting for input, or you’ll effectively deadlock) and would necessitate having the producer and consumer running in the same loop which seems way too tightly coupled.

    So use a second thread. It really isn’t that complicated. The page you linked to had reasonable example. Here’s a somewhat modernized version, which also closes the streams:

    try (PipedInputStream in = new PipedInputStream()) {
        new Thread(() -> {
            try (PipedOutputStream out = new PipedOutputStream(in)) {
                writeDataToOutputStream(out);
            } catch (IOException iox) {
                // handle IOExceptions
            }
        }).start();
        processDataFromInputStream(in);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended
I just followed the instructions from this page ( http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/ ) to setup apache
I have this page: http://mysite.org/myapp/pages/blog?name=user9 and I need to have this: user9.mysite.org What should
I have used this page http://www.binarytides.com/blog/php-redirect-go-back-to-previous-page/ to go back but from http://page.co/test.php?item=26 I post
Say, I have this page: http://www.webkit.org/blog-files/3d-transforms/morphing-cubes.html I save the page & run the html
On this page http://equals.lsri.nottingham.ac.uk/puzzle/create , if you type something into an input and then
On this page: http://www.palosverdes.com/sandbox/9slategrey/index.cfm I'm trying to put in a new menu (the one
I'm using this tutorial: http://blog.springsource.org/2011/01/04/green-beans-getting-started-with-spring-mvc/ to run a Spring MVC app using spring's tool
I used this tutorial - http://www.justwebdevelopment.com/blog/removed-shipping-address-and-shipping-method-from-onepage-checkout-in-magento/ to remove the shipping steps in one page
Consider this page @ http://www.bloodbone.ws/screwed.html I need to be able to have the a.grow

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.