Package org.eclipse.birt.core.util
Class IOUtil
- java.lang.Object
-
- org.eclipse.birt.core.util.IOUtil
-
public class IOUtil extends java.lang.Object
A 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 int
INT_LENGTH
protected static java.util.logging.Logger
logger
static int
LONG_LENGTH
static int
MAX_NUMBER_OF_STREAM_BUFFER
static int
RA_STREAM_BUFFER_LENGTH
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
bytesToInteger(byte[] b)
Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.static long
bytesToLong(byte[] b)
Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.static int
getInt(byte[] bytes)
Assemble four bytes to an int value, make sure that the passed bytes length is 4.static int
getTypeIndex(java.lang.Object obValue)
from object class to its type index valuestatic void
integerToBytes(int v, byte[] b)
static void
longToBytes(long v, byte[] b)
static <T> T
read(java.io.DataInputStream inputStream, java.lang.Class<T> clazz)
static boolean
readBool(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 double
readDouble(java.io.DataInputStream inputStream)
Read a double value from an input streamstatic float
readFloat(java.io.DataInputStream inputStream)
Read a float value from an input streamstatic int
readInt(java.io.InputStream inputStream)
Read an int value from an input streamstatic java.util.List
readIntList(java.io.DataInputStream dis)
static java.util.List
readList(java.io.DataInputStream dis)
Read a list from an input streamstatic java.util.List
readList(java.io.DataInputStream dis, java.lang.ClassLoader classLoader)
Read a list from an input streamstatic long
readLong(java.io.DataInputStream inputStream)
Read a long value from an input streamstatic java.util.Map
readMap(java.io.DataInputStream dis)
Read a Map from an input streamstatic java.util.Map
readMap(java.io.DataInputStream dis, java.lang.ClassLoader loader)
Read a Map from an input streamstatic java.lang.Object
readObject(java.io.DataInputStream dis)
Currently these data types are supported.static java.lang.Object
readObject(java.io.DataInputStream dis, java.lang.ClassLoader classLoader)
Currently these data types are supported.static short
readShort(java.io.InputStream inputStream)
Read an int value from an input streamstatic java.lang.String
readString(java.io.DataInputStream dis)
Read a String from an input streamstatic <T> void
write(java.io.DataOutputStream out, T object, java.lang.Class<T> clazz)
static void
writeBool(java.io.OutputStream outputStream, boolean bool)
Write a boolean value to an output streamstatic void
writeBytes(java.io.DataOutputStream dos, byte[] bytes)
Write a bytes to an output streamstatic void
writeDouble(java.io.DataOutputStream outputStream, double value)
Write a double value to an output streamstatic void
writeFloat(java.io.DataOutputStream outputStream, float value)
Write a float value to an output streamstatic void
writeInt(java.io.OutputStream outputStream, int value)
Write an int value to an output streamstatic void
writeIntList(java.io.DataOutputStream dos, java.util.List list)
static void
writeList(java.io.DataOutputStream dos, java.util.List list)
Write a list to an output streamstatic void
writeLong(java.io.DataOutputStream outputStream, long value)
Write a long value to an output streamstatic void
writeMap(java.io.DataOutputStream dos, java.util.Map map)
Write a Map to an output streamstatic void
writeObject(java.io.DataOutputStream dos, java.lang.Object obValue)
When obValue is not supported te be serialized, an IOException will be thrown.static void
writeRawBytes(java.io.DataOutputStream dos, byte[] bytes)
Write a byte array to an output stream only with its raw content.static void
writeShort(java.io.OutputStream outputStream, short value)
Write an int value to an output streamstatic void
writeString(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.IOException
Read 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.IOException
Write 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.IOException
Read 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.IOException
Write 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.IOException
Read 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.IOException
Write 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.IOException
Read 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.IOException
Write 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.IOException
Read 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.IOException
Write 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.IOException
Read 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.IOException
Write 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.IOException
Write 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.IOException
Currently 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.IOException
Currently 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.IOException
When 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.IOException
Read 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.IOException
Write 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.IOException
Read a list from an input stream- Parameters:
dos
-- Returns:
- Throws:
java.io.IOException
BirtException
-
writeBytes
public static final void writeBytes(java.io.DataOutputStream dos, byte[] bytes) throws java.io.IOException
Write a bytes to an output stream- Parameters:
dos
-dataMap
-- Throws:
java.io.IOException
BirtException
-
readList
public static final java.util.List readList(java.io.DataInputStream dis) throws java.io.IOException
Read a list from an input stream- Parameters:
dos
-- Returns:
- Throws:
java.io.IOException
BirtException
-
readList
public static final java.util.List readList(java.io.DataInputStream dis, java.lang.ClassLoader classLoader) throws java.io.IOException
Read a list from an input stream- Parameters:
dos
-- Returns:
- Throws:
java.io.IOException
BirtException
-
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.IOException
Write a list to an output stream- Parameters:
dos
-dataMap
-- Throws:
java.io.IOException
BirtException
-
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.IOException
Read a Map from an input stream- Parameters:
dos
-- Returns:
- Throws:
java.io.IOException
BirtException
-
readMap
public static final java.util.Map readMap(java.io.DataInputStream dis, java.lang.ClassLoader loader) throws java.io.IOException
Read a Map from an input stream- Parameters:
dos
-- Returns:
- Throws:
java.io.IOException
BirtException
-
writeMap
public static final void writeMap(java.io.DataOutputStream dos, java.util.Map map) throws java.io.IOException
Write a Map to an output stream- Parameters:
dos
-map
-- Throws:
java.io.IOException
BirtException
-
-