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 Details

  • 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:
      outputStream -
      str -
      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