public class SeekableInMemoryByteChannel extends Object implements SeekableByteChannel
SeekableByteChannel implementation that wraps a byte[].
When this channel is used for writing an internal buffer grows to accommodate
incoming data. A natural size limit is the value of Integer.MAX_VALUE.
Internal buffer can be accessed via array().
| Constructor and Description |
|---|
SeekableInMemoryByteChannel()
Parameterless constructor - allocates internal buffer by itself.
|
SeekableInMemoryByteChannel(byte[] data)
Constructor taking a byte array.
|
SeekableInMemoryByteChannel(int size)
Constructor taking a size of storage to be allocated.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Obtains the array backing this channel.
|
void |
close() |
boolean |
isOpen() |
long |
position() |
SeekableByteChannel |
position(long newPosition) |
int |
read(ByteBuffer buf) |
long |
size() |
SeekableByteChannel |
truncate(long newSize) |
int |
write(ByteBuffer b) |
public SeekableInMemoryByteChannel(byte[] data)
This constructor is intended to be used with pre-allocated buffer or when reading from a given byte array.
data - input data or pre-allocated array.public SeekableInMemoryByteChannel()
public SeekableInMemoryByteChannel(int size)
Creates a channel and allocates internal storage of a given size.
size - size of internal buffer to allocate, in bytes.public long position()
position in interface SeekableByteChannelpublic SeekableByteChannel position(long newPosition) throws IOException
position in interface SeekableByteChannelIOExceptionpublic long size()
size in interface SeekableByteChannelpublic SeekableByteChannel truncate(long newSize)
truncate in interface SeekableByteChannelpublic int read(ByteBuffer buf) throws IOException
read in interface ReadableByteChannelread in interface SeekableByteChannelIOExceptionpublic void close()
public int write(ByteBuffer b) throws IOException
write in interface SeekableByteChannelwrite in interface WritableByteChannelIOExceptionCopyright © 2018 The Apache Software Foundation. All rights reserved.