SeekableByteChannel implementation that wraps a byte[].
When this channel is used for writing an internal buffer grows to accommodate incoming data. The natural size limit is the value of Integer#MAX_VALUE
and it is not possible to set the position or truncate to a value bigger than that. Internal buffer can be accessed
via SeekableInMemoryByteChannel#array().
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicBoolean | |
| private byte[] | |
| private static final int | |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SeekableInMemoryByteChannel(final byte[]
input data or pre-allocated array. data)Constructs a new instance from a byte array. |
| public | SeekableInMemoryByteChannel(final int
size of internal buffer to allocate, in bytes. size)Constructs a new instance from a size of storage to be allocated. |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | |
| public void | |
| private void | |
| public boolean | |
| public long | position()
Implements java. |
| public SeekableByteChannel | position(final long
The new position, a non-negative integer counting
the number of bytes from the beginning of the entity newPosition)Implements java. |
| public int | read(final ByteBuffer
The buffer into which bytes are to be transferred buf)Implements java. |
| private void | |
| public long | size()
Implements java. |
| public SeekableByteChannel | truncate(final long
The new size, a non-negative byte count newSize)Implements java. |
| public int | write(final ByteBuffer
The buffer from which bytes are to be retrieved b)Implements java. |
| closed | back to summary |
|---|---|
| private final AtomicBoolean closed | |
| data | back to summary |
|---|---|
| private byte[] data | |
| NAIVE_RESIZE_LIMIT | back to summary |
|---|---|
| private static final int NAIVE_RESIZE_LIMIT | |
| position | back to summary |
|---|---|
| private int position | |
| size | back to summary |
|---|---|
| private int size | |
| SeekableInMemoryByteChannel | back to summary |
|---|---|
| public SeekableInMemoryByteChannel() Constructs a new instance using a default empty buffer. | |
| SeekableInMemoryByteChannel | back to summary |
|---|---|
| public SeekableInMemoryByteChannel(final byte[] data) Constructs a new instance from a byte array. This constructor is intended to be used with pre-allocated buffer or when reading from a given byte array.
| |
| SeekableInMemoryByteChannel | back to summary |
|---|---|
| public SeekableInMemoryByteChannel(final int size) Constructs a new instance from a size of storage to be allocated. Creates a channel and allocates internal storage of a given size.
| |
| array | back to summary |
|---|---|
| public byte[] array() Obtains the array backing this channel. Note The returned buffer is not aligned with containing data, use
| |
| close | back to summary |
|---|---|
| public void close() Implements java. Doc from java. Closes this channel. After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a If this channel is already closed then invoking this method has no effect. This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
| |
| ensureOpen | back to summary |
|---|---|
| private void ensureOpen() throws ClosedChannelException | |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() Implements java. Doc from java. Tells whether or not this channel is open.
| |
| position | back to summary |
|---|---|
| public long position() Implements java. Returns this channel's position.
This method violates the contract of
| |
| position | back to summary |
|---|---|
| public SeekableByteChannel position(final long newPosition) throws IOException Implements java. Doc from java. Sets this channel's position. Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified. Setting the channel's position is not recommended when connected to
an entity, typically a file, that is opened with the
| |
| read | back to summary |
|---|---|
| public int read(final ByteBuffer buf) throws IOException Implements java. Doc from java. Reads a sequence of bytes from this channel into the given buffer. Bytes are read starting at this channel's current position, and
then the position is updated with the number of bytes actually read.
Otherwise this method behaves exactly as specified in the
| |
| resize | back to summary |
|---|---|
| private void resize(final int newLength) | |
| size | back to summary |
|---|---|
| public long size() Implements java. Returns the current size of entity to which this channel is connected.
This method violates the contract of
| |
| truncate | back to summary |
|---|---|
| public SeekableByteChannel truncate(final long newSize) Implements java. Truncates the entity, to which this channel is connected, to the given size.
This method violates the contract of
| |
| write | back to summary |
|---|---|
| public int write(final ByteBuffer b) throws IOException Implements java. Doc from java. Writes a sequence of bytes to this channel from the given buffer. Bytes are written starting at this channel's current position, unless
the channel is connected to an entity such as a file that is opened with
the
| |