Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

buffer?

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A buffered input stream fills a buffer with data that hasn’t been handled yet. When a program
needs this data, it looks to the buffer first before going to the original stream
source.Buffered byte streams use the BufferedInputStream and BufferedOutputStream
classes.


Buffered Reader Class (java.io.*)
A buffer stores keys from the InputStreamReader it in an allocated memory area called a buffer.
Your program will read characters from the buffer rather than directly from the device. This relieves
the input device from being accessed every time data is required from the program.


Are these Buffer same? Is this the same buffer that if fills too much make "Buffer Overflow"?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "buffer" is a general concept; it's not one specific memory location, or anything like that. BufferedReader, BufferedInputStream, etc, each have an array inside which acts as the buffer for that object. Your operating system will maintain its own buffers for various purposes.

"Buffer overflow" means that there is more data to be stored than will fit in the fixed-sized buffer being used in some particular situation. It could arise in many different contexts.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedReader, BufferedInputStream, etc, each have an array inside which acts as the buffer for that object.





You mean in above code, When BufferedReader object is created, Is an array create inside it that saves data?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the BufferedReader has a member variable that is an array of char.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You realise there is a potential error in your reading? You are not closing the Reader when you have finished with it. You should close Readers and Writers in finally blocks, so as to ensure they are closed whether an Exception occurs or not.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic