Package org.eclipse.birt.core.util

# Class IOUtil

java.lang.Object
org.eclipse.birt.core.util.IOUtil

public class IOUtil extends 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 final int`
`INT_LENGTH`
`protected static Logger`
`logger`
`static final int`
`LONG_LENGTH`
`static final int`
`MAX_NUMBER_OF_STREAM_BUFFER`
`static final int`
`RA_STREAM_BUFFER_LENGTH`

## Constructor Summary

Constructors
Constructor
Description
`IOUtil()`

## Method Summary

Modifier and Type
Method
Description
`static final int`
`bytesToInteger(byte[] b)`
Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.
`static final long`
`bytesToLong(byte[] b)`
Assemble eight bytes to an long value, make sure that the passed bytes length larger than 8.
`static final int`
`getInt(byte[] bytes)`
Assemble four bytes to an int value, make sure that the passed bytes length is 4.
`static int`
`getTypeIndex(Object obValue)`
from object class to its type index value
`static final void`
`integerToBytes(int v, byte[] b)`
`static final void`
`longToBytes(long v, byte[] b)`
`static final <T> T`
`read(DataInputStream inputStream, Class<T> clazz)`
`static final boolean`
`readBool(InputStream inputStream)`
Read a bool value from an input stream
`static final byte[]`
`readBytes(DataInputStream dis)`
Read a list from an input stream
`static final double`
`readDouble(DataInputStream inputStream)`
Read a double value from an input stream
`static final float`
`readFloat(DataInputStream inputStream)`
Read a float value from an input stream
`static final int`
`readInt(InputStream inputStream)`
Read an int value from an input stream
`static final List`
`readIntList(DataInputStream dis)`
`static final List`
`readList(DataInputStream dis)`
Read a list from an input stream
`static final List`
`readList(DataInputStream dis, ClassLoader classLoader)`
Read a list from an input stream
`static final long`
`readLong(DataInputStream inputStream)`
Read a long value from an input stream
`static final Map`
`readMap(DataInputStream dis)`
Read a Map from an input stream
`static final Map`
`readMap(DataInputStream dis, ClassLoader loader)`
Read a Map from an input stream
`static final Object`
`readObject(DataInputStream dis)`
Currently these data types are supported.
`static final Object`
`readObject(DataInputStream dis, ClassLoader classLoader)`
Currently these data types are supported.
`static final short`
`readShort(InputStream inputStream)`
Read an int value from an input stream
`static final String`
`readString(DataInputStream dis)`
Read a String from an input stream
`static final <T> void`
`write(DataOutputStream out, T object, Class<T> clazz)`
`static final void`
`writeBool(OutputStream outputStream, boolean bool)`
Write a boolean value to an output stream
`static final void`
`writeBytes(DataOutputStream dos, byte[] bytes)`
Write a bytes to an output stream
`static final void`
`writeDouble(DataOutputStream outputStream, double value)`
Write a double value to an output stream
`static final void`
`writeFloat(DataOutputStream outputStream, float value)`
Write a float value to an output stream
`static final void`
`writeInt(OutputStream outputStream, int value)`
Write an int value to an output stream
`static final void`
`writeIntList(DataOutputStream dos, List list)`
`static final void`
`writeList(DataOutputStream dos, List list)`
Write a list to an output stream
`static final void`
`writeLong(DataOutputStream outputStream, long value)`
Write a long value to an output stream
`static final void`
`writeMap(DataOutputStream dos, Map map)`
Write a Map to an output stream
`static final void`
`writeObject(DataOutputStream dos, Object obValue)`
When obValue is not supported te be serialized, an IOException will be thrown.
`static final void`
`writeRawBytes(DataOutputStream dos, byte[] bytes)`
Write a byte array to an output stream only with its raw content.
`static final void`
`writeShort(OutputStream outputStream, short value)`
Write an int value to an output stream
`static final void`
`writeString(DataOutputStream dos, String str)`
Write a String value to an output stream

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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 Logger logger

## Constructor Details

### IOUtil

public IOUtil()

## Method Details

### read

public static final <T> T read(DataInputStream inputStream, Class<T> clazz) throws IOException

Throws:
  `IOException`

### write

public static final <T> void write(DataOutputStream out, T object, Class<T> clazz) throws IOException

Throws:
  `IOException`

### readShort

public static final short readShort(InputStream inputStream) throws IOException
Read an int value from an input stream

Parameters:
  `inputStream` -
Returns:
  int value
Throws:
  `IOException`

### writeShort

public static final void writeShort(OutputStream outputStream, short value) throws IOException
Write an int value to an output stream

Parameters:
  `outputStream` -
  `value` -
Throws:
  `IOException`

### readInt

public static final int readInt(InputStream inputStream) throws IOException
Read an int value from an input stream

Parameters:
  `inputStream` -
Returns:
  int value
Throws:
  `IOException`

### writeInt

public static final void writeInt(OutputStream outputStream, int value) throws IOException
Write an int value to an output stream

Parameters:
  `outputStream` -
  `value` -
Throws:
  `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(InputStream inputStream) throws IOException
Read a bool value from an input stream

Parameters:
  `inputStream` -
Returns:
  boolean value
Throws:
  `IOException`

### writeBool

public static final void writeBool(OutputStream outputStream, boolean bool) throws IOException
Write a boolean value to an output stream

Parameters:
  `outputStream` -
  `bool` -
Throws:
  `IOException`

### readFloat

public static final float readFloat(DataInputStream inputStream) throws IOException
Read a float value from an input stream

Parameters:
  `inputStream` -
Returns:
  int value
Throws:
  `IOException`

### writeFloat

public static final void writeFloat(DataOutputStream outputStream, float value) throws IOException
Write a float value to an output stream

Parameters:
  `outputStream` -
  `value` -
Throws:
  `IOException`

### readDouble

public static final double readDouble(DataInputStream inputStream) throws IOException
Read a double value from an input stream

Parameters:
  `inputStream` -
Returns:
  int value
Throws:
  `IOException`

### writeDouble

public static final void writeDouble(DataOutputStream outputStream, double value) throws IOException
Write a double value to an output stream

Parameters:
  `outputStream` -
  `value` -
Throws:
  `IOException`

### readLong

public static final long readLong(DataInputStream inputStream) throws IOException
Read a long value from an input stream

Parameters:
  `inputStream` -
Returns:
  int value
Throws:
  `IOException`

### writeLong

public static final void writeLong(DataOutputStream outputStream, long value) throws IOException
Write a long value to an output stream

Parameters:
  `outputStream` -
  `value` -
Throws:
  `IOException`

### writeRawBytes

public static final void writeRawBytes(DataOutputStream dos, byte[] bytes) throws IOException
Write a byte array to an output stream only with its raw content.

Parameters:
  `dos` -
  `bytes` - , it can not be null
Throws:
  `IOException`

### getTypeIndex

public static int getTypeIndex(Object obValue)
from object class to its type index value

Parameters:
  `obValue` -
Returns:

### readObject

public static final Object readObject(DataInputStream dis) throws IOException
Currently these data types are supported. Integer Float Double BigDecimal Date Time Timestamp Boolean String byte[] List Map

Returns:
Throws:
  `IOException`

### readObject

public static final Object readObject(DataInputStream dis, ClassLoader classLoader) throws IOException
Currently these data types are supported. Integer Float Double BigDecimal Date Time Timestamp Boolean String byte[] List Map

Returns:
Throws:
  `IOException`

### writeObject

public static final void writeObject(DataOutputStream dos, Object obValue) throws IOException
When obValue is not supported te be serialized, an IOException will be thrown.

Parameters:
  `dos` -
  `obValue` -
Throws:
  `IOException`

### readString

public static final String readString(DataInputStream dis) throws IOException
Read a String from an input stream

Parameters:
  `inputStream` -
Returns:
  an String
Throws:
  `IOException`

### writeString

public static final void writeString(DataOutputStream dos, String str) throws IOException
Write a String value to an output stream

Parameters:
  `str` -
  `outputStream` -
Throws:
  `IOException`

### readBytes

public static final byte[] readBytes(DataInputStream dis) throws IOException
Read a list from an input stream

Parameters:
  `dos` -
Returns:
Throws:
  `IOException`
  `BirtException`

### writeBytes

public static final void writeBytes(DataOutputStream dos, byte[] bytes) throws IOException
Write a bytes to an output stream

Parameters:
  `dos` -
  `dataMap` -
Throws:
  `IOException`
  `BirtException`

### readList

public static final List readList(DataInputStream dis) throws IOException
Read a list from an input stream

Parameters:
  `dos` -
Returns:
Throws:
  `IOException`
  `BirtException`

### readList

public static final List readList(DataInputStream dis, ClassLoader classLoader) throws IOException
Read a list from an input stream

Parameters:
  `dos` -
Returns:
Throws:
  `IOException`
  `BirtException`

### readIntList

public static final List readIntList(DataInputStream dis) throws IOException

Throws:
  `IOException`

### writeList

public static final void writeList(DataOutputStream dos, List list) throws IOException
Write a list to an output stream

Parameters:
  `dos` -
  `dataMap` -
Throws:
  `IOException`
  `BirtException`

### writeIntList

public static final void writeIntList(DataOutputStream dos, List list) throws IOException

Throws:
  `IOException`

### readMap

public static final Map readMap(DataInputStream dis) throws IOException
Read a Map from an input stream

Parameters:
  `dos` -
Returns:
Throws:
  `IOException`
  `BirtException`

### readMap

public static final Map readMap(DataInputStream dis, ClassLoader loader) throws IOException
Read a Map from an input stream

Parameters:
  `dos` -
Returns:
Throws:
  `IOException`
  `BirtException`

### writeMap

public static final void writeMap(DataOutputStream dos, Map map) throws IOException
Write a Map to an output stream

Parameters:
  `dos` -
  `map` -
Throws:
  `IOException`
  `BirtException`