Class IoUtil


  • public class IoUtil
    extends java.lang.Object
    Author:
    Sebastian Menski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.charset.Charset ENCODING_CHARSET  
    • Constructor Summary

      Constructors 
      Constructor Description
      IoUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeSilently​(java.io.Closeable closeable)
      Close a closable ignoring any IO exception.
      static byte[] fileAsByteArray​(java.io.File file)
      Returns the content of a File.
      static java.io.InputStream fileAsStream​(java.io.File file)
      Returns the input stream of a file.
      static java.io.InputStream fileAsStream​(java.lang.String filename)
      Returns the input stream of a file with specified filename
      static java.lang.String fileAsString​(java.io.File file)
      Returns the content of a File.
      static java.lang.String fileAsString​(java.lang.String filename)
      Returns the content of a file with specified filename
      static java.io.File getClasspathFile​(java.lang.String filename)
      Returns the File for a filename.
      static java.io.File getClasspathFile​(java.lang.String filename, java.lang.ClassLoader classLoader)
      Returns the File for a filename.
      static byte[] inputStreamAsByteArray​(java.io.InputStream inputStream)
      Returns the input stream as byte[].
      static java.lang.String inputStreamAsString​(java.io.InputStream inputStream)
      Returns the input stream as String.
      static java.lang.String readerAsString​(java.io.Reader reader)
      Returns the Reader content as String.
      static java.io.InputStream stringAsInputStream​(java.lang.String string)
      Returns the String as InputStream.
      • Methods inherited from class java.lang.Object

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

      • ENCODING_CHARSET

        public static final java.nio.charset.Charset ENCODING_CHARSET
    • Constructor Detail

      • IoUtil

        public IoUtil()
    • Method Detail

      • inputStreamAsString

        public static java.lang.String inputStreamAsString​(java.io.InputStream inputStream)
        Returns the input stream as String.
        Parameters:
        inputStream - the input stream
        Returns:
        the input stream as String.
      • inputStreamAsByteArray

        public static byte[] inputStreamAsByteArray​(java.io.InputStream inputStream)
        Returns the input stream as byte[].
        Parameters:
        inputStream - the input stream
        Returns:
        the input stream as byte[].
      • readerAsString

        public static java.lang.String readerAsString​(java.io.Reader reader)
        Returns the Reader content as String.
        Parameters:
        reader - the Reader
        Returns:
        the Reader content as String
      • stringAsInputStream

        public static java.io.InputStream stringAsInputStream​(java.lang.String string)
        Returns the String as InputStream.
        Parameters:
        string - the String to convert
        Returns:
        the InputStream containing the String
      • closeSilently

        public static void closeSilently​(java.io.Closeable closeable)
        Close a closable ignoring any IO exception.
        Parameters:
        closeable - the closable to close
      • fileAsString

        public static java.lang.String fileAsString​(java.lang.String filename)
        Returns the content of a file with specified filename
        Parameters:
        filename - name of the file to load
        Returns:
        Content of the file as String
      • fileAsString

        public static java.lang.String fileAsString​(java.io.File file)
        Returns the content of a File.
        Parameters:
        file - the file to load
        Returns:
        Content of the file as String
      • fileAsByteArray

        public static byte[] fileAsByteArray​(java.io.File file)
        Returns the content of a File.
        Parameters:
        file - the file to load
        Returns:
        Content of the file as String
      • fileAsStream

        public static java.io.InputStream fileAsStream​(java.lang.String filename)
        Returns the input stream of a file with specified filename
        Parameters:
        filename - the name of a File to load
        Returns:
        the file content as input stream
        Throws:
        IoUtilException - if the file cannot be loaded
      • fileAsStream

        public static java.io.InputStream fileAsStream​(java.io.File file)
        Returns the input stream of a file.
        Parameters:
        file - the File to load
        Returns:
        the file content as input stream
        Throws:
        IoUtilException - if the file cannot be loaded
      • getClasspathFile

        public static java.io.File getClasspathFile​(java.lang.String filename)
        Returns the File for a filename.
        Parameters:
        filename - the filename to load
        Returns:
        the file object
      • getClasspathFile

        public static java.io.File getClasspathFile​(java.lang.String filename,
                                                    java.lang.ClassLoader classLoader)
        Returns the File for a filename.
        Parameters:
        filename - the filename to load
        classLoader - the classLoader to load file with, if null falls back to TCCL and then this class's classloader
        Returns:
        the file object
        Throws:
        IoUtilException - if the file cannot be loaded