SharedByteArrayInputStreampublic class SharedByteArrayInputStream extends ByteArrayInputStream implements SharedInputStreamA ByteArrayInputStream that implements the SharedInputStream interface,
allowing the underlying byte array to be shared between multiple readers. |
Fields Summary |
---|
protected int | startPosition within shared buffer that this stream starts at. |
Constructors Summary |
---|
public SharedByteArrayInputStream(byte[] buf)Create a SharedByteArrayInputStream representing the entire
byte array.
super(buf);
| public SharedByteArrayInputStream(byte[] buf, int offset, int length)Create a SharedByteArrayInputStream representing the part
of the byte array from offset for length
bytes.
super(buf, offset, length);
start = offset;
|
Methods Summary |
---|
public long | getPosition()Return the current position in the InputStream, as an
offset from the beginning of the InputStream.
return pos - start;
| public java.io.InputStream | newStream(long start, long end)Return a new InputStream representing a subset of the data
from this InputStream, starting at start (inclusive)
up to end (exclusive). start must be
non-negative. If end is -1, the new stream ends
at the same place as this stream. The returned InputStream
will also implement the SharedInputStream interface.
if (start < 0)
throw new IllegalArgumentException("start < 0");
if (end == -1)
end = count - this.start;
return new SharedByteArrayInputStream(buf,
this.start + (int)start, (int)(end - start));
|
|