Enum IOUtils

    • Method Detail

      • values

        public static IOUtils[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (IOUtils c : IOUtils.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static IOUtils valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • toByteArray

        public static byte[] toByteArray​(InputStream is)
                                  throws IOException
        Reads and returns the rest of the given input stream as a byte array. Caller is responsible for closing the given input stream.
        Throws:
        IOException
      • toString

        public static String toString​(InputStream is)
                               throws IOException
        Reads and returns the rest of the given input stream as a string. Caller is responsible for closing the given input stream.
        Throws:
        IOException
      • closeQuietly

        public static void closeQuietly​(Closeable is,
                                        org.apache.commons.logging.Log log)
        Closes the given Closeable quietly.
        Parameters:
        is - the given closeable
        log - logger used to log any failure should the close fail
      • release

        public static void release​(Closeable is,
                                   org.apache.commons.logging.Log log)
        Releases the given Closeable especially if it was an instance of Releasable.

        For example, the creation of a ResettableInputStream would entail physically opening a file. If the opened file is meant to be closed only (in a finally block) by the very same code block that created it, then it is necessary that the release method must not be called while the execution is made in other stack frames. In such case, as other stack frames may inadvertently or indirectly call the close method of the stream, the creator of the stream would need to explicitly disable the accidental closing via ResettableInputStream#disableClose(), so that the release method becomes the only way to truly close the opened file.

      • copy

        public static long copy​(InputStream in,
                                OutputStream out)
                         throws IOException
        Copies all bytes from the given input stream to the given output stream. Caller is responsible for closing the streams.
        Throws:
        IOException - if there is any IO exception during read or write.