Class IO

java.lang.Object
org.eclipse.jetty.util.IO

public class IO extends Object
IO Utilities. Provides stream handling utilities in singleton Threadpool implementation accessed by static members.
  • Field Details

  • Constructor Details

    • IO

      public IO()
  • Method Details

    • copy

      public static void copy(InputStream in, OutputStream out) throws IOException
      Copy Stream in to Stream out until EOF or exception.
      Parameters:
      in - the input stream to read from (until EOF)
      out - the output stream to write to
      Throws:
      IOException - if unable to copy streams
    • copy

      public static void copy(Reader in, Writer out) throws IOException
      Copy Reader to Writer out until EOF or exception.
      Parameters:
      in - the read to read from (until EOF)
      out - the writer to write to
      Throws:
      IOException - if unable to copy the streams
    • copy

      public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException
      Copy Stream in to Stream for byteCount bytes or until EOF or exception.
      Parameters:
      in - the stream to read from
      out - the stream to write to
      byteCount - the number of bytes to copy
      Throws:
      IOException - if unable to copy the streams
    • copy

      public static void copy(Reader in, Writer out, long byteCount) throws IOException
      Copy Reader to Writer for byteCount bytes or until EOF or exception.
      Parameters:
      in - the Reader to read from
      out - the Writer to write to
      byteCount - the number of bytes to copy
      Throws:
      IOException - if unable to copy streams
    • copy

      public static void copy(File from, File to) throws IOException
      Copy files or directories
      Parameters:
      from - the file to copy
      to - the destination to copy to
      Throws:
      IOException - if unable to copy
    • copyDir

      public static void copyDir(File from, File to) throws IOException
      Throws:
      IOException
    • copyFile

      public static void copyFile(File from, File to) throws IOException
      Throws:
      IOException
    • toString

      public static String toString(Path path, Charset charset) throws IOException
      Read Path to string.
      Parameters:
      path - the path to read from (until EOF)
      charset - the charset to read with
      Returns:
      the String parsed from path (default Charset)
      Throws:
      IOException - if unable to read the path (or handle the charset)
    • toString

      public static String toString(InputStream in) throws IOException
      Read input stream to string.
      Parameters:
      in - the stream to read from (until EOF)
      Returns:
      the String parsed from stream (default Charset)
      Throws:
      IOException - if unable to read the stream (or handle the charset)
    • toString

      public static String toString(InputStream in, String encoding) throws IOException
      Read input stream to string.
      Parameters:
      in - the stream to read from (until EOF)
      encoding - the encoding to use (can be null to use default Charset)
      Returns:
      the String parsed from the stream
      Throws:
      IOException - if unable to read the stream (or handle the charset)
    • toString

      public static String toString(InputStream in, Charset encoding) throws IOException
      Read input stream to string.
      Parameters:
      in - the stream to read from (until EOF)
      encoding - the Charset to use (can be null to use default Charset)
      Returns:
      the String parsed from the stream
      Throws:
      IOException - if unable to read the stream (or handle the charset)
    • toString

      public static String toString(Reader in) throws IOException
      Read input stream to string.
      Parameters:
      in - the reader to read from (until EOF)
      Returns:
      the String parsed from the reader
      Throws:
      IOException - if unable to read the stream (or handle the charset)
    • delete

      public static boolean delete(File file)
      Delete File. This delete will recursively delete directories - BE CAREFUL
      Parameters:
      file - The file (or directory) to be deleted.
      Returns:
      true if file was deleted, or directory referenced was deleted. false if file doesn't exist, or was null.
    • isEmptyDir

      public static boolean isEmptyDir(File dir)
      Test if directory is empty.
      Parameters:
      dir - the directory
      Returns:
      true if directory is null, doesn't exist, or has no content. false if not a directory, or has contents
    • close

      public static void close(Closeable closeable)
      Closes an arbitrary closable, and logs exceptions at ignore level
      Parameters:
      closeable - the closeable to close
    • close

      public static void close(InputStream is)
      closes an input stream, and logs exceptions
      Parameters:
      is - the input stream to close
    • close

      public static void close(OutputStream os)
      closes an output stream, and logs exceptions
      Parameters:
      os - the output stream to close
    • close

      public static void close(Reader reader)
      closes a reader, and logs exceptions
      Parameters:
      reader - the reader to close
    • close

      public static void close(Writer writer)
      closes a writer, and logs exceptions
      Parameters:
      writer - the writer to close
    • readBytes

      public static byte[] readBytes(InputStream in) throws IOException
      Throws:
      IOException
    • write

      public static long write(GatheringByteChannel out, ByteBuffer[] buffers, int offset, int length) throws IOException
      A gathering write utility wrapper.

      This method wraps a gather write with a loop that handles the limitations of some operating systems that have a limit on the number of buffers written. The method loops on the write until either all the content is written or no progress is made.

      Parameters:
      out - The GatheringByteChannel to write to
      buffers - The buffers to write
      offset - The offset into the buffers array
      length - The length in buffers to write
      Returns:
      The total bytes written
      Throws:
      IOException - if unable write to the GatheringByteChannel
    • getNullStream

      public static OutputStream getNullStream()
      Returns:
      An outputstream to nowhere
    • getClosedStream

      public static InputStream getClosedStream()
      Returns:
      An outputstream to nowhere
    • getNullWriter

      public static Writer getNullWriter()
      Returns:
      An writer to nowhere
    • getNullPrintWriter

      public static PrintWriter getNullPrintWriter()
      Returns:
      An writer to nowhere