public abstract class NativeTypeSerializer
extends java.lang.Object
Field
).
When using this class, all writing needs to be done using the writeValue(java.lang.Object, com.goldencode.util.NativeTypeSerializer, java.io.ObjectOutput)
API and it
must be read using the readValueWorker(java.io.ObjectInput)
API.
All Java 7 native types are supported, plus String
. If the class passed to
getWorker(java.lang.Class<?>)
is not a native type or String
, then it will fallback to serializing
the value as a plain Object
.
Modifier and Type | Class and Description |
---|---|
private static class |
NativeTypeSerializer.BooleanSerializer
A serializer for native
boolean values. |
private static class |
NativeTypeSerializer.ByteSerializer
A serializer for native
byte values. |
private static class |
NativeTypeSerializer.CharSerializer
A serializer for native
char values. |
private static class |
NativeTypeSerializer.DoubleSerializer
A serializer for native
double values. |
private static class |
NativeTypeSerializer.FloatSerializer
A serializer for native
float values. |
private static class |
NativeTypeSerializer.IntSerializer
A serializer for native
int values. |
private static class |
NativeTypeSerializer.LongSerializer
A serializer for native
long values. |
private static class |
NativeTypeSerializer.ObjectSerializer
A fallback serializer for
Object instances. |
private static class |
NativeTypeSerializer.ShortSerializer
A serializer for native
short values. |
private static class |
NativeTypeSerializer.StringSerializer
A serializer for
String values. |
Modifier and Type | Field and Description |
---|---|
static NativeTypeSerializer.BooleanSerializer |
BOOLEAN_SERIALIZER
A serializer for native
boolean values. |
static NativeTypeSerializer.ByteSerializer |
BYTE_SERIALIZER
A serializer for native
byte values. |
static NativeTypeSerializer.CharSerializer |
CHAR_SERIALIZER
A serializer for native
char values. |
static NativeTypeSerializer.DoubleSerializer |
DOUBLE_SERIALIZER
A serializer for native
double values. |
static NativeTypeSerializer.FloatSerializer |
FLOAT_SERIALIZER
A serializer for native
float values. |
static NativeTypeSerializer.IntSerializer |
INT_SERIALIZER
A serializer for native
int values. |
static NativeTypeSerializer.LongSerializer |
LONG_SERIALIZER
A serializer for native
long values. |
protected byte |
mark
A special mark to identify the type of the written value, when reading.
|
static NativeTypeSerializer.ObjectSerializer |
OBJECT_SERIALIZER
Fallback serializer for other
Object instances. |
static NativeTypeSerializer.ShortSerializer |
SHORT_SERIALIZER
A serializer for native
short values. |
static NativeTypeSerializer.StringSerializer |
STRING_SERIALIZER
A serializer for
String values. |
private static NativeTypeSerializer[] |
workers
An array of workers, identified by their
mark . |
Modifier | Constructor and Description |
---|---|
protected |
NativeTypeSerializer(int mark)
Create a new serializer and set its mark.
|
Modifier and Type | Method and Description |
---|---|
static NativeTypeSerializer |
getWorker(java.lang.Class<?> ftype)
Get the
NativeTypeSerializer associated with the given Class . |
static java.lang.Object |
readValue(java.io.ObjectInput in)
Read the given value using the specified
worker , from the
specified destination. |
protected abstract java.lang.Object |
readValueWorker(java.io.ObjectInput in)
A worker to read the value from the specified source.
|
static void |
writeValue(java.lang.Object value,
NativeTypeSerializer worker,
java.io.ObjectOutput out)
Write the given value using the specified
worker , to the
specified destination. |
protected abstract void |
writeValueWorker(java.lang.Object value,
java.io.ObjectOutput out)
A worker to write the value to the specified destination.
|
public static final NativeTypeSerializer.ByteSerializer BYTE_SERIALIZER
byte
values.public static final NativeTypeSerializer.ShortSerializer SHORT_SERIALIZER
short
values.public static final NativeTypeSerializer.IntSerializer INT_SERIALIZER
int
values.public static final NativeTypeSerializer.LongSerializer LONG_SERIALIZER
long
values.public static final NativeTypeSerializer.FloatSerializer FLOAT_SERIALIZER
float
values.public static final NativeTypeSerializer.DoubleSerializer DOUBLE_SERIALIZER
double
values.public static final NativeTypeSerializer.BooleanSerializer BOOLEAN_SERIALIZER
boolean
values.public static final NativeTypeSerializer.CharSerializer CHAR_SERIALIZER
char
values.public static final NativeTypeSerializer.StringSerializer STRING_SERIALIZER
String
values.public static final NativeTypeSerializer.ObjectSerializer OBJECT_SERIALIZER
Object
instances.private static final NativeTypeSerializer[] workers
mark
.protected final byte mark
protected NativeTypeSerializer(int mark)
mark
- The serializer's mark.public static void writeValue(java.lang.Object value, NativeTypeSerializer worker, java.io.ObjectOutput out) throws java.io.IOException
worker
, to the
specified destination.
The first written byte will be the worker's mark
, followed by the serialized value.
value
- The value to be written.worker
- The worker to write the value.out
- The destination.java.io.IOException
- In case of I/O errors.public static java.lang.Object readValue(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
worker
, from the
specified destination.
The first read byte will be the worker's mark
, followed by the serialized value.
in
- The source.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If the worker is NativeTypeSerializer.ObjectSerializer
and the object's class can not be found.public static NativeTypeSerializer getWorker(java.lang.Class<?> ftype)
NativeTypeSerializer
associated with the given Class
.ftype
- The class.protected abstract void writeValueWorker(java.lang.Object value, java.io.ObjectOutput out) throws java.io.IOException
value
- The value to be written.out
- The destination.java.io.IOException
- In case of I/O errors.protected abstract java.lang.Object readValueWorker(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- The source.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If the worker is NativeTypeSerializer.ObjectSerializer
and the object's class can not be found.