wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes How to design/implement Reader with peek functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to design/implement Reader with peek functionality" Watch "How to design/implement Reader with peek functionality" New topic
Author

How to design/implement Reader with peek functionality

Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I need to implement a Reader which will periodically need to peek ahead at some of the data while reading it. As I see it, there are two ways I could implement this:

1. Using a mark(), read(), and reset() paradigm
2. Using a PushbackReader in which I read the data, and then unread() it

I was wondering if people had some input (no pun indented) as to any significant pros or cons of the two paradigms. Obviously with the first I need an underlying reader that supports marking -- I would likely use a BufferedReader. With the second I need to know ahead of time the largest number of characters I need to peek at so I can create the PushbackReader with a large enough buffer. That's not a problem. Other than those differences, I am hard pressed to see any pros or cons either way. Just as some more information, the reader will need to peek at 2 or 3 characters sometimes, and blocks of up to 200 characters at other times.

Thoughts?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to design/implement Reader with peek functionality
 
Similar Threads
java program automatically chooses the default in switch on the next loop
InputStream to multiple Readers
Data loss during file transfer
How to implement a Object pool in java
Byte vs Character streams