Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by tom_mai78101 Nov 20, 2012 at 4:29 PM 3 replies 1.8k views
Original Post
tom_mai78101
tom_mai78101
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.
Glass_Knife
Glass_Knife
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.
tom_mai78101
tom_mai78101
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.
Bruno Sofiato
Bruno Sofiato
By doing that, you'd be buffering twice ... I would advise you to just buffer on the reader.
Glass_Knife
Glass_Knife

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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.