aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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