posted 17 years ago
[Bharath]: Can i expect a better preformance?
Probably. It looks like the biggest problem is whenever you do s read that does not return 0x47 - you just keep doing single reads, one byte at a time. This is usually slow; it's better to read many bytes at once. That's what your BufferedInputStream is doing for you, behind the scenes. Would it make sense to read, say, a block of 187 bytes instead? Or even 1870? Or more? I bet that would be much faster. You will probably want to use the readFully() method.
[Bharath]: And as for pushbackstream, from the docs i dont see how it can fit my need, can you please through some more light on this?
Well, I don't really know how or why you need to "re-process the bytes that [you] have already processed". When you need to go backwards, how far back to you need to go? Is there a limit? And how often do you need to do this, anyway?
PushbackInputStream allows you to put bytes back into the stream after reading them (using unread()), essentially restoring the stream to an earlier state before you read the bytes. But you're limited in that you can only put the bytes back if you still have that data in memory, typically in an array. If that fits your problem, great; if not, never mind.
Ultimately, using mark() and reset() is probably better than PushbackInputStream. But it will only work if you never need to move back more than some finite number of bytes (which will be kept in memory). If you are at the end of a 3 GB file and need to go back to the beginning, that's too much to possibly fit in memory, so forget it.
[Bharath]: And my file is not markable, why? i don't know, may be they have some constraints for a file to be markable.
Markability is not a property of a file; it's a property of a stream. If you look at the API for various InputStream types, you will see that a FileInputStream is not ever markable (isMarkable() returns false), but a BufferedInputStream is, always. I suspect you tried marking with the FileInputStream; try marking the BufferedInputStream instead.
[ December 20, 2007: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister