Package marauroa.common.net
Class OutputSerializer
java.lang.Object
marauroa.common.net.OutputSerializer
OutputSerializer is used to serialize classes that implement the Serializable
interface into a OutputStream.
-
Constructor Summary
ConstructorsConstructorDescriptionOutputSerializer(OutputStream out)Constructor that defines a specified OutputStream for the serializer -
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeJsonString(String value)escapes a JSON stringintgets the protocolVersionvoidsetProtocolVersion(int protocolVersion)sets the protocol versionvoidwrite(byte a)Add the byte to the serializervoidwrite(byte[] a)Add the byte array to the serializervoidwrite(float a)Add the float to the serializervoidwrite(int a)Add the int to the serializervoidwrite(long a)Add the long to the serializervoidwrite(short a)Add the short to the serializervoidAdd the String to the serializer, using UTF-8 encodingvoidAdd the String array to the serializer, using UTF-8 encodingvoidwrite(Serializable obj)Add the Object to the serializer, if it implements the marauroa.common.net.Serializable interfacevoidwrite(Serializable[] objs)Add the Object array to the serializer, if it implements the marauroa.common.net.Serializable interfacevoidwrite255LongArray(byte[] a)Add a byte array whose size is smaller than 255 to the serializervoidAdd a short string to the serializer, using UTF-8 encodingvoidwrite65536LongArray(byte[] a)Add a long byte array whose size is smaller than 2^31 to the serializervoid/** Add a long string to the serializer, using UTF-8 encodingstatic voidwriteJson(StringBuilder out, String value)writes a json key-value-pairstatic voidwriteJson(StringBuilder out, String key, String value)writes a json key-value-pairstatic voidwriteObjectCollectionToJson(StringBuilder out, String name, Collection<? extends Attributes> collection, DetailLevel level)converts a list of objects into a json fragment
-
Constructor Details
-
OutputSerializer
Constructor that defines a specified OutputStream for the serializer- Parameters:
out- the OutputStream to which objects are serialized
-
-
Method Details
-
write
Add the Object to the serializer, if it implements the marauroa.common.net.Serializable interface- Parameters:
obj- the object to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the byte to the serializer- Parameters:
a- the byte to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the byte array to the serializer- Parameters:
a- the byte array to serialize- Throws:
IOException- in case of an IO-error
-
write255LongArray
Add a byte array whose size is smaller than 255 to the serializer- Parameters:
a- the byte array to serialize- Throws:
IOException- in case of an IO-error
-
write65536LongArray
Add a long byte array whose size is smaller than 2^31 to the serializer- Parameters:
a- the byte array to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the short to the serializer- Parameters:
a- the short to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the int to the serializer- Parameters:
a- the int to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the long to the serializer- Parameters:
a- the long to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the float to the serializer- Parameters:
a- the int to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the String to the serializer, using UTF-8 encoding- Parameters:
a- the String to serialize- Throws:
IOException- in case of an IO-error
-
write255LongString
Add a short string to the serializer, using UTF-8 encoding- Parameters:
a- the String to serialize- Throws:
IOException- in case of an IO-error
-
write65536LongString
/** Add a long string to the serializer, using UTF-8 encoding- Parameters:
a- the String to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the String array to the serializer, using UTF-8 encoding- Parameters:
a- the String array to serialize- Throws:
IOException- in case of an IO-error
-
write
Add the Object array to the serializer, if it implements the marauroa.common.net.Serializable interface- Parameters:
objs- the object array to serialize- Throws:
IOException- in case of an IO-error
-
getProtocolVersion
public int getProtocolVersion()gets the protocolVersion- Returns:
- protocol version
-
setProtocolVersion
public void setProtocolVersion(int protocolVersion)sets the protocol version- Parameters:
protocolVersion- protocol version
-
escapeJsonString
escapes a JSON string- Parameters:
value- json string to escape- Returns:
- escaped json string
-
writeJson
writes a json key-value-pair- Parameters:
out- buffer to write tovalue- value
-
writeJson
writes a json key-value-pair- Parameters:
out- buffer to write tokey- keyvalue- value
-
writeObjectCollectionToJson
public static void writeObjectCollectionToJson(StringBuilder out, String name, Collection<? extends Attributes> collection, DetailLevel level)converts a list of objects into a json fragment- Parameters:
out- output buffername- trusted name of list (will not be escaped).collection- list of rpobjectslevel- serialization level
-