Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between PushbackInputStream and BufferedInputStream?  RSS feed

 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys , please help with this , what is the need of PushbackInputStream class when there is a BufferedInputStream ??? And i din't quit understand the concept of unread() !!
 
Stephan van Hulst
Saloon Keeper
Posts: 7003
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a BufferedInputStream buffers input, as its name implies. It will read chunks of data into a buffer before it returns bytes to the client.

A PushbackInputStream does no such thing. If you want to read one byte, it will read one byte. It doesn't buffer chunks. However, a PushbackInputStream provides the ability to push bytes back onto the stream, so you can re-read them. It does this by creating a buffer which it will fill with bytes you unread. Subsequent reads from the stream will then first return the unread bytes until the buffer is empty, after which it will continue to read new input as usual.

This can be useful if you first want to take a peek at the data, and then put the data back on the stream, so another method can read the stream as if nothing happened to it before.
 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much , actually am kinda confused with few java I/O classes and their implementations ....can anyone suggest me a free online source on Streams ??
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good place to start: http://download.oracle.com/javase/tutorial/essential/io/index.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!