From: bugbear on
Tom Anderson wrote:
> On Tue, 27 Jul 2010, bugbear wrote:
>
>> I've looked in the standard libraries, and Apache.
>>
>> I want a Reader (or Stream) that provides a view onto PART of an
>> existing Reader (or Stream) defined by an offset and a size.
>>
>> Such an implementation would be very useful to me, e.g. for decoding
>> some JPEG data (using a standard JPEG stream decoder) where the JPEG
>> is actually held as a sub-set of some other file (e.g. the thumbnail
>> for a giant TIFF image).
>>
>> Does anyone know of such a class/library?
>
> If i've understood you correctly, then i think this may be of use to you:
>
> http://commons.apache.org/fileupload/apidocs/org/apache/commons/fileupload/util/LimitedInputStream.html
>
>
> This is a moderately common thing to need, and since it's not in the
> standard library, there are dozens of other implementations of it
> around, mostly with the same name!
>
> It's also not hard to write if you don't want to drag in another
> library. You just write a FilterInputStream with a count of bytes
> remaining, and implement read() and read(byte[], int, int) to check the
> count and behave accordingly. And override the mark/reset methods to
> respect the count, or do nothing.

But I also want an offset, which makes things harder.

I know how to code it - back in my career I've coded it in both
C and C++.

But (like any Good Boy) I was trying to avoid re-inventing the wheel.

BugBear
From: Lew on
bugbear wrote:
> But I also want an offset, which makes things harder.
>
> I know how to code it - back in my career I've coded it in both
> C and C++.
>
> But (like any Good Boy) I was trying to avoid re-inventing the wheel.

Good thing there's
<http://java.sun.com/javase/6/docs/api/java/io/RandomAccessFile.html>
thrn.

--
Lew