|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.asyncobjects.io.BinaryData
public final class BinaryData
Immutable binary data class. The class avoids copying of data during
concat(BinaryData[])
, subrange(int, int)
operators.
However copying could be forced using flatten()
.
Depending on situation there are three different representations of the data:
empty()
}. This version has no data, so access times in
that case is 0(1).String
implementation.
There is a backing array, offset, and length. It is created by the method
fromBytes(byte[], int, int)
}. Note that method copies data to
internal array to prevent modification. Access times in that case is 0(1).
concat(BinaryData[])
. Access time in that case is 0(log(n)) (n is
amount of data nodes used to represent binary, in normal situations it is
about 2-3) when byteAt(int)
and friends are used. However it is
possible to use iterator()
and iterator(int, int)
to have
0(1) amortized cost (when accesssing O(length()
) elements.
The class implements Comparable
interface. Bytes are compared using
unsigned comparison. So 0xFF is bigger that 0x7F.
Nested Class Summary | |
---|---|
static class |
BinaryData.ByteIterator
A base class for byte iterators. |
Method Summary | |
---|---|
byte |
byteAt(int i)
Byte at specified position |
int |
compareTo(BinaryData data)
Compare an object to another binary data |
BinaryData |
concat(BinaryData data)
Concatenate |
static BinaryData |
concat(BinaryData[] other)
Concatenate binary data into large binary data |
BinaryData |
drop(int n)
Get new data with first n elements dropped |
BinaryData |
dropTo(int n,
byte[] target,
int startOffset)
Copy data to array and drop copied data. |
static BinaryData |
empty()
|
boolean |
endsWith(BinaryData data)
Check if one binary data ends with another |
boolean |
equals(Object other)
|
BinaryData |
flatten()
Defragment the node and ensure that it uses minimal amound of allocated data. |
static BinaryData |
fromBytes(byte... data)
Get binary data wrapper from specified byte array |
static BinaryData |
fromBytes(byte[] data,
int offset,
int length)
Get binary data wrapper from specified byte array |
static BinaryData |
get(ByteBuffer buffer)
Get data from NIO buffer. |
int |
hashCode()
|
BinaryData |
head(int n)
Get data with first n elements |
int |
intAt(int i)
Get big endian int at the specified posion. |
boolean |
isEmpty()
|
boolean |
isValidPosition(int i)
Check if position is a vaild one |
boolean |
isValidRange(int start,
int limit)
Check if range is completly within this object |
BinaryData.ByteIterator |
iterator()
|
BinaryData.ByteIterator |
iterator(int start,
int limit)
Get iterator. |
int |
length()
|
long |
longAt(int i)
Get big endian long at the specified posion. |
Promise<BinaryData> |
promise()
Return a promise that wraps this value |
static BinaryData |
put(ByteBuffer buffer,
BinaryData data)
Put binary data into the buffer |
short |
shortAt(int i)
Get big endian short at the specified posion. |
BinaryData |
subrange(int start,
int limit)
Get subrange of data |
byte[] |
toArray()
|
byte[] |
toArray(int srcStart,
byte[] target,
int targetStart,
int length)
Copy data to byte array |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static BinaryData concat(BinaryData[] other)
other
- binary outputs
public static BinaryData empty()
EMPTY
public static BinaryData fromBytes(byte... data)
data
- a data to wrap
public static BinaryData fromBytes(byte[] data, int offset, int length)
data
- a data to wrapoffset
- an offset in the datalength
- an length in the data
public byte byteAt(int i)
i
- a position
public int intAt(int i)
iterator(int, int)
instead.
i
- a posiion
public long longAt(int i)
iterator(int, int)
instead.
i
- a posiion
public short shortAt(int i)
iterator(int, int)
instead.
i
- a posiion
public boolean isValidPosition(int i)
i
- a position
public boolean isValidRange(int start, int limit)
start
- a start posionlimit
- a position right after last byte of the range
public int length()
length
in interface BatchedData<BinaryData>
BatchedData.length()
public BinaryData subrange(int start, int limit)
BatchedData
subrange
in interface BatchedData<BinaryData>
start
- a start posiionlimit
- a limit
BatchedData.subrange(int, int)
public BinaryData head(int n)
BatchedData
head
in interface BatchedData<BinaryData>
n
- amount to cut from beginning of the data
BatchedData.head(int)
public BinaryData drop(int n)
BatchedData
drop
in interface BatchedData<BinaryData>
n
- cut point
BatchedData.drop(int)
public BinaryData dropTo(int n, byte[] target, int startOffset)
n
- amount to copytarget
- target arraystartOffset
- start offset in array
public byte[] toArray(int srcStart, byte[] target, int targetStart, int length)
srcStart
- start of data region in this sequencetarget
- a target arraytargetStart
- a start posion in targetlength
- amount to copy
public byte[] toArray()
public BinaryData flatten()
public BinaryData.ByteIterator iterator(int start, int limit)
start
- start positionlimit
- limit position
public BinaryData.ByteIterator iterator()
public boolean equals(Object other)
equals
in class Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
public int compareTo(BinaryData data)
compareTo
in interface Comparable<BinaryData>
data
- a data to compre to
Comparable.compareTo(Object)
public String toString()
toString
in class Object
Object.toString()
public BinaryData concat(BinaryData data)
concat
in interface BatchedData<BinaryData>
data
- a data to append
concat(BinaryData[])
,
BatchedData.concat(net.sf.asyncobjects.io.BatchedData)
public boolean isEmpty()
isEmpty
in interface BatchedData<BinaryData>
BatchedData.isEmpty()
public boolean endsWith(BinaryData data)
data
- a possible suffix
public Promise<BinaryData> promise()
BatchedData
promise
in interface BatchedData<BinaryData>
BatchedData.promise()
public static BinaryData get(ByteBuffer buffer)
buffer
- a buffer to update
public static BinaryData put(ByteBuffer buffer, BinaryData data)
buffer
- a NIO buffer to changedata
- a data to put
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |