Package org.eclipse.birt.core.util
Class IOUtil
- java.lang.Object
-
- org.eclipse.birt.core.util.IOUtil
-
public class IOUtil extends java.lang.ObjectA util class to read or write primitive Java data type. Please notice, every method has a stream which might be input stream or output stream as parameters. This stream should be already added a buffered layer underlying it.
-
-
Field Summary
Fields Modifier and Type Field Description static intINT_LENGTHprotected static java.util.logging.Loggerloggerstatic intLONG_LENGTHstatic intMAX_NUMBER_OF_STREAM_BUFFERstatic intRA_STREAM_BUFFER_LENGTH
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbytesToInteger(byte[] b)Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.static longbytesToLong(byte[] b)Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.static intgetInt(byte[] bytes)Assemble four bytes to an int value, make sure that the passed bytes length is 4.static intgetTypeIndex(java.lang.Object obValue)from object class to its type index valuestatic voidintegerToBytes(int v, byte[] b)static voidlongToBytes(long v, byte[] b)static <T> Tread(java.io.DataInputStream inputStream, java.lang.Class<T> clazz)static booleanreadBool(java.io.InputStream inputStream)Read a bool value from an input streamstatic byte[]readBytes(java.io.DataInputStream dis)Read a list from an input streamstatic doublereadDouble(java.io.DataInputStream inputStream)Read a double value from an input streamstatic floatreadFloat(java.io.DataInputStream inputStream)Read a float value from an input streamstatic intreadInt(java.io.InputStream inputStream)Read an int value from an input streamstatic java.util.ListreadIntList(java.io.DataInputStream dis)static java.util.ListreadList(java.io.DataInputStream dis)Read a list from an input streamstatic java.util.ListreadList(java.io.DataInputStream dis, java.lang.ClassLoader classLoader)Read a list from an input streamstatic longreadLong(java.io.DataInputStream inputStream)Read a long value from an input streamstatic java.util.MapreadMap(java.io.DataInputStream dis)Read a Map from an input streamstatic java.util.MapreadMap(java.io.DataInputStream dis, java.lang.ClassLoader loader)Read a Map from an input streamstatic java.lang.ObjectreadObject(java.io.DataInputStream dis)Currently these data types are supported.static java.lang.ObjectreadObject(java.io.DataInputStream dis, java.lang.ClassLoader classLoader)Currently these data types are supported.static shortreadShort(java.io.InputStream inputStream)Read an int value from an input streamstatic java.lang.StringreadString(java.io.DataInputStream dis)Read a String from an input streamstatic <T> voidwrite(java.io.DataOutputStream out, T object, java.lang.Class<T> clazz)static voidwriteBool(java.io.OutputStream outputStream, boolean bool)Write a boolean value to an output streamstatic voidwriteBytes(java.io.DataOutputStream dos, byte[] bytes)Write a bytes to an output streamstatic voidwriteDouble(java.io.DataOutputStream outputStream, double value)Write a double value to an output streamstatic voidwriteFloat(java.io.DataOutputStream outputStream, float value)Write a float value to an output streamstatic voidwriteInt(java.io.OutputStream outputStream, int value)Write an int value to an output streamstatic voidwriteIntList(java.io.DataOutputStream dos, java.util.List list)static voidwriteList(java.io.DataOutputStream dos, java.util.List list)Write a list to an output streamstatic voidwriteLong(java.io.DataOutputStream outputStream, long value)Write a long value to an output streamstatic voidwriteMap(java.io.DataOutputStream dos, java.util.Map map)Write a Map to an output streamstatic voidwriteObject(java.io.DataOutputStream dos, java.lang.Object obValue)When obValue is not supported te be serialized, an IOException will be thrown.static voidwriteRawBytes(java.io.DataOutputStream dos, byte[] bytes)Write a byte array to an output stream only with its raw content.static voidwriteShort(java.io.OutputStream outputStream, short value)Write an int value to an output streamstatic voidwriteString(java.io.DataOutputStream dos, java.lang.String str)Write a String value to an output stream
-
-
-
Field Detail
-
INT_LENGTH
public static final int INT_LENGTH
- See Also:
- Constant Field Values
-
LONG_LENGTH
public static final int LONG_LENGTH
- See Also:
- Constant Field Values
-
RA_STREAM_BUFFER_LENGTH
public static final int RA_STREAM_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
MAX_NUMBER_OF_STREAM_BUFFER
public static final int MAX_NUMBER_OF_STREAM_BUFFER
- See Also:
- Constant Field Values
-
logger
protected static java.util.logging.Logger logger
-
-
Method Detail
-
read
public static final <T> T read(java.io.DataInputStream inputStream, java.lang.Class<T> clazz) throws java.io.IOException- Throws:
java.io.IOException
-
write
public static final <T> void write(java.io.DataOutputStream out, T object, java.lang.Class<T> clazz) throws java.io.IOException- Throws:
java.io.IOException
-
readShort
public static final short readShort(java.io.InputStream inputStream) throws java.io.IOExceptionRead an int value from an input stream- Parameters:
inputStream-- Returns:
- int value
- Throws:
java.io.IOException
-
writeShort
public static final void writeShort(java.io.OutputStream outputStream, short value) throws java.io.IOExceptionWrite an int value to an output stream- Parameters:
outputStream-value-- Throws:
java.io.IOException
-
readInt
public static final int readInt(java.io.InputStream inputStream) throws java.io.IOExceptionRead an int value from an input stream- Parameters:
inputStream-- Returns:
- int value
- Throws:
java.io.IOException
-
writeInt
public static final void writeInt(java.io.OutputStream outputStream, int value) throws java.io.IOExceptionWrite an int value to an output stream- Parameters:
outputStream-value-- Throws:
java.io.IOException
-
getInt
public static final int getInt(byte[] bytes)
Assemble four bytes to an int value, make sure that the passed bytes length is 4.- Parameters:
bytes-- Returns:
- int value of bytes
-
bytesToInteger
public static final int bytesToInteger(byte[] b)
Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.- Parameters:
bytes-- Returns:
- int value of bytes
-
bytesToLong
public static final long bytesToLong(byte[] b)
Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.- Parameters:
bytes-- Returns:
- int value of bytes
-
integerToBytes
public static final void integerToBytes(int v, byte[] b)
-
longToBytes
public static final void longToBytes(long v, byte[] b)
-
readBool
public static final boolean readBool(java.io.InputStream inputStream) throws java.io.IOExceptionRead a bool value from an input stream- Parameters:
inputStream-- Returns:
- boolean value
- Throws:
java.io.IOException
-
writeBool
public static final void writeBool(java.io.OutputStream outputStream, boolean bool) throws java.io.IOExceptionWrite a boolean value to an output stream- Parameters:
outputStream-bool-- Throws:
java.io.IOException
-
readFloat
public static final float readFloat(java.io.DataInputStream inputStream) throws java.io.IOExceptionRead a float value from an input stream- Parameters:
inputStream-- Returns:
- int value
- Throws:
java.io.IOException
-
writeFloat
public static final void writeFloat(java.io.DataOutputStream outputStream, float value) throws java.io.IOExceptionWrite a float value to an output stream- Parameters:
outputStream-value-- Throws:
java.io.IOException
-
readDouble
public static final double readDouble(java.io.DataInputStream inputStream) throws java.io.IOExceptionRead a double value from an input stream- Parameters:
inputStream-- Returns:
- int value
- Throws:
java.io.IOException
-
writeDouble
public static final void writeDouble(java.io.DataOutputStream outputStream, double value) throws java.io.IOExceptionWrite a double value to an output stream- Parameters:
outputStream-value-- Throws:
java.io.IOException
-
readLong
public static final long readLong(java.io.DataInputStream inputStream) throws java.io.IOExceptionRead a long value from an input stream- Parameters:
inputStream-- Returns:
- int value
- Throws:
java.io.IOException
-
writeLong
public static final void writeLong(java.io.DataOutputStream outputStream, long value) throws java.io.IOExceptionWrite a long value to an output stream- Parameters:
outputStream-value-- Throws:
java.io.IOException
-
writeRawBytes
public static final void writeRawBytes(java.io.DataOutputStream dos, byte[] bytes) throws java.io.IOExceptionWrite a byte array to an output stream only with its raw content.- Parameters:
dos-bytes- , it can not be null- Throws:
java.io.IOException
-
getTypeIndex
public static int getTypeIndex(java.lang.Object obValue)
from object class to its type index value- Parameters:
obValue-- Returns:
-
readObject
public static final java.lang.Object readObject(java.io.DataInputStream dis) throws java.io.IOExceptionCurrently these data types are supported. Integer Float Double BigDecimal Date Time Timestamp Boolean String byte[] List Map- Returns:
- Throws:
java.io.IOException
-
readObject
public static final java.lang.Object readObject(java.io.DataInputStream dis, java.lang.ClassLoader classLoader) throws java.io.IOExceptionCurrently these data types are supported. Integer Float Double BigDecimal Date Time Timestamp Boolean String byte[] List Map- Returns:
- Throws:
java.io.IOException
-
writeObject
public static final void writeObject(java.io.DataOutputStream dos, java.lang.Object obValue) throws java.io.IOExceptionWhen obValue is not supported te be serialized, an IOException will be thrown.- Parameters:
dos-obValue-- Throws:
java.io.IOException
-
readString
public static final java.lang.String readString(java.io.DataInputStream dis) throws java.io.IOExceptionRead a String from an input stream- Parameters:
inputStream-- Returns:
- an String
- Throws:
java.io.IOException
-
writeString
public static final void writeString(java.io.DataOutputStream dos, java.lang.String str) throws java.io.IOExceptionWrite a String value to an output stream- Parameters:
outputStream-str-- Throws:
java.io.IOException
-
readBytes
public static final byte[] readBytes(java.io.DataInputStream dis) throws java.io.IOExceptionRead a list from an input stream- Parameters:
dos-- Returns:
- Throws:
java.io.IOExceptionBirtException
-
writeBytes
public static final void writeBytes(java.io.DataOutputStream dos, byte[] bytes) throws java.io.IOExceptionWrite a bytes to an output stream- Parameters:
dos-dataMap-- Throws:
java.io.IOExceptionBirtException
-
readList
public static final java.util.List readList(java.io.DataInputStream dis) throws java.io.IOExceptionRead a list from an input stream- Parameters:
dos-- Returns:
- Throws:
java.io.IOExceptionBirtException
-
readList
public static final java.util.List readList(java.io.DataInputStream dis, java.lang.ClassLoader classLoader) throws java.io.IOExceptionRead a list from an input stream- Parameters:
dos-- Returns:
- Throws:
java.io.IOExceptionBirtException
-
readIntList
public static final java.util.List readIntList(java.io.DataInputStream dis) throws java.io.IOException- Throws:
java.io.IOException
-
writeList
public static final void writeList(java.io.DataOutputStream dos, java.util.List list) throws java.io.IOExceptionWrite a list to an output stream- Parameters:
dos-dataMap-- Throws:
java.io.IOExceptionBirtException
-
writeIntList
public static final void writeIntList(java.io.DataOutputStream dos, java.util.List list) throws java.io.IOException- Throws:
java.io.IOException
-
readMap
public static final java.util.Map readMap(java.io.DataInputStream dis) throws java.io.IOExceptionRead a Map from an input stream- Parameters:
dos-- Returns:
- Throws:
java.io.IOExceptionBirtException
-
readMap
public static final java.util.Map readMap(java.io.DataInputStream dis, java.lang.ClassLoader loader) throws java.io.IOExceptionRead a Map from an input stream- Parameters:
dos-- Returns:
- Throws:
java.io.IOExceptionBirtException
-
writeMap
public static final void writeMap(java.io.DataOutputStream dos, java.util.Map map) throws java.io.IOExceptionWrite a Map to an output stream- Parameters:
dos-map-- Throws:
java.io.IOExceptionBirtException
-
-