This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes buffer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "buffer?" Watch "buffer?" New topic
Author

buffer?

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yes, the BufferedReader has a member variable that is an array of char.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
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

Joined: Sep 06, 2007
Posts: 635
Thanks Ernest!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: buffer?
 
Similar Threads
write to f file
What is meant by calling native API while working with Buffered streams
cleared, commited and flushed
HTTPServletResponse sendRedirect
java/input-output stream