Sign in to follow this  
tom_mai78101

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

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
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
[quote name='tom_mai78101' timestamp='1353579136' post='5003190']
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.
[/quote]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this