Class StreamUtil


  • public final class StreamUtil
    extends Object
    • Constructor Detail

      • StreamUtil

        public StreamUtil()
    • Method Detail

      • writeTo

        public static void writeTo​(boolean b,
                                   OutputStream os)
                            throws IOException
        This method allows to write a boolean to the output stream.
        Parameters:
        b - the boolean to write
        os - 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 IOException
        This method allows to write a byte to the output stream.
        Parameters:
        b - the byte to write
        os - 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 IOException
        This method allows to write a short to the output stream.
        Parameters:
        s - the short to write
        os - 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 IOException
        This method allows to write an integer to the output stream.
        Parameters:
        i - the integer to write
        os - 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 IOException
        This method allows to write a long to the output stream.
        Parameters:
        l - the long to write
        os - 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 IOException
        This method allows to write a float to the output stream.
        Parameters:
        f - the float to write
        os - 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 IOException
        This method allows to write a double to the output stream.
        Parameters:
        d - the double to write
        os - 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 write
        os - 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 IOException
        This method allows to write byte array to the output stream.
        Parameters:
        tab - the byte array to write
        os - 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 IOException
        This method allows to write byte array to the output stream.
        Parameters:
        tab - the byte array to write
        offset - 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 object
        length - 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 write
        os - 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 write
        os - 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 write
        os - 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 write
        os - 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 IOException
        This method allows to write a int array to the output stream.
        Parameters:
        array - the int array to write
        os - 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 IOException
        This method allows to write a boolean array to the output stream.
        Parameters:
        array - the boolean array to write
        os - 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 write
        os - 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.