de.intarsys.tools.randomaccess
public class RandomAccessByteArray extends AbstractRandomAccess
Modifier and Type | Field and Description |
---|---|
protected byte[] |
data
The byte array data
|
protected int |
length
The number of valid bytes in the byte array
|
Constructor and Description |
---|
RandomAccessByteArray(byte[] buffer) |
RandomAccessByteArray(byte[] buffer,
int length) |
Modifier and Type | Method and Description |
---|---|
protected void |
basicSetLengthResize(int newLength) |
void |
close()
Closes this random access data container and releases any system
resources associated with the stream.
|
void |
flush()
Force changes to be made persistent.
|
protected byte[] |
getData() |
long |
getLength()
Returns the length of this data container.
|
long |
getOffset()
Returns the current offset in this data container.
|
boolean |
isReadOnly()
true if this is a read only data container. |
int |
read()
Reads a byte of data from this data container.
|
int |
read(byte[] buffer)
Reads up to
buffer.length bytes of data from this data
container into an array of bytes. |
int |
read(byte[] buffer,
int bufferOffset,
int numBytes)
Reads up to
len bytes of data from this data container into
an array of bytes. |
void |
seek(long pOffset)
Sets the offset, measured from the beginning of the data container at
which the next read or write occurs.
|
void |
seekBy(long delta)
Sets the offset, measured from the current offset at which the next read
or write occurs.
|
void |
setLength(long newLength)
Assign the length.
|
byte[] |
toByteArray() |
void |
write(byte[] buffer)
Writes
b.length bytes from the specified byte array,
starting at the current offset. |
void |
write(byte[] buffer,
int start,
int numBytes)
Writes
len bytes from the specified byte array starting at
start . |
void |
write(int b)
Writes the specified byte .
|
asInputStream, asOutputStream, getPositionStack, mark, reset
protected byte[] data
protected int length
public RandomAccessByteArray(byte[] buffer)
public RandomAccessByteArray(byte[] buffer, int length)
protected final void basicSetLengthResize(int newLength)
public void close() throws java.io.IOException
IRandomAccess
java.io.IOException
- if an I/O error occurs.public void flush() throws java.io.IOException
IRandomAccess
java.io.IOException
protected byte[] getData()
public long getLength() throws java.io.IOException
IRandomAccess
java.io.IOException
- if an I/O error occurs.public long getOffset()
IRandomAccess
public boolean isReadOnly()
IRandomAccess
true
if this is a read only data container.true
if this is a read only data container.public int read()
IRandomAccess
0x00-0x0ff
). This method
blocks if no input is yet available.
This method behaves in exactly the same way as the
InputStream.read()
method of InputStream
.
-1
if the end of the data
container has been reached.public int read(byte[] buffer)
IRandomAccess
buffer.length
bytes of data from this data
container into an array of bytes. This method blocks until at least one
byte of input is available.
This method behaves in the exactly the same way as the
InputStream.read(byte[])
method of InputStream
.
buffer
- the buffer into which the data is read.-1
if there is no more data because the end of this
data container has been reached.public int read(byte[] buffer, int bufferOffset, int numBytes)
IRandomAccess
len
bytes of data from this data container into
an array of bytes. This method blocks until at least one byte of input is
available.
buffer
- the buffer into which the data is read.bufferOffset
- the start offset of the data.numBytes
- the maximum number of bytes read.-1
if there is no more data because the end of the
file has been reached.public void seek(long pOffset) throws java.io.IOException
IRandomAccess
pOffset
- the offset position, measured in bytes from the beginning of
the data containerjava.io.IOException
- if offset
is less than 0
or if
an I/O error occurs.public void seekBy(long delta) throws java.io.IOException
IRandomAccess
delta
- the amount of bytes by which to change the current offset
positionjava.io.IOException
- if the resulting offset
is less than
0
or if an I/O error occurs.public void setLength(long newLength)
IRandomAccess
public byte[] toByteArray()
public void write(byte[] buffer)
IRandomAccess
b.length
bytes from the specified byte array,
starting at the current offset.buffer
- the data.public void write(byte[] buffer, int start, int numBytes)
IRandomAccess
len
bytes from the specified byte array starting at
start
.buffer
- the data.start
- the start offset in the data.numBytes
- the number of bytes to write.public void write(int b)
IRandomAccess
b
- the byte
to be written.