Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    Copied from RICO (https://github.com/rico-projects/rico)
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
      Copies the content of an input stream to an output stream.
      static void copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize)
      Copies the content of an input stream to an output stream.
      static byte[] fromBase64​(java.lang.String content)
      Converts a Base64 string into a byte array.
      static byte[] fromBase64StripWhitespace​(java.lang.String content)
      Converts a Base64 string into a byte array.
      static byte[] readContent​(java.io.InputStream inputStream)
      Reads the content of an input stream into a byte array.
      static java.lang.String readContentAsString​(java.io.InputStream inputStream, java.nio.charset.Charset encoding)
      Reads the content of an input stream into a string.
      static java.lang.String readContentAsUtf8String​(java.io.InputStream inputStream)
      Reads the content of an input stream into a string using UTF-8 encoding.
      static java.lang.String toBase64​(byte[] bytes)
      Converts a byte array into a Base64 string.
      static java.lang.String toBase64splitIntoMultipleLines​(byte[] bytes, int maxCharsPerLine)
      Converts a byte array into a Base64 string.
      static void writeContent​(java.io.OutputStream outputStream, byte[] rawData)  
      static void writeUtf8Content​(java.io.OutputStream outputStream, java.lang.String content)  
      • Methods inherited from class java.lang.Object

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

      • IOUtils

        public IOUtils()
    • Method Detail

      • toBase64

        public static java.lang.String toBase64​(byte[] bytes)
        Converts a byte array into a Base64 string.
        Parameters:
        bytes - the bytes to convert
        Returns:
        the Base64 representation of the input bytes.
      • toBase64splitIntoMultipleLines

        public static java.lang.String toBase64splitIntoMultipleLines​(byte[] bytes,
                                                                      int maxCharsPerLine)
        Converts a byte array into a Base64 string. The output string is split into multiple lines such that all but the last line have a given length.
        Parameters:
        bytes - the bytes to convert
        maxCharsPerLine - the max num of chars per line
        Returns:
        the Base64 representation of the input bytes.
      • fromBase64

        public static byte[] fromBase64​(java.lang.String content)
        Converts a Base64 string into a byte array.
        Parameters:
        content - the Base64 string
        Returns:
        the byte array representation of the input string.
      • fromBase64StripWhitespace

        public static byte[] fromBase64StripWhitespace​(java.lang.String content)
        Converts a Base64 string into a byte array. Additionally strips all white spaces from the input.
        Parameters:
        content - the Base64 string
        Returns:
        the byte array representation of the input string.
      • copy

        public static void copy​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream)
                         throws java.io.IOException
        Copies the content of an input stream to an output stream.
        Parameters:
        inputStream - the source to read from
        outputStream - the target to write to
        Throws:
        java.io.IOException - if reading from or writing to the streams failed
      • copy

        public static void copy​(java.io.InputStream inputStream,
                                java.io.OutputStream outputStream,
                                int bufferSize)
                         throws java.io.IOException
        Copies the content of an input stream to an output stream.
        Parameters:
        inputStream - the source to read from
        outputStream - the target to write to
        bufferSize - the size of the buffer to allocate for copying
        Throws:
        java.io.IOException - if reading from or writing to the streams failed
      • readContent

        public static byte[] readContent​(java.io.InputStream inputStream)
                                  throws java.io.IOException
        Reads the content of an input stream into a byte array.
        Parameters:
        inputStream - the stream to read from
        Returns:
        array of bytes read from the stream
        Throws:
        java.io.IOException - if reading from the stream failed
      • readContentAsUtf8String

        public static java.lang.String readContentAsUtf8String​(java.io.InputStream inputStream)
                                                        throws java.io.IOException
        Reads the content of an input stream into a string using UTF-8 encoding.
        Parameters:
        inputStream - the stream to read from
        Returns:
        string read from the stream
        Throws:
        java.io.IOException - if reading from the stream failed
      • readContentAsString

        public static java.lang.String readContentAsString​(java.io.InputStream inputStream,
                                                           java.nio.charset.Charset encoding)
                                                    throws java.io.IOException
        Reads the content of an input stream into a string.
        Parameters:
        inputStream - the stream to read from
        encoding - the character set to use when converting the bytes to characters
        Returns:
        string read from the stream
        Throws:
        java.io.IOException - if reading from the stream failed
      • writeUtf8Content

        public static void writeUtf8Content​(java.io.OutputStream outputStream,
                                            java.lang.String content)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeContent

        public static void writeContent​(java.io.OutputStream outputStream,
                                        byte[] rawData)
                                 throws java.io.IOException
        Throws:
        java.io.IOException