|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectat.spardat.xma.util.ByteArray
Implements an efficient, growing byte array. The array may have an optional header that consumes the first 5 bytes. The first 4 bytes reserve place for the total length, the 5th byte indicates if this is compressed or not.
| Nested Class Summary | |
class |
ByteArray.ByteArrayOS
Inner nested class to write to the end of the buffer by using an OutputStream interface. |
| Field Summary | |
static int |
HEADER_LEN
Length of the header |
| Constructor Summary | |
ByteArray(byte[] array)
Constructor that constructs by providing the array from outside. |
|
ByteArray(byte[] array,
int length)
Constructor that constructs by providing the array from outside. |
|
ByteArray(int initialSize)
Constructs with an internal buffer of size initialSize. |
|
| Method Summary | |
void |
addHeader()
Adds header at the beginning of this. |
static void |
dump(byte[] data)
Writes hex-dump to System.out. |
static void |
dump(byte[] data,
int len,
java.io.PrintWriter pw)
Writes a hex-dump of data to the given printwriter. |
byte |
get()
Returns the byte at the current position and increments the position indicator. |
byte[] |
getBuffer()
Returns the internally stored byte array. |
byte[] |
getBytes()
Returns a copy of the bytes stored in this. |
ByteArray |
getCompressed()
Creates a new ByteArray by compressing the contents of this. |
int |
getLengthInHeader()
Returns the length stored in the header. |
java.io.OutputStream |
getOutputStream()
Returns an OutputStream that allows to append to this. |
int |
getPosition()
Returns current position |
byte |
getRel(int offset)
Returns the byte at (position+offset) without changing the current position. |
ByteArray |
getUncompressed()
Creates a new ByteArray by uncompressing the contents of this. |
boolean |
hasHeader()
Indicates if this has a header. |
boolean |
hasRemaining()
Returns true if there are bytes from the current position until the end. |
boolean |
isCompressed()
Returns if the stream is compressed. |
void |
readFrom(java.io.InputStream in)
Reads all bytes from the provided inputstream in until an EOF or an error is detected and stores the bytes at the end of this buffer. |
void |
readFrom(java.io.InputStream in,
int maxSize)
Reads bytes from the provided inputstream in until either EOF or the size of this is maxSize. |
int |
remaining()
Returns the number of bytes from the current position until the end. |
void |
reset()
All accumulated output in this is discarded. |
void |
rewind()
Current position is set to zero. |
void |
set(byte[] b,
int srcOffset,
int srcLen,
int dstOffset)
Extracts srcLen bytes at offset srcOffset from b and copies them to the offset dstOffset in this. |
void |
setComputeHeaderLength(boolean value)
Forces the header to indicate the length of this or not. |
void |
setHeader(boolean what)
Sets the header-status of this. |
void |
setPosition(int pos)
Sets the current position to the provided index. |
int |
size()
Returns how many bytes this ByteArray stores. |
void |
write(byte[] b)
Appends all bytes from b to this byte array. |
void |
write(byte[] b,
int off,
int len)
Appends len bytes from the specified byte array
starting at offset off to this byte array. |
void |
write(int b)
Appends the specified byte to the end of this byte array |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int HEADER_LEN
| Constructor Detail |
public ByteArray(int initialSize)
public ByteArray(byte[] array)
public ByteArray(byte[] array,
int length)
| Method Detail |
public int size()
public void write(int b)
b - the byte to be appended
public void write(byte[] b,
int off,
int len)
len bytes from the specified byte array
starting at offset off to this byte array.
b - the data.off - the start offset in the data.len - the number of bytes to write.public void write(byte[] b)
public void set(byte[] b,
int srcOffset,
int srcLen,
int dstOffset)
public void reset()
public byte[] getBuffer()
public byte[] getBytes()
public void readFrom(java.io.InputStream in)
throws java.io.IOException
in - input stream to read from
java.io.IOException
public void readFrom(java.io.InputStream in,
int maxSize)
throws java.io.IOException
in - input stream to read frommaxSize - maximum size of this
java.io.IOExceptionpublic byte get()
public byte getRel(int offset)
public void setPosition(int pos)
public void rewind()
public int getPosition()
public int remaining()
public boolean hasRemaining()
public static void dump(byte[] data,
int len,
java.io.PrintWriter pw)
public static void dump(byte[] data)
public java.io.OutputStream getOutputStream()
public boolean hasHeader()
public void addHeader()
public void setHeader(boolean what)
public void setComputeHeaderLength(boolean value)
java.lang.IllegalStateException - is not hasHeader()public int getLengthInHeader()
java.lang.IllegalStateException - if this does not have a headerpublic boolean isCompressed()
public ByteArray getCompressed()
public ByteArray getUncompressed()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||