public class ByteArrayStream extends RandomAccessStream
If you plan to read or write huge amount of data, consider using the CompressedByteArrayStream class instead.
CompressedByteArrayStreampos, SEEK_CUR, SEEK_END, SEEK_SETskipBuffer| Constructor and Description |
|---|
ByteArrayStream(byte[] buffer)
Creates a ByteArrayStream.
|
ByteArrayStream(byte[] buffer,
int len)
Creates a ByteArrayStream.
|
ByteArrayStream(int size)
Creates a ByteArrayStream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes available in the buffer from the actual read position.
|
void |
close()
does nothing.
|
int |
count()
Deprecated.
use
getPos() instead. |
byte[] |
getBuffer()
Gets the internal buffer used.
|
int |
getPos()
Returns the current offset in this stream.
|
void |
mark()
Sets the current position as the maximum size of the buffer so that no
more than the current written data will be read.
|
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the stream.
|
void |
readFully(Stream inputStream,
int retryCount,
int bufSize)
Reads all data from the input stream into our buffer.
|
void |
reset()
Resets the position to 0 so the buffer can be reused, and sets the mark to the buffer real limits.
|
int |
reuse()
Reuses the already read part of the buffer.
|
void |
setBuffer(byte[] buffer)
Sets the buffer to be used, resetting the current position.
|
void |
setPos(int newPos)
Sets the file pointer for read and write operations to the given position.
|
void |
setPos(int offset,
int origin)
Sets the file pointer for read and write operations to a new position defined by adding offset to a reference
position specified by origin.
|
void |
setSize(int newSize,
boolean copyOldData)
Sets the size of the current byte array.
|
int |
skipBytes(int n)
Moves the cursor n bytes from the current position, moving backwards if n is negative, or forward if n is
positive.
The cursor cannot be placed outside the stream limits, stopping at position 0 when moving backwards, or at the last position of the stream, when moving forward. |
byte[] |
toByteArray()
Returns a copy of the data inside this buffer.
|
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the stream.
|
asInputStream, asOutputStream, asStream, asStream, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytespublic ByteArrayStream(byte[] buffer)
buffer - The initial buffer from where data will be read or written into.public ByteArrayStream(byte[] buffer,
int len)
buffer - The initial buffer from where data will be read or written into.len - The length to read from the buffer.public ByteArrayStream(int size)
size - The initial size that the byte array will have.public void mark()
reset()public int available()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic byte[] getBuffer()
count()public void setBuffer(byte[] buffer)
buffer - the new internal buffer.@Deprecated public int count()
getPos() instead.public int getPos()
RandomAccessStreamgetPos in class RandomAccessStreampublic int readBytes(byte[] buf,
int start,
int count)
Streampublic void reset()
mark()public int skipBytes(int n)
public int reuse()
public int writeBytes(byte[] buf,
int start,
int count)
StreamIOException if an error prevented the write
operation from occurring.writeBytes in class Streambuf - the byte array to write data fromstart - the start position in the byte arraycount - the number of bytes to writepublic void setSize(int newSize,
boolean copyOldData)
newSize - the new array sizecopyOldData - If true, the old data up to pos is copied into the new buffer.public byte[] toByteArray()
public void setPos(int offset,
int origin)
throws IOException
RandomAccessStreamsetPos in class RandomAccessStreamoffset - number of bytes to offset from origin.origin - position from where offset is added. It is specified by one of the SEEK_* constants.IOException - if the new position is negative or if an I/O error occurs.public void setPos(int newPos)
throws IOException
RandomAccessStreamsetPos in class RandomAccessStreamnewPos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.IOException - if pos is negative or if an I/O error occurs.public void readFully(Stream inputStream, int retryCount, int bufSize) throws IOException
inputStream - The input stream from where data will be readretryCount - The number of times to retry if no data is read. In remote
connections, use at least 5; for files, it can be 0.bufSize - The size of buffer used to read data.IOException