Class IOUtils

java.lang.Object
net.adoptopenjdk.icedteaweb.io.IOUtils

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

    • IOUtils

      public IOUtils()
  • Method Details

    • toBase64

      public static 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 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(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(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(InputStream inputStream, OutputStream outputStream) throws 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:
      IOException - if reading from or writing to the streams failed
    • copy

      public static void copy(InputStream inputStream, OutputStream outputStream, int bufferSize) throws 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:
      IOException - if reading from or writing to the streams failed
    • readContent

      public static byte[] readContent(InputStream inputStream) throws 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:
      IOException - if reading from the stream failed
    • readContentAsUtf8String

      public static String readContentAsUtf8String(InputStream inputStream) throws 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:
      IOException - if reading from the stream failed
    • readContentAsString

      public static String readContentAsString(InputStream inputStream, Charset encoding) throws 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:
      IOException - if reading from the stream failed
    • writeUtf8Content

      public static void writeUtf8Content(OutputStream outputStream, String content) throws IOException
      Throws:
      IOException
    • writeContent

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