|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.devexperts.qd.kit.ByteArrayField
public class ByteArrayField
The ByteArrayField
represents a linear byte array field
with plain serialized form. It uses CompactInt
to encode
byte array length first, then serializes bytes themselves. The value -1
for length is used as a marker to distinguish 'null' array from empty one.
Default represenation of the value is byte[]
as returned by readObj(java.io.DataInput)
,
but String
, char[]
and arbitrary serializable objects are also
supported by writeObj(java.io.DataOutput, java.lang.Object)
and toString(Object)
.
Constructor Summary | |
---|---|
ByteArrayField(int index,
java.lang.String name)
|
Method Summary | |
---|---|
boolean |
equals(java.lang.Object value1,
java.lang.Object value2)
Compares two specified field values for equality. |
java.lang.Object |
fromByteArray(byte[] bytes)
This method is a hook to convert byte arrays into objects. |
int |
getIndex()
Returns index of this field in its parent DataRecord . |
java.lang.String |
getLocalName()
Returns local name of this field -- the name of this field that is unique withing the record. |
java.lang.String |
getName()
Returns name of this field. |
DataRecord |
getRecord()
Returns parent DataRecord of this field. |
SerialFieldType |
getSerialType()
Returns serial type of this field. |
java.lang.Object |
parseString(java.lang.String value)
Parses string representation of specified field value. |
java.lang.Object |
readObj(java.io.DataInput in)
Reads field value from specified data intput and returns it to the caller. |
void |
setRecord(DataRecord record)
Sets reference to parent data record. |
byte[] |
toByteArray(java.lang.Object value)
This method is a hook to provide custom conversion of objects to byte arrays for serialization. |
java.lang.String |
toString()
|
java.lang.String |
toString(java.lang.Object value)
Returns string representation of the specified field value. |
void |
writeObj(java.io.DataOutput out,
java.lang.Object value)
Writes specified field value into specified data output. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.devexperts.qd.DataField |
---|
getIndex, getLocalName, getName, getRecord |
Constructor Detail |
---|
public ByteArrayField(int index, java.lang.String name)
Method Detail |
---|
public java.lang.Object fromByteArray(byte[] bytes)
readObj(java.io.DataInput)
.
This method can be overriden to provide custom conversion of byte arrays to objects.
If you override this method, then you also typically need to override toByteArray(Object)
and consider overrding toString(Object)
.
For example, if you need to convert byte arrays to MyObject
instances, write:
public Object fromByteArray(byte[] bytes) { return MyObject.forByteArray(bytes); }It is recommended that all such MyObject classes lazily reconstruct themselves from byte array to avoid potentially costly deserialization in multiplexor nodes.
bytes
- Byte array to convert to object.
public byte[] toByteArray(java.lang.Object value)
byte[]
is returned as is.
String
and char[]
are converted to UTF8 bytes.
null
is returned. In this case callee if this method
uses IOUtil.objectToBytes(Object)
or IOUtil.writeObject(DataOutput, Object)
.
equals(Object, Object)
, toString(Object)
, and
writeObj(DataOutput, Object)
.
This method can be overriden to provide custom conversion of objects to byte arrays.
If you override this method, then you also typically need to override fromByteArray(byte[])
and consider overrding toString(Object)
.
For example, if you need to convert MyObject
instances to byte arrays, write:
public byte[] toByteArray(Object value) { if (value instanceof MyObject) return ((MyObject)value).toByteArray(); else super.toByteArray(value); }It is recommended that all such MyObject classes cache their produced byte arrays to avoid potentially costly serialization in multiplexor nodes.
value
- The object to convert to byte array.
null
if default conversion via IOUtil.objectToBytes(java.lang.Object)
or
IOUtil.writeObject(DataOutput, Object)
shall be used.public java.lang.String toString(java.lang.Object value)
toByteArray(Object)
,
if that returns null, then it uses IOUtil.objectToBytes(Object)
; then returns a hex
representation of the resulting byte array.
toString
in interface DataObjField
public java.lang.Object parseString(java.lang.String value)
value
.
parseString
in interface DataObjField
public boolean equals(java.lang.Object value1, java.lang.Object value2)
value1 == value2 || (value1 != null && value1.equals(value2))
.
equals
in interface DataObjField
public final void writeObj(java.io.DataOutput out, java.lang.Object value) throws java.io.IOException
writeObj
in interface DataObjField
java.io.IOException
- as specified data output does.public final java.lang.Object readObj(java.io.DataInput in) throws java.io.IOException
readObj
in interface DataObjField
java.io.IOException
- as specified data input does.public final SerialFieldType getSerialType()
DataField
public final void setRecord(DataRecord record)
java.lang.IllegalStateException
- if parent record already set to different instance.public final java.lang.String toString()
toString
in class java.lang.Object
public final DataRecord getRecord()
DataField
DataRecord
of this field.
getRecord
in interface DataField
public final int getIndex()
DataField
DataRecord
.
getIndex
in interface DataField
public final java.lang.String getName()
DataField
DataScheme
.
It is required that this full field name consists of its parent record name
followed by dot ('.') followed by local name
of this filed
like these: "FooRecord.Category", "FooRecord.Amount", etc.
getName
in interface DataField
public java.lang.String getLocalName()
DataField
getLocalName
in interface DataField
DataField.getName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |