Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    An utility class for I/O related functionality.
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(org.slf4j.Logger log, java.io.Closeable closeable)
      Close the Closeable object and ignore any IOException or null pointers.
      static void close​(org.slf4j.Logger log, java.io.Closeable... closeables)
      Close the Closeable objects and ignore any IOException or null pointers.
      static boolean confirmPrompt​(java.lang.String prompt)
      Confirm prompt for the console operations.
      static java.io.File createTempDir​(java.lang.String prefix, java.lang.String suffix)
      Create a temp directory with given prefix and suffix.
      static java.io.File createTempDir​(java.lang.String prefix, java.lang.String suffix, java.io.File dir)
      Create a temp directory with given prefix and suffix in the specified dir.
      static java.io.File createTempFileAndDeleteOnExit​(java.lang.String prefix, java.lang.String suffix)
      Create a temp directory with given prefix and suffix.
      static void writeFully​(java.nio.channels.WritableByteChannel bc, java.nio.ByteBuffer buf)
      Write a ByteBuffer to a WritableByteChannel, handling short writes.
      • 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

      • close

        public static void close​(org.slf4j.Logger log,
                                 java.io.Closeable... closeables)
        Close the Closeable objects and ignore any IOException or null pointers. Must only be used for cleanup in exception handlers.
        Parameters:
        log - the log to record problems to at debug level. Can be null.
        closeables - the objects to close
      • close

        public static void close​(org.slf4j.Logger log,
                                 java.io.Closeable closeable)
        Close the Closeable object and ignore any IOException or null pointers. Must only be used for cleanup in exception handlers.
        Parameters:
        log - the log to record problems to at debug level. Can be null.
        closeable - the objects to close
      • confirmPrompt

        public static boolean confirmPrompt​(java.lang.String prompt)
                                     throws java.io.IOException
        Confirm prompt for the console operations.
        Parameters:
        prompt - Prompt message to be displayed on console
        Returns:
        Returns true if confirmed as 'Y', returns false if confirmed as 'N'
        Throws:
        java.io.IOException
      • writeFully

        public static void writeFully​(java.nio.channels.WritableByteChannel bc,
                                      java.nio.ByteBuffer buf)
                               throws java.io.IOException
        Write a ByteBuffer to a WritableByteChannel, handling short writes.
        Parameters:
        bc - The WritableByteChannel to write to
        buf - The input buffer
        Throws:
        java.io.IOException - On I/O error
      • createTempDir

        public static java.io.File createTempDir​(java.lang.String prefix,
                                                 java.lang.String suffix)
                                          throws java.io.IOException
        Create a temp directory with given prefix and suffix.
        Parameters:
        prefix - prefix of the directory name
        suffix - suffix of the directory name
        Returns:
        directory created
        Throws:
        java.io.IOException
      • createTempDir

        public static java.io.File createTempDir​(java.lang.String prefix,
                                                 java.lang.String suffix,
                                                 java.io.File dir)
                                          throws java.io.IOException
        Create a temp directory with given prefix and suffix in the specified dir.
        Parameters:
        prefix - prefix of the directory name
        suffix - suffix of the directory name
        dir - The directory in which the file is to be created, or null if the default temporary-file directory is to be used
        Returns:
        directory created
        Throws:
        java.io.IOException
      • createTempFileAndDeleteOnExit

        public static java.io.File createTempFileAndDeleteOnExit​(java.lang.String prefix,
                                                                 java.lang.String suffix)
                                                          throws java.io.IOException
        Create a temp directory with given prefix and suffix.
        Parameters:
        prefix - prefix of the directory name
        suffix - suffix of the directory name
        Returns:
        directory created
        Throws:
        java.io.IOException