• Advertisement
Sign in to follow this  

There is no difference between BufferedInputStream wrapped in BufferedReader and BufferedReader reading InputStream directly?

This topic is 1887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This function returns an InputStream object.

[source lang="java"]Manager.open("C:/test.txt");[/source]

Exhibit A:

[source lang="java"]Manager assets = new Manager();
InputStream input = assets.open("C:/test.txt");
BufferedReader buffer = new BufferedReader(new InputStreamReader(input));[/source]

Exhibit B:

[source lang="java"] Manager assets = new Manager();
BufferedInputStream input = new BufferedInputStream(assets.open("C:/test.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(input));[/source]

Highly performance-wise, is there a significant difference between the two? Thanks in advance. Edited by tom_mai78101

Share this post


Link to post
Share on other sites
Advertisement
The Javadocs suggest wrapping the InputStreamReader in a BufferedReader to improve performance, which you are doing.

As far as the InputStream passed into the InputStreamReader, since the InputStream is only an interface, do you know what object
is implementing that interface? Maybe the object returned from the Manager.open() class is also a BufferedInputStream.

Either way, I would say that any savings here will be slight, and when you really do need a huge savings, use the jconsole to profile some tests and see which one is better. But until then, don't worry about it.

http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

Ciao, G.K.

Share this post


Link to post
Share on other sites
Thanks for the input.

I don't know what object is implementing that InputStream interface (It should be an abstract class, right? That's how it is with my Eclipse editor code syntax coloring...). The only thing I know of when checking the Javadoc for that Manager class, is that it only returns a final InputStream. And that's it. It doesn't say it returns a BufferedInputStream or anything.

Share this post


Link to post
Share on other sites

Thanks for the input.

I don't know what object is implementing that InputStream interface (It should be an abstract class, right? That's how it is with my Eclipse editor code syntax coloring...). The only thing I know of when checking the Javadoc for that Manager class, is that it only returns a final InputStream. And that's it. It doesn't say it returns a BufferedInputStream or anything.


It wasn't obvious to me if the Manager class was something you coded, or a library that you are using. Either way, I would say that one double buffer is enough, and leave it at that!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement