public class ByteChannelOutputStream extends Object implements EXROutputStream
SeekableByteChannel
.
This class assumes that the SeekableByteChannel
specified during
its construction will remain open through the lifetime of an instance.
Constructor and Description |
---|
ByteChannelOutputStream(SeekableByteChannel channel)
Constructs a
ByteChannelOutputStream which relies on a non-null,
already open SeekableByteChannel . |
Modifier and Type | Method and Description |
---|---|
long |
position()
Get the current writing position, in bytes from the beginning of the
stream.
|
EXROutputStream |
position(long pos)
Set the current position.
|
void |
write(ByteBuffer src)
Write to the stream.
|
public ByteChannelOutputStream(SeekableByteChannel channel)
ByteChannelOutputStream
which relies on a non-null,
already open SeekableByteChannel
.channel
- the SeekableByteChannel
to be used by the
newly constructed instanceNullPointerException
- is channel
is nullIllegalArgumentException
- is channel
is not openpublic void write(ByteBuffer src) throws EXRIOException
EXROutputStream
write(dst)
writes n bytes to the stream, where
n is the number of bytes remaining in the buffer, that is,
dst.remaining()
, at the moment this method is invoked. The bytes
are written from the current position of the buffer.
If an I/O error occurs, write(dst)
throws an exception.
write
in interface EXROutputStream
src
- The buffer from which bytes are to be transferredEXRIOException
- if an I/O error occurs.public long position() throws EXRIOException
EXROutputStream
write()
will write the first byte in
the stream, position()
returns 0.position
in interface EXROutputStream
EXRIOException
- if an I/O error occurs.public EXROutputStream position(long pos) throws EXRIOException
EXROutputStream
position(i)
,
position()
returns i.position
in interface EXROutputStream
pos
- the new writing position.EXRIOException
- if an I/O error occurs.