public class ByteArrayHandle extends AbstractNIOHandle
IRandomAccess
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
buffer
Backing ByteBuffer.
|
protected static int |
INITIAL_LENGTH
Initial length of a new file.
|
EOF_ERROR_MSG
Constructor and Description |
---|
ByteArrayHandle()
Creates a random access byte stream to write to a byte array.
|
ByteArrayHandle(byte[] bytes)
Creates a random access byte stream to read from, and
write to, the bytes specified by the byte[] argument.
|
ByteArrayHandle(ByteBuffer bytes)
Creates a random access byte stream to read from, and
write to, the supplied ByteBuffer.
|
ByteArrayHandle(int capacity)
Creates a random access byte stream to read from, and write to.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this random access stream and releases
any system resources associated with the stream.
|
ByteBuffer |
getByteBuffer()
Gets the byte buffer backing this handle.
|
byte[] |
getBytes()
Gets a byte array representing the current state of this ByteArrayHandle.
|
long |
getFilePointer()
Returns the current offset in this stream.
|
ByteOrder |
getOrder()
Returns the current order (endianness) of the stream.
|
long |
length()
Returns the length of this stream.
|
int |
read(byte[] b)
Reads up to b.length bytes of data
from this stream into an array of bytes.
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this stream into an array of bytes.
|
int |
read(ByteBuffer buf)
Reads up to buffer.capacity() bytes of data
from this stream into a ByteBuffer.
|
int |
read(ByteBuffer buf,
int off,
int len)
Reads up to len bytes of data from this stream into a ByteBuffer.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
seek(long pos)
Sets the stream pointer offset, measured from the beginning
of this stream, at which the next read or write occurs.
|
void |
setLength(long length)
Sets the new length of the handle.
|
void |
setOrder(ByteOrder order)
Sets the byte order (endianness) of the stream.
|
int |
skipBytes(int n) |
long |
skipBytes(long n)
A
long variant of DataInput.skipBytes(int) . |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given
ByteBuffer to this stream.
|
void |
write(ByteBuffer buf,
int off,
int len)
Writes up to len bytes of data from the given ByteBuffer to this
stream.
|
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(String s) |
void |
writeChar(int v) |
void |
writeChars(String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(String str) |
exists, validateLength, validateMode
protected static final int INITIAL_LENGTH
protected ByteBuffer buffer
public ByteArrayHandle(byte[] bytes)
bytes
- byte array to work withpublic ByteArrayHandle(ByteBuffer bytes)
bytes
- ByteBuffer used for reading and writingpublic ByteArrayHandle(int capacity)
capacity
- Number of bytes to initially allocate.public ByteArrayHandle()
public byte[] getBytes()
public ByteBuffer getByteBuffer()
public void setLength(long length) throws IOException
AbstractNIOHandle
setLength
in class AbstractNIOHandle
length
- New length.IOException
- If there is an error changing the handle's length.public void close()
IRandomAccess
public long getFilePointer()
IRandomAccess
public long length()
IRandomAccess
public int read(byte[] b) throws IOException
IRandomAccess
b
- the array to fill from this streamIOException
- if reading is not possiblepublic int read(byte[] b, int off, int len) throws IOException
IRandomAccess
b
- the array to fill from this streamoff
- the offset in b
from which to start filling;
expected to be non-negative and no greater than
b.length - len
len
- the number of bytes to read; expected to be positive and
no greater than b.length - offset
IOException
- if reading is not possiblepublic int read(ByteBuffer buf) throws IOException
IRandomAccess
buf
- the ByteBuffer to fill from this streamIOException
- if reading is not possiblepublic int read(ByteBuffer buf, int off, int len) throws IOException
IRandomAccess
buf
- the ByteBuffer to fill from this streamoff
- the offset in b
from which to start filling;
expected to be non-negative and no greater than
buffer.capacity() - len
len
- the number of bytes to read; expected to be positive and
no greater than buffer.capacity() - offset
IOException
- if reading is not possiblepublic void seek(long pos) throws IOException
IRandomAccess
pos
- new byte offset (pointer) in the current stream.
Unless otherwise noted, may be larger or smaller than the
current pointer, but must be non-negative and less than the
value of #length()IOException
- if pos
is invalid or the seek failsIRandomAccess.getFilePointer()
public ByteOrder getOrder()
IRandomAccess
public void setOrder(ByteOrder order)
IRandomAccess
order
- Order to set.public boolean readBoolean() throws IOException
IOException
public byte readByte() throws IOException
IOException
public char readChar() throws IOException
IOException
public double readDouble() throws IOException
IOException
public float readFloat() throws IOException
IOException
public void readFully(byte[] b) throws IOException
IOException
public void readFully(byte[] b, int off, int len) throws IOException
IOException
public int readInt() throws IOException
IOException
public String readLine() throws IOException
IOException
public long readLong() throws IOException
IOException
public short readShort() throws IOException
IOException
public int readUnsignedByte() throws IOException
IOException
public int readUnsignedShort() throws IOException
IOException
public String readUTF() throws IOException
IOException
public int skipBytes(int n) throws IOException
IOException
public long skipBytes(long n) throws IOException
IRandomAccess
long
variant of DataInput.skipBytes(int)
.n
- the number of bytes to skipIOException
- if the operation failedpublic void write(byte[] b) throws IOException
IOException
public void write(byte[] b, int off, int len) throws IOException
IOException
public void write(ByteBuffer buf) throws IOException
IRandomAccess
buf
- the ByteBuffer containing bytes to write to this streamIOException
- if writing is not possiblepublic void write(ByteBuffer buf, int off, int len) throws IOException
IRandomAccess
buf
- the ByteBuffer containing bytes to write to this streamoff
- the offset in b
from which to start writing;
expected to be non-negative and no greater than
buf.capacity() - len
len
- the number of bytes to write; expected to be positive and
no greater than buf.capacity() - offset
IOException
- if writing is not possiblepublic void write(int b) throws IOException
IOException
public void writeBoolean(boolean v) throws IOException
IOException
public void writeByte(int v) throws IOException
IOException
public void writeBytes(String s) throws IOException
IOException
public void writeChar(int v) throws IOException
IOException
public void writeChars(String s) throws IOException
IOException
public void writeDouble(double v) throws IOException
IOException
public void writeFloat(float v) throws IOException
IOException
public void writeInt(int v) throws IOException
IOException
public void writeLong(long v) throws IOException
IOException
public void writeShort(int v) throws IOException
IOException
public void writeUTF(String str) throws IOException
IOException
Copyright © 2005–2022 Open Microscopy Environment. All rights reserved.