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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:31:01+00:00 2026-05-15T16:31:01+00:00

Can I easily convert InputStream to BufferedReader using Guava? I’m looking for something like:

  • 0

Can I easily convert InputStream to BufferedReader using Guava?

I’m looking for something like:

InputStream inputStream = ...;
BufferedReader br = Streams.newBufferedReader(inputStream);

I can open files using the Files.newReader(File file, Charset charset). That’s cool and I want to do the same using the InputStream.

UPDATE:

Using CharStreams.newReaderSupplier seems to verbose for me. Correct me if I’m wrong, but in order to easily convert InputStream to BufferedReader using Guava I have to do something like that:

final InputStream inputStream = new FileInputStream("/etc/fstab");
Reader bufferedReader = new BufferedReader(CharStreams.newReaderSupplier(new InputSupplier<InputStream>(){
      public InputStream getInput() throws IOException {
        return inputStream;
      }
    }, Charset.defaultCharset()).getInput());

Of course I can create helper do sth like:

return new BufferedReader(new InputStreamReader(inputStream));

However I think that such helper should be offered by Guava IO. I can do such trick for File instance. Why cannot I for InputStream?

// Guava can do this
Reader r = Files.newReader(new File("foo"), charset);
// but cannot do this
Reader r = SomeGuavaUtil.newReader(inputStream, charset);

Correct me If I’m wrong but it seems to me like lack in the API.

  • 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-15T16:31:02+00:00Added an answer on May 15, 2026 at 4:31 pm

    No, there isn’t anything quite like that in Guava. CharStreams is the general class for working with Readers and Writers and it has a method

    InputSupplier<InputStreamReader> newReaderSupplier(
        InputSupplier<? extends InputStream> in, Charset charset)
    

    which could be useful with any kind of supplier of InputStreams.

    Obviously, you can just write new BufferedReader(new InputStreamReader(in, charset)) or wrap that in your own factory method as well.

    Edit:

    Yes, you wouldn’t want to use the InputSupplier version when you already have an InputStream. It’s sort of like how it’s a bad idea to make an Iterable that can actually only work once, such as one that wraps an existing Iterator or Enumeration or some such. In general, using InputSupplier requires thinking about how you do I/O a little different, such as thinking of a File as something that can act as a supplier of FileInputStreams. I’ve used InputSuppliers that wrap whole requests to a server and return the response content as an InputStream, enabling me to use Guava utilities to copy that to a file, etc.

    In any case, I’m not entirely sure why CharStreams doesn’t have a method to create a Reader from an InputStream other than perhaps they didn’t feel it was needed. You may want to file an issue requesting this.

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

Sidebar

Related Questions

In Bash I can easily do something like command1 && command2 || command3 which
Can anybody give an example of c++ code that can easily convert a decimal
Using scons I can easily set my include paths: env.Append( CPPPATH=['foo'] ) This passes
I can easily write a string to a connection using io.WriteString. However, I can't
can you easily convert an xdocument and xelement into string to store in the
I would like my date to be YYYY-MM-DD (DD-MM-YYYY), I can't seem to convert
In the below example, how can I easily convert eventScores to List<int> so that
Possible Duplicate: How can I easily convert DataReader to List<T>? I want to put
In Ruby on Rails you can easily convert any text into a format which
Can you easily convert between ASCII characters and their Asian full-width Unicode wide characters?

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.