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.SeekableByteChannel
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
position
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public long size()
size
in interface java.nio.channels.SeekableByteChannel
public java.nio.channels.SeekableByteChannel truncate(long newSize)
truncate
in interface java.nio.channels.SeekableByteChannel
public int read(java.nio.ByteBuffer buf) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
read
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public int write(java.nio.ByteBuffer b) throws java.io.IOException
write
in interface java.nio.channels.SeekableByteChannel
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public 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. All Rights Reserved