public class SeekableInMemoryByteChannel
extends java.lang.Object
implements java.nio.channels.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() |
java.nio.channels.SeekableByteChannel |
position(long newPosition) |
int |
read(java.nio.ByteBuffer buf) |
long |
size() |
java.nio.channels.SeekableByteChannel |
truncate(long newSize) |
int |
write(java.nio.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 java.nio.channels.SeekableByteChannelpublic java.nio.channels.SeekableByteChannel position(long newPosition)
throws java.io.IOException
position in interface java.nio.channels.SeekableByteChanneljava.io.IOExceptionpublic long size()
size in interface java.nio.channels.SeekableByteChannelpublic java.nio.channels.SeekableByteChannel truncate(long newSize)
truncate in interface java.nio.channels.SeekableByteChannelpublic int read(java.nio.ByteBuffer buf)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChannelread in interface java.nio.channels.SeekableByteChanneljava.io.IOExceptionpublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelpublic boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic int write(java.nio.ByteBuffer b)
throws java.io.IOException
write in interface java.nio.channels.SeekableByteChannelwrite in interface java.nio.channels.WritableByteChanneljava.io.IOExceptionpublic byte[] array()
NOTE:
The returned buffer is not aligned with containing data, use
size() to obtain the size of data stored in the buffer.
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"