Class IoUtils


  • public final class IoUtils
    extends java.lang.Object
    General utility methods for working with IO.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private IoUtils()
      The private constructor of IoUtils.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void cleanup​(java.io.Closeable... closeables)
      Closes the Closeable objects and ignore any IOException or null pointers.
      static void closeQuietly​(java.io.Closeable closeable)
      Closes the given Closeable quietly by ignoring IOException.
      static void readFully​(java.io.InputStream in, byte[] buf, int off, int len)
      Does the readFully based on the Input read.
      static void readFully​(Input in, long position, byte[] buffer, int offset, int length)
      Does the readFully based on Input's positioned read.
      • Methods inherited from class java.lang.Object

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

      • IoUtils

        private IoUtils()
        The private constructor of IoUtils.
    • Method Detail

      • cleanup

        public static void cleanup​(java.io.Closeable... closeables)
        Closes the Closeable objects and ignore any IOException or null pointers. Must only be used for cleanup in exception handlers.
        Parameters:
        closeables - the objects to close.
      • closeQuietly

        public static void closeQuietly​(java.io.Closeable closeable)
        Closes the given Closeable quietly by ignoring IOException.
        Parameters:
        closeable - The resource to close.
        Since:
        1.1.0
      • readFully

        public static void readFully​(Input in,
                                     long position,
                                     byte[] buffer,
                                     int offset,
                                     int length)
                              throws java.io.IOException
        Does the readFully based on Input's positioned read. This does not change the current offset of the stream and is thread-safe.
        Parameters:
        in - the input source.
        position - the given position.
        buffer - the buffer to be read.
        length - the maximum number of bytes to read.
        offset - the start offset in array buffer.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readFully

        public static void readFully​(java.io.InputStream in,
                                     byte[] buf,
                                     int off,
                                     int len)
                              throws java.io.IOException
        Does the readFully based on the Input read.
        Parameters:
        in - the input stream of bytes.
        buf - the buffer to be read.
        off - the start offset in array buffer.
        len - the maximum number of bytes to read.
        Throws:
        java.io.IOException - if an I/O error occurs.