|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.ROByteArray
public final class ROByteArray
An immutable, Serializable, wrapper for a byte array. This enables byte array data to be safely shared between multiple users, thus avoid copies and duplicates.
We clone at entry and exit and deserialisation to protect our internal data.
This also has helper methods for storing/extracting (with zlib) lossless-compressed String values. (The internal form is deflated UTF-8 without headers or checksum.)
These instances are suitable for pooling with MemoryTools.intern().
Intended to be efficient on the wire and in memory.
| Field Summary | |
|---|---|
static ROByteArray |
EMPTY
Empty array. |
private static java.lang.String |
HEX_DIGITS
The set of characters from which we produce our hex digits. |
private byte[] |
payload
The (non-null) payload reference. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
| Constructor Summary | |
|---|---|
ROByteArray(byte[] data)
Construct with (copy of) non-null data block. |
|
| Method Summary | |
|---|---|
static ROByteArray |
compressFromString(java.lang.String in)
Create an instance from the compressed UTF-8 form of the argumentString. |
boolean |
equals(java.lang.Object obj)
Is equal to an instance with a payload of the same length and content; may be slow to compute. |
static ROByteArray |
fromHexString(java.lang.String s)
Creates instance from a hex representation as generated by toHexString(). |
byte |
get(int index)
Get value at specified index. |
byte[] |
getData(int start,
int afterEnd)
Get (a copy of) a portion of the data block. |
java.io.InputStream |
getInputStream()
Get internal data as InputStream (supporting mark()). |
int |
hashCode()
Compute a hash based on the length and some of the payload. |
int |
length()
Get length of the data; non-negative. |
protected java.lang.Object |
readResolve()
Deserialise: use constructor for validation, defensive copying, etc. |
byte[] |
toByteArray()
Get (a copy of) the entire data block; never null. |
java.lang.String |
toHexString()
Returns a fixed-length unsigned lower-case hex representation of the data. |
java.lang.String |
toString()
Returns a human-readable representation of this object. |
static java.lang.String |
uncompressToString(ROByteArray in)
Extract a String from an ROByteArray created by compressFromString(); never null. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private final byte[] payload
private static final java.lang.String HEX_DIGITS
public static final ROByteArray EMPTY
private static final long serialVersionUID
| Constructor Detail |
|---|
public ROByteArray(byte[] data)
data - non-null array of bytes| Method Detail |
|---|
public byte[] toByteArray()
public byte[] getData(int start,
int afterEnd)
public int length()
public byte get(int index)
public int hashCode()
This takes a fixed small number of sample points whose relative positions partly depend on the length, and the length itself is part of the hash.
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.io.InputStream getInputStream()
Each call produces a completely independent stream.
public java.lang.String toHexString()
For example, a data array containing { 13, 241 } would produce "0df1".
public static ROByteArray fromHexString(java.lang.String s)
java.lang.IllegalArgumentException - for invalid inputpublic static final ROByteArray compressFromString(java.lang.String in)
The compression is zlib deflate without any checksums or other avoidable redundant data, so error checking had better be done elsewhere.
The String value can be recovered with the uncompressToString() method.
in - non-null String
public static final java.lang.String uncompressToString(ROByteArray in)
throws java.io.IOException
in - non-null, non-empty value generated by compressFromString()
java.io.IOException - when having difficulty decoding the inputprotected java.lang.Object readResolve()
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||