Package fr.dyade.aaa.common.stream
Class StreamUtil
- java.lang.Object
-
- fr.dyade.aaa.common.stream.StreamUtil
-
public final class StreamUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static byteBOOLEAN(package private) static byteBYTE(package private) static byteBYTEARRAYprivate static Charsetcharset(package private) static byteDOUBLE(package private) static byte[]EMPTY_BYTE_ARRAY(package private) static StringEMPTY_STRINGstatic intFALSE(package private) static byteFLOAT(package private) static byteINT(package private) static Loggerlogger(package private) static byteLONG(package private) static byteNULLstatic intPER_THREAD_BUFFER_LENGTHprivate static ThreadLocal<byte[]>perThreadBuffer(package private) static byteSHORTstatic StringSTREAM_CHARSET_DFLTstatic StringSTREAM_CHARSET_PROPERTYstatic StringSTREAM_USE_JVM_CHARSET_PROPERTY(package private) static byteSTRINGstatic intTRUE
-
Constructor Summary
Constructors Constructor Description StreamUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectdecodeValue(Decoder decoder)static voidencodeValue(Object obj, Encoder encoder)static intgetEncodedSize(Object obj)static booleanisStreamable(Object obj)Test if an object is writable to an output stream.static ArrayList<String>readArrayListOfStringFrom(InputStream is)This method allows to restore a list of String objects from the input stream.static boolean[]readArrayOfBooleanFrom(InputStream is)This method allows to restore a boolean array from the input stream.static int[]readArrayOfIntFrom(InputStream is)This method allows to restore a int array from the input stream.static String[]readArrayOfStringFrom(InputStream is)This method allows to restore a String array from the input stream.static booleanreadBooleanFrom(InputStream is)This method allows to restore a boolean from the input stream.static byte[]readByteArrayFrom(InputStream is)This method allows to restore a byte array from the input stream.static byte[]readByteArrayFrom(InputStream is, int length)This method allows to restore a byte array from the input stream.static bytereadByteFrom(InputStream is)This method allows to restore a byte from the input stream.static doublereadDoubleFrom(InputStream is)This method allows to restore a double from the input stream.static floatreadFloatFrom(InputStream is)This method allows to restore a float from the input stream.private static voidreadFully(byte[] buf, InputStream is)private static byte[]readFully(int length, InputStream is)static intreadIntFrom(InputStream is)This method allows to restore an integer from the input stream.static PropertiesreadJPropertiesFrom(InputStream is)This method allows to restore a java.util.Properties object from the input stream.static longreadLongFrom(InputStream is)This method allows to restore a long from the input stream.static ObjectreadObjectFrom(InputStream is)This method allows to restore an object from the input stream.static PropertiesreadPropertiesFrom(InputStream is)This method allows to restore a Properties object from the input stream.static shortreadShortFrom(InputStream is)This method allows to restore a short from the input stream.static StringreadShortStringFrom(InputStream is)This method allows to restore a short String from the input stream.static StringreadStringFrom(InputStream is)This method allows to restore a String from the input streamstatic intreadUnsignedByteFrom(InputStream is)This method allows to restore a byte from the input stream.static longreadUnsignedIntFrom(InputStream is)This method allows to restore an integer from the input stream.static Vector<String>readVectorOfStringFrom(InputStream is)This method allows to restore a vector of String objects from the input stream.static voidwriteArrayOfBooleanTo(boolean[] array, OutputStream os)This method allows to write a boolean array to the output stream.static voidwriteArrayOfIntTo(int[] array, OutputStream os)This method allows to write a int array to the output stream.static voidwriteArrayOfStringTo(String[] array, OutputStream os)This method allows to write a String array to the output stream.static voidwriteListOfStringTo(List v, OutputStream os)This method allows to write a generic list of String objects to the output stream.static voidwriteObjectTo(Object obj, OutputStream os)This method allows to write an object to the output stream.static voidwriteTo(boolean b, OutputStream os)This method allows to write a boolean to the output stream.static voidwriteTo(byte[] tab, int offset, int length, OutputStream os)This method allows to write byte array to the output stream.static voidwriteTo(byte[] tab, OutputStream os)This method allows to write byte array to the output stream.static voidwriteTo(byte b, OutputStream os)This method allows to write a byte to the output stream.static voidwriteTo(double d, OutputStream os)This method allows to write a double to the output stream.static voidwriteTo(float f, OutputStream os)This method allows to write a float to the output stream.static voidwriteTo(int i, OutputStream os)This method allows to write an integer to the output stream.static voidwriteTo(long l, OutputStream os)This method allows to write a long to the output stream.static voidwriteTo(short s, OutputStream os)This method allows to write a short to the output stream.static voidwriteTo(Properties p, OutputStream os)This method allows to write a Properties object to the output stream.static voidwriteTo(String str, OutputStream os)This method allows to write a String to the output streamstatic voidwriteTo(Properties p, OutputStream os)This method allows to write a java.util.Properties object to the output stream.
-
-
-
Field Detail
-
logger
static final Logger logger
-
STREAM_CHARSET_PROPERTY
public static final String STREAM_CHARSET_PROPERTY
- See Also:
- Constant Field Values
-
STREAM_USE_JVM_CHARSET_PROPERTY
public static final String STREAM_USE_JVM_CHARSET_PROPERTY
- See Also:
- Constant Field Values
-
STREAM_CHARSET_DFLT
public static final String STREAM_CHARSET_DFLT
- See Also:
- Constant Field Values
-
charset
private static final Charset charset
-
PER_THREAD_BUFFER_LENGTH
public static final int PER_THREAD_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
perThreadBuffer
private static ThreadLocal<byte[]> perThreadBuffer
-
TRUE
public static final int TRUE
- See Also:
- Constant Field Values
-
FALSE
public static final int FALSE
- See Also:
- Constant Field Values
-
EMPTY_STRING
static final String EMPTY_STRING
- See Also:
- Constant Field Values
-
EMPTY_BYTE_ARRAY
static final byte[] EMPTY_BYTE_ARRAY
-
NULL
static final byte NULL
- See Also:
- Constant Field Values
-
BOOLEAN
static final byte BOOLEAN
- See Also:
- Constant Field Values
-
BYTE
static final byte BYTE
- See Also:
- Constant Field Values
-
SHORT
static final byte SHORT
- See Also:
- Constant Field Values
-
INT
static final byte INT
- See Also:
- Constant Field Values
-
LONG
static final byte LONG
- See Also:
- Constant Field Values
-
FLOAT
static final byte FLOAT
- See Also:
- Constant Field Values
-
DOUBLE
static final byte DOUBLE
- See Also:
- Constant Field Values
-
STRING
static final byte STRING
- See Also:
- Constant Field Values
-
BYTEARRAY
static final byte BYTEARRAY
- See Also:
- Constant Field Values
-
-
Method Detail
-
readFully
private static byte[] readFully(int length, InputStream is) throws IOException- Throws:
IOException
-
readFully
private static void readFully(byte[] buf, InputStream is) throws IOException- Throws:
IOException
-
writeTo
public static void writeTo(boolean b, OutputStream os) throws IOExceptionThis method allows to write a boolean to the output stream.- Parameters:
b- the boolean to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readBooleanFrom
public static boolean readBooleanFrom(InputStream is) throws IOException
This method allows to restore a boolean from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the boolean
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(byte b, OutputStream os) throws IOExceptionThis method allows to write a byte to the output stream.- Parameters:
b- the byte to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readByteFrom
public static byte readByteFrom(InputStream is) throws IOException
This method allows to restore a byte from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the byte
- Throws:
IOException- an error occurs during IO operation.
-
readUnsignedByteFrom
public static int readUnsignedByteFrom(InputStream is) throws IOException
This method allows to restore a byte from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the byte
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(short s, OutputStream os) throws IOExceptionThis method allows to write a short to the output stream.- Parameters:
s- the short to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readShortFrom
public static short readShortFrom(InputStream is) throws IOException
This method allows to restore a short from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the short
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(int i, OutputStream os) throws IOExceptionThis method allows to write an integer to the output stream.- Parameters:
i- the integer to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readIntFrom
public static int readIntFrom(InputStream is) throws IOException
This method allows to restore an integer from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the integer
- Throws:
IOException- an error occurs during IO operation.
-
readUnsignedIntFrom
public static long readUnsignedIntFrom(InputStream is) throws IOException
This method allows to restore an integer from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the integer
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(long l, OutputStream os) throws IOExceptionThis method allows to write a long to the output stream.- Parameters:
l- the long to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readLongFrom
public static long readLongFrom(InputStream is) throws IOException
This method allows to restore a long from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the long
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(float f, OutputStream os) throws IOExceptionThis method allows to write a float to the output stream.- Parameters:
f- the float to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readFloatFrom
public static float readFloatFrom(InputStream is) throws IOException
This method allows to restore a float from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the float
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(double d, OutputStream os) throws IOExceptionThis method allows to write a double to the output stream.- Parameters:
d- the double to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readDoubleFrom
public static double readDoubleFrom(InputStream is) throws IOException
This method allows to restore a double from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the double
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(String str, OutputStream os) throws IOException
This method allows to write a String to the output stream. /!\ Be careful, since Joram 5.19 by default String objects are encoded using UTF-8 charset.- Parameters:
str- the String to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readStringFrom
public static String readStringFrom(InputStream is) throws IOException
This method allows to restore a String from the input stream. /!\ Be careful, since Joram 5.19 by default String objects are encoded using UTF-8 charset.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the String object or null
- Throws:
IOException- an error occurs during IO operation.
-
readShortStringFrom
public static String readShortStringFrom(InputStream is) throws IOException
This method allows to restore a short String from the input stream. The maximum length for a short String is 255 characters (Used only one time in AMQP). /!\ Be careful, these String objects are encoded using UTF-8 charset.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the String object or null
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(byte[] tab, OutputStream os) throws IOExceptionThis method allows to write byte array to the output stream.- Parameters:
tab- the byte array to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(byte[] tab, int offset, int length, OutputStream os) throws IOExceptionThis method allows to write byte array to the output stream.- Parameters:
tab- the byte array to writeoffset- the starting offset of the subarray.length- the length of the subarray.os- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readByteArrayFrom
public static byte[] readByteArrayFrom(InputStream is) throws IOException
This method allows to restore a byte array from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the byte array object or null
- Throws:
IOException- an error occurs during IO operation.
-
readByteArrayFrom
public static byte[] readByteArrayFrom(InputStream is, int length) throws IOException
This method allows to restore a byte array from the input stream.- Parameters:
is- the stream to read data from in order to restore the objectlength- the length of bytes to read- Returns:
- the byte array object or null
- Throws:
IOException- an error occurs during IO operation.
-
isStreamable
public static boolean isStreamable(Object obj)
Test if an object is writable to an output stream.- Parameters:
obj- the object to write- Returns:
- true if the object is writable to an output stream.
-
writeObjectTo
public static void writeObjectTo(Object obj, OutputStream os) throws IOException
This method allows to write an object to the output stream.- Parameters:
obj- the object to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readObjectFrom
public static Object readObjectFrom(InputStream is) throws IOException
This method allows to restore an object from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the object or null
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(Properties p, OutputStream os) throws IOException
This method allows to write a Properties object to the output stream.- Parameters:
p- the Properties object to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readPropertiesFrom
public static Properties readPropertiesFrom(InputStream is) throws IOException
This method allows to restore a Properties object from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the Properties object or null
- Throws:
IOException- an error occurs during IO operation.
-
writeListOfStringTo
public static void writeListOfStringTo(List v, OutputStream os) throws IOException
This method allows to write a generic list of String objects to the output stream.- Parameters:
v- the List object to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readVectorOfStringFrom
public static Vector<String> readVectorOfStringFrom(InputStream is) throws IOException
This method allows to restore a vector of String objects from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the Vector object or null
- Throws:
IOException- an error occurs during IO operation.
-
readArrayListOfStringFrom
public static ArrayList<String> readArrayListOfStringFrom(InputStream is) throws IOException
This method allows to restore a list of String objects from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the ArrayList object or null
- Throws:
IOException- an error occurs during IO operation.
-
writeArrayOfStringTo
public static void writeArrayOfStringTo(String[] array, OutputStream os) throws IOException
This method allows to write a String array to the output stream.- Parameters:
array- the String array to writeos- the stream to write to- Throws:
IOException- an error occurs during IO operation.
-
readArrayOfStringFrom
public static String[] readArrayOfStringFrom(InputStream is) throws IOException
This method allows to restore a String array from the input stream.- Parameters:
is- the stream to read data from in order to restore the String array- Returns:
- the String array or null
- Throws:
IOException- an error occurs during IO operation.
-
writeArrayOfIntTo
public static void writeArrayOfIntTo(int[] array, OutputStream os) throws IOExceptionThis method allows to write a int array to the output stream.- Parameters:
array- the int array to writeos- the stream to write to- Throws:
IOException- an error occurs during IO operation.
-
readArrayOfIntFrom
public static int[] readArrayOfIntFrom(InputStream is) throws IOException
This method allows to restore a int array from the input stream.- Parameters:
is- the stream to read data from in order to restore the int array- Returns:
- the int array or null
- Throws:
IOException- an error occurs during IO operation.
-
writeArrayOfBooleanTo
public static void writeArrayOfBooleanTo(boolean[] array, OutputStream os) throws IOExceptionThis method allows to write a boolean array to the output stream.- Parameters:
array- the boolean array to writeos- the stream to write to- Throws:
IOException- an error occurs during IO operation.
-
readArrayOfBooleanFrom
public static boolean[] readArrayOfBooleanFrom(InputStream is) throws IOException
This method allows to restore a boolean array from the input stream.- Parameters:
is- the stream to read data from in order to restore the boolean array- Returns:
- the boolean array or null
- Throws:
IOException- an error occurs during IO operation.
-
writeTo
public static void writeTo(Properties p, OutputStream os) throws IOException
This method allows to write a java.util.Properties object to the output stream.- Parameters:
p- the java.util.Properties object to writeos- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
readJPropertiesFrom
public static Properties readJPropertiesFrom(InputStream is) throws IOException
This method allows to restore a java.util.Properties object from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the java.util.Properties object or null
- Throws:
IOException- an error occurs during IO operation.
-
getEncodedSize
public static int getEncodedSize(Object obj) throws IOException
- Throws:
IOException
-
encodeValue
public static void encodeValue(Object obj, Encoder encoder) throws Exception
- Throws:
Exception
-
-