Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 575

Like
0Likes
Like

Posted 20 November 2012 - 10:29 AM

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, 20 November 2012 - 10:30 AM.


Sponsor:

#2 Glass_Knife   Moderators   -  Reputation: 4781

Like
0Likes
Like

Posted 20 November 2012 - 11:53 AM

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.
I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#3 tom_mai78101   Members   -  Reputation: 575

Like
0Likes
Like

Posted 22 November 2012 - 04:12 AM

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.

#4 Bubsy   Members   -  Reputation: 407

Like
0Likes
Like

Posted 22 November 2012 - 09:00 PM

By doing that, you'd be buffering twice ... I would advise you to just buffer on the reader.

#5 Glass_Knife   Moderators   -  Reputation: 4781

Like
0Likes
Like

Posted 23 November 2012 - 07:05 PM

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!
I think, therefore I am. I think? - "George Carlin"
Indie Game Programming




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS