public class ExternalizableUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
UTF8 |
Constructor and Description |
---|
ExternalizableUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copyStream(java.io.DataInput in,
java.io.DataOutput out) |
static java.math.BigInteger |
readBigInteger(java.io.DataInput in)
Reads an
BigInteger from the input stream, the structure is such as:
A boolean to tell if the value is null or not. |
static java.lang.Boolean |
readBoolean(java.io.DataInput in)
Reads a
Boolean to the input stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
readDocument(java.io.DataInput in,
DocumentHandler handler)
Reads a document from the input stream.
|
static int |
readDocumentList(java.io.DataInput ins,
DocumentListHandler handler) |
static <T extends java.lang.Enum<T>> |
readEnum(java.io.DataInput in,
java.lang.Class<T> cls)
Reads an enumeration from the input stream.
|
static int[] |
readIntArray(java.io.DataInput in)
Reads an integer array to the output stream, the structure is such as:
An integer (
DataOutput.writeInt(int) ) to tell if the size of the array. |
static java.lang.Integer |
readInteger(java.io.DataInput in)
Reads an
Integer to the input stream, the structure is such as:
A boolean to tell if the value is null or not. |
static java.util.List<java.lang.Integer> |
readIntList(java.io.DataInput in)
Reads an integer array and exposes it as if it was a integer list
|
static int |
readKeyValueContainer(java.io.DataInput in,
DirectiveHandler handler)
Read the content of a
KeyValuesContainer . |
static java.lang.Long |
readLong(java.io.DataInput in)
Reads an
Long to the input stream, the structure is such as:
A boolean to tell if the value is null or not. |
static int |
readMetaContainer(java.io.DataInput in,
MetaHandler handler)
Reads a meta container.
|
static int |
readPartContainer(java.io.DataInput in,
PartContainerHandler handler)
Reads a
PartContainer from the input stream
The IOCallbackHandler.endHandler() is always invoked, weither the container was null or not. |
static void |
readStream(java.io.DataInput ins,
PartHandler handler)
Reads a stream for a part.
|
static java.lang.String |
readString(java.io.DataInput in)
Reads an
String from the input stream, the structure is such as:
A boolean to tell if the value is null or not. |
static java.lang.String[] |
readStringArray(java.io.DataInput in)
Reads an
String array to the output stream, the structure is such as:
An integer (DataOutput.writeInt(int) ) to tell if the size of the array. |
static java.util.List<java.lang.String> |
readStringList(java.io.DataInput in)
Reads a
String array and exposes it as if it was a String list |
static java.lang.String[][] |
readStringMatrix(java.io.DataInput in) |
static void |
writeBigInteger(java.io.DataOutput out,
java.math.BigInteger i)
Writes an
BigInteger to the output stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
writeBoolean(java.io.DataOutput out,
java.lang.Boolean b)
Writes a
Boolean to the output stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
writeDocument(java.io.DataOutput out,
Document doc)
Writes a document to the output stream.
|
static void |
writeDocumentList(java.io.DataOutput outs,
Document[] docList) |
static void |
writeEnum(java.io.DataOutput out,
java.lang.Enum<?> enumeration)
The structure is such as:
A boolean to tell if the value is null (
false ) or not. |
static void |
writeIntArray(java.io.DataOutput out,
int[] intList)
Writes an integer array to the output stream, the structure is such as:
An integer (
DataOutput.writeInt(int) ) to tell if the size of the array. |
static void |
writeInteger(java.io.DataOutput out,
java.lang.Integer i)
Writes a
Integer to the output stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
writeIntList(java.io.DataOutput out,
java.util.List<java.lang.Integer> intList)
Writes an integer list as if it was a integer array.
|
static void |
writeKeyValueContainer(java.io.DataOutput out,
KeyValuesContainer<java.lang.String,java.lang.String> kvContainer)
Writes the content of a
KeyValuesContainer . |
static void |
writeLong(java.io.DataOutput out,
java.lang.Long l)
Writes a
Long to the output stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
writeMetaContainer(java.io.DataOutput out,
MetaContainer container)
A meta container is written such as:
If there is another meta in the meta container, sends
true . |
static void |
writePartContainer(java.io.DataOutput out,
PartContainer pc)
Writes a part container.
|
static void |
writeStream(java.io.DataOutput out,
ContentStream stream)
Writes the content of a
ContentStream . |
static void |
writeString(java.io.DataOutput out,
java.lang.String str)
Writes an
String to the output stream, the structure is such as:
A boolean to tell if the value is null or not. |
static void |
writeStringArray(java.io.DataOutput out,
java.lang.String[] str)
Writes an
String array to the output stream, the structure is such as:
An integer (DataOutput.writeInt(int) ) to tell if the size of the array. |
static void |
writeStringList(java.io.DataOutput out,
java.util.List<java.lang.String> str)
Writes an
String list as if it was a string array. |
static void |
writeStringMatrix(java.io.DataOutput out,
java.lang.String[][] str) |
public static java.lang.Boolean readBoolean(java.io.DataInput in) throws java.io.IOException
Boolean
to the input stream, the structure is such as:
null
or not. If it is null
returns null
null
, reads the boolean value with DataInput.readBoolean()
in
- The stream to read fromnull
, Boolean#FALSE
or Boolean#TRUE
java.io.IOException
public static void writeBoolean(java.io.DataOutput out, java.lang.Boolean b) throws java.io.IOException
Boolean
to the output stream, the structure is such as:
null
or not. If it is null
returns without sending anymore datanull
, writes the boolean value with DataOutput.writeBoolean(boolean)
out
- The stream to write tob
- The value to writejava.io.IOException
public static java.lang.Integer readInteger(java.io.DataInput in) throws java.io.IOException
Integer
to the input stream, the structure is such as:
null
or not. If it is null
returns null
null
, reads the integer value with DataInput.readInt()
in
- The stream to read fromnull
, or an Integer valuejava.io.IOException
public static void writeInteger(java.io.DataOutput out, java.lang.Integer i) throws java.io.IOException
Integer
to the output stream, the structure is such as:
null
or not. If it is null
returns without sending anymore datanull
, writes the int value with DataOutput.writeInt(int)
out
- the stream to write tob
- the value to writejava.io.IOException
public static java.math.BigInteger readBigInteger(java.io.DataInput in) throws java.io.IOException
BigInteger
from the input stream, the structure is such as:
null
or not. If it is null
returns null
null
, reads the big integer into as a byte array
DataInput.readInt()
DataInput.readFully(byte[])
in
- The stream to read fromnull
, or an Integer valuejava.io.IOException
public static void writeBigInteger(java.io.DataOutput out, java.math.BigInteger i) throws java.io.IOException
BigInteger
to the output stream, the structure is such as:
null
or not. If it is null
returns without sending anything morenull
, turns the big integer into a byte array BigInteger.toByteArray()
then writes it:
DataOutput.writeInt(int)
DataOutput.write(byte[])
out
- i
- java.io.IOException
public static java.lang.Long readLong(java.io.DataInput in) throws java.io.IOException
Long
to the input stream, the structure is such as:
null
or not. If it is null
returns null
null
, reads the integer value with DataInput.readLong()
in
- The stream to read fromnull
, or a Long instancejava.io.IOException
public static void writeLong(java.io.DataOutput out, java.lang.Long l) throws java.io.IOException
Long
to the output stream, the structure is such as:
null
or not. If it is null
returns without sending anymore datanull
, writes the int value with DataOutput.writeLong(long)
out
- the stream to write tol
- the value to writejava.io.IOException
public static java.lang.String readString(java.io.DataInput in) throws java.io.IOException
String
from the input stream, the structure is such as:
null
or not. If it is null
returns null
null
the value of the string as an UTF-8 byte array
DataInput.readInt()
DataInput.readFully(byte[])
in
- The stream to read fromnull
, or a Long instancejava.io.IOException
public static void writeString(java.io.DataOutput out, java.lang.String str) throws java.io.IOException
String
to the output stream, the structure is such as:
null
or not. If it is null
writes false
with DataOutput.writeBoolean(boolean)
and returns.null
the value of the string as an UTF-8 byte array
DataOutput.writeInt(int)
DataOutput.write(byte[])
out
- str
- java.io.IOException
public static java.lang.String[] readStringArray(java.io.DataInput in) throws java.io.IOException
String array
to the output stream, the structure is such as:
DataOutput.writeInt(int)
) to tell if the size of the array. If less than 0 then the array is null
, then returns null
.
readString(DataInput)
java.io.IOException
public static void writeStringArray(java.io.DataOutput out, java.lang.String[] str) throws java.io.IOException
String array
to the output stream, the structure is such as:
DataOutput.writeInt(int)
) to tell if the size of the array. If less than 0 then the array is null
, then returns without sending anything else.
writeString(DataOutput, String)
out
- The destination streamstr
- the value to writejava.io.IOException
public static java.lang.String[][] readStringMatrix(java.io.DataInput in) throws java.io.IOException
java.io.IOException
public static void writeStringMatrix(java.io.DataOutput out, java.lang.String[][] str) throws java.io.IOException
java.io.IOException
public static java.util.List<java.lang.String> readStringList(java.io.DataInput in) throws java.io.IOException
String
array and exposes it as if it was a String
listin
- null
)java.io.IOException
ExternalizableUtils#readStringArray(DataInput)}
public static void writeStringList(java.io.DataOutput out, java.util.List<java.lang.String> str) throws java.io.IOException
String
list as if it was a string array.out
- The destination streamstr
- the value to writejava.io.IOException
ExternalizableUtils#writeStringArray(DataOutput, String[])}
public static int[] readIntArray(java.io.DataInput in) throws java.io.IOException
DataOutput.writeInt(int)
) to tell if the size of the array. If less than 0 then the array is null
, then returns null
.
DataInput.readInt()
java.io.IOException
public static void writeIntArray(java.io.DataOutput out, int[] intList) throws java.io.IOException
DataOutput.writeInt(int)
) to tell if the size of the array. If less than 0 then the array is null
, then returns without sending anything else.
DataOutput.write(int)
out
- The destination streamintList
- the value to writejava.io.IOException
public static java.util.List<java.lang.Integer> readIntList(java.io.DataInput in) throws java.io.IOException
in
- null
)java.io.IOException
ExternalizableUtils#readIntArray(DataInput)}
public static void writeIntList(java.io.DataOutput out, java.util.List<java.lang.Integer> intList) throws java.io.IOException
out
- The destination streamintList
- the value to writejava.io.IOException
ExternalizableUtils#writeIntArray(DataOutput, int[])}
public static int readKeyValueContainer(java.io.DataInput in, DirectiveHandler handler) throws java.lang.Exception
KeyValuesContainer
.
The IOCallbackHandler.endHandler()
is always invoked, weither the container was null
or not.
The structure of the directive container is such as:
readString(DataInput)
readStringList(DataInput)
in
- handler
- the consumer of each key-value pairjava.lang.Exception
public static void writeKeyValueContainer(java.io.DataOutput out, KeyValuesContainer<java.lang.String,java.lang.String> kvContainer) throws java.io.IOException
KeyValuesContainer
.
The structure of the directive container is such as:
null
write a false an returnswriteString(DataOutput, String)
writeStringList(DataOutput, List)
out
- kvContainer
- java.io.IOException
public static <T extends java.lang.Enum<T>> T readEnum(java.io.DataInput in, java.lang.Class<T> cls) throws java.io.IOException
false
) or notnull
, reads the name of the enumeration and instantiate it with Enum.valueOf(Class, String)
in
- cls
- The class of the expected enumerationjava.io.IOException
public static void writeEnum(java.io.DataOutput out, java.lang.Enum<?> enumeration) throws java.io.IOException
false
) or not. If null
returnsnull
, writes the name (Enum.name()
) of the enumerationout
- enumeration
- java.io.IOException
public static void readStream(java.io.DataInput ins, PartHandler handler) throws java.lang.Exception
ins
- handler
- The part handler, cannot be null
java.lang.Exception
public static void writeStream(java.io.DataOutput out, ContentStream stream) throws java.io.IOException
ContentStream
.
ContentStream.getStreamLength()
if less than 0 (which means that the size of the stream is unknown)
the stream is completely read once (into a black hole) to know the exact number of bytes of the stream.
Then the stream will re re-read once more to write its content
ContentStream.getStreamLength()
is greater or equal to 0, then exactly that number of bytes will be written.
If the stream contains less than heralded, an error is raised. If the stream contains more, this is ignored.
null
writes 0.out
- stream
- java.io.IOException
public static void copyStream(java.io.DataInput in, java.io.DataOutput out) throws java.io.IOException
in
- The input stream. It is structured such as:
long
, the size of the stream. Must be equal or greater than 0out
- The destination streamjava.io.IOException
- IF failed to read the source or to write to the destination streampublic static int readMetaContainer(java.io.DataInput in, MetaHandler handler) throws java.lang.Exception
boolean
, if true
there is another meta in the meta container. If false
, there is no more Meta and we are finished with this meta containerIOCallbackHandler.endHandler()
is always invoked, weither the container was null
or not.in
- The source to read a Meta container from. A meta container is a list of meta, it is structure such as:
The string are read by readString(DataInput)
handler
- The processor of the meta (for each meta in the meta container)java.lang.Exception
public static void writeMetaContainer(java.io.DataOutput out, MetaContainer container) throws java.io.IOException
true
. Sends false
and returns.writeString(DataOutput, String)
out
- The stream to write a meta container to.container
- to copy to the output streamjava.io.IOException
public static int readPartContainer(java.io.DataInput in, PartContainerHandler handler) throws java.lang.Exception
PartContainer
from the input stream
The IOCallbackHandler.endHandler()
is always invoked, weither the container was null
or not.
For the structure, see writePartContainer(DataOutput, PartContainer)
in
- handler
- java.lang.Exception
public static void writePartContainer(java.io.DataOutput out, PartContainer pc) throws java.io.IOException
DataOutput.writeBoolean(boolean)
to tell if there is more part to send. If there is no more parts, emit false
and returnswriteString(DataOutput, String)
writeKeyValueContainer(DataOutput, KeyValuesContainer)
writeStream(DataOutput, ContentStream)
out
- pc
- the part container to write to the streamjava.io.IOException
public static void readDocument(java.io.DataInput in, DocumentHandler handler) throws java.lang.Exception
null
.
The IOCallbackHandler.endHandler()
is always invoked.
For the structure, see writeDocument(DataOutput, Document)
in
- handler
- The handler to process the document. Cannot be nulljava.lang.Exception
public static void writeDocument(java.io.DataOutput out, Document doc) throws java.lang.Exception
writeString(DataOutput, String)
writeString(DataOutput, String)
writeKeyValueContainer(DataOutput, KeyValuesContainer)
writeMetaContainer(DataOutput, MetaContainer)
writePartContainer(DataOutput, PartContainer)
out
- doc
- The document to send. Must be not null
java.lang.Exception
public static void writeDocumentList(java.io.DataOutput outs, Document[] docList) throws java.lang.Exception
java.lang.Exception
public static int readDocumentList(java.io.DataInput ins, DocumentListHandler handler) throws java.io.IOException, java.lang.Exception
java.io.IOException
java.lang.Exception
Copyright © 2021 Dassault Systèmes, All Rights Reserved.