Class Streams


  • public final class Streams
    extends java.lang.Object
    Utility class for stream treatment.
    Author:
    agz, jsc
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] convertInputStreamToByteArray​(java.io.InputStream inputStream)
      Returns the content of the specified InputStream as a byte[], which has exactly the size of the content.
      static java.lang.String convertInputStreamToString​(java.io.InputStream inputStream, java.nio.charset.Charset charset)
      Reads the content of the specified InputStream to a byte[], which will then be interpreted as String with the given encoding.
      static long stream​(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize)
      Streams an InputStream completely to an OutputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • stream

        public static long stream​(java.io.InputStream inputStream,
                                  java.io.OutputStream outputStream,
                                  int bufferSize)
                           throws java.io.IOException
        Streams an InputStream completely to an OutputStream. The binary data from inputStream will be stored to outputStream in chunks of the size bufferSize until the end of inputStream is reached.
        Parameters:
        inputStream - the input stream to read from
        outputStream - the output stream to write to
        bufferSize - the size of the chunks to use
        Returns:
        the number of bytes streamed
        Throws:
        java.io.IOException
      • convertInputStreamToByteArray

        public static byte[] convertInputStreamToByteArray​(java.io.InputStream inputStream)
                                                    throws java.io.IOException
        Returns the content of the specified InputStream as a byte[], which has exactly the size of the content.

        The specified InputStream must not be null.

        Parameters:
        inputStream - InputStream to convert into a byte[]
        Returns:
        byte[] with the content of the specified InputStream
        Throws:
        java.io.IOException - on errors reading the inputStream
      • convertInputStreamToString

        public static java.lang.String convertInputStreamToString​(java.io.InputStream inputStream,
                                                                  java.nio.charset.Charset charset)
                                                           throws java.io.IOException
        Reads the content of the specified InputStream to a byte[], which will then be interpreted as String with the given encoding.
        Parameters:
        inputStream - InputStream the input stream to read from
        charset - the Charset to decode the bytes to a String. Must not be null.
        Returns:
        a String being the content of the given InputStream
        Throws:
        java.io.IOException