Class IOUtil


  • public class IOUtil
    extends java.lang.Object
    Utility class for manipulating streams.
    Since:
    1.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeQuietly​(java.io.InputStream in)
      Closes an input stream and quietly ignores any exception.
      static void closeQuietly​(java.io.OutputStream out)
      Closes an output stream and quietly ignores any exception.
      static void closeQuietly​(java.io.Reader in)
      Closes an input stream and quietly ignores any exception.
      static void closeQuietly​(java.io.Writer out)
      Closes an output stream and quietly ignores any exception.
      static java.net.URL getResource​(java.lang.ClassLoader classLoader, java.lang.String resource)
      Finds a resource on the classpath.
      static java.io.InputStream getResourceAsStream​(java.lang.String resource)
      Loads a resource from the classpath.
      • Methods inherited from class java.lang.Object

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

      • closeQuietly

        public static void closeQuietly​(java.io.Reader in)
        Closes an input stream and quietly ignores any exception.
        Parameters:
        in - the stream to close
      • closeQuietly

        public static void closeQuietly​(java.io.Writer out)
        Closes an output stream and quietly ignores any exception.
        Parameters:
        out - the stream to close
      • closeQuietly

        public static void closeQuietly​(java.io.InputStream in)
        Closes an input stream and quietly ignores any exception.
        Parameters:
        in - the stream to close
      • closeQuietly

        public static void closeQuietly​(java.io.OutputStream out)
        Closes an output stream and quietly ignores any exception.
        Parameters:
        out - the stream to close
      • getResource

        public static java.net.URL getResource​(java.lang.ClassLoader classLoader,
                                               java.lang.String resource)
        Finds a resource on the classpath. The resource is always loaded from the root of the classpath, whether the resource name includes a leading slash or not.
        Parameters:
        resource - the name of the resource to load
        Returns:
        the resource URL, or null if the resource was not found
        Since:
        1.2.1
      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String resource)
                                                       throws java.io.IOException
        Loads a resource from the classpath.
        Parameters:
        resource - the name of the resource to load
        Returns:
        a new InputStream to read the resource or null if the resource was not found
        Throws:
        java.io.IOException - if an I/O error occurs
        Since:
        1.2