public class ByteBufferInputStream extends InputStream
InputStream
that reads from an existing ByteBuffer
.
Will reposition the buffer at construction, and read sequentially from that
point. Attempting to read past the buffer's limit will return end-of-file.
Warnings:
Because this class explicitly repositions the buffer, you should not create
two instances around the same buffer; slice()
the buffer
instead. Instances of this class are only as thread-safe as the underlying
buffer (and the JavaDocs don't have much to say about that).
Constructor and Description |
---|
ByteBufferInputStream(ByteBuffer buf)
Creates an instance that positions the stream at the start of the
buffer.
|
ByteBufferInputStream(ByteBuffer buf,
int off)
Creates an instance that positions the stream at the specified offset.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
public ByteBufferInputStream(ByteBuffer buf)
public ByteBufferInputStream(ByteBuffer buf, int off)
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public void reset() throws IOException
reset
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException