public final class ByteArrayField extends AbstractDataObjField
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 representation 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)
.
Note: extension of this class is not supported because of the high-performance architecture for binary protocol reading/writing.
Constructor and Description |
---|
ByteArrayField(int index,
String name) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object value1,
Object value2)
Compares two specified field values for equality.
|
Object |
fromByteArray(byte[] bytes)
This method is a hook to convert byte arrays into objects.
|
Object |
parseString(String value)
Parses string representation of specified field value.
|
Object |
readObj(com.devexperts.io.BufferedInput in)
Reads field value from specified data input and returns it to the caller.
|
Object |
readObj(DataInput in)
Reads field value from specified data input and returns it to the caller.
|
byte[] |
toByteArray(Object value)
This method is a hook to provide custom conversion of objects to byte arrays for serialization.
|
String |
toString(Object value)
Returns string representation of the specified field value.
|
void |
writeObj(com.devexperts.io.BufferedOutput out,
Object value)
Writes specified field value into specified buffered output.
|
void |
writeObj(DataOutput out,
Object value)
Writes specified field value into specified data output.
|
getString, read, setString, write
getDefaultPropertyName, getIndex, getLocalName, getName, getPropertyName, getRecord, getSerialType, setRecord, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getIndex, getLocalName, getName, getPropertyName, getRecord, getSerialType
public ByteArrayField(int index, String name)
public Object fromByteArray(byte[] bytes)
readObj(java.io.DataInput)
.
This method can be overridden 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 overriding 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(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 overridden 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 overriding 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 String toString(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
toString
in class AbstractDataObjField
public Object parseString(String value)
AbstractDataObjField
value
.parseString
in interface DataObjField
parseString
in class AbstractDataObjField
public boolean equals(Object value1, Object value2)
AbstractDataObjField
value1 == value2 || (value1 != null && value1.equals(value2))
.equals
in interface DataObjField
equals
in class AbstractDataObjField
public void writeObj(DataOutput out, Object value) throws IOException
DataObjField
IOException
- as specified data output does.public void writeObj(com.devexperts.io.BufferedOutput out, Object value) throws IOException
DataObjField
IOException
- as specified data output does.public Object readObj(DataInput in) throws IOException
DataObjField
IOException
- as specified data input does.public Object readObj(com.devexperts.io.BufferedInput in) throws IOException
DataObjField
IOException
- as specified data input does.Copyright © 2002–2025 Devexperts LLC. All rights reserved.