Class IOUtils

java.lang.Object
org.openl.util.IOUtils

public class IOUtils extends Object
A set of utils to work with general IO streams.
Author:
Yury Molchan
  • Constructor Details

    • IOUtils

      public IOUtils()
  • Method Details

    • closeQuietly

      public static void closeQuietly(AutoCloseable closeable)
      Unconditionally close a AutoCloseable.

      Equivalent to AutoCloseable.close(), except any exceptions will be ignored.

      Parameters:
      closeable - the object to close, may be null or already closed
    • copyAndClose

      public static void copyAndClose(InputStream input, OutputStream output) throws IOException
      Copy bytes from InputStream to an OutputStream and close them after.

      Parameters:
      input - the InputStream to read from
      output - the OutputStream to write to
      Throws:
      NullPointerException - if the input or output is null
      IOException - if an I/O error occurs
    • copy

      public static void copy(InputStream input, OutputStream output, byte[] buffer) throws IOException
      Copy bytes from InputStream to an OutputStream.

      This method uses the provided buffer, so there is no need to use a BufferedInputStream.

      Parameters:
      input - the InputStream to read from
      output - the OutputStream to write to
      buffer - the buffer to use for the copy
      Throws:
      NullPointerException - if the input or output is null
      IOException - if an I/O error occurs
    • toInputStream

      public static InputStream toInputStream(CharSequence input)
      Convert the specified CharSequence to an input stream, encoded as bytes using UTF-8 character encoding.
      Parameters:
      input - the CharSequence to convert
      Returns:
      an input stream