Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    Input / output utilities.
    Version:
    2020-02-23
    Author:
    Vladimir Dzhuvinov
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeSilently​(java.io.Closeable closeable)
      Closes a Closeable without throwing an IOException.
      static java.lang.String readFileToString​(java.io.File file)
      Reads the content of the specified file into a string using UTF-8 character set encoding.
      static java.lang.String readFileToString​(java.io.File file, java.nio.charset.Charset charset)
      Reads the content of the specified file into a string.
      static java.lang.String readInputStreamToString​(java.io.InputStream stream)
      Reads the specified input stream into a string using UTF-8 character set encoding.
      static java.lang.String readInputStreamToString​(java.io.InputStream stream, java.nio.charset.Charset charset)
      Reads the specified input stream into a string.
      • Methods inherited from class java.lang.Object

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

      • readInputStreamToString

        public static java.lang.String readInputStreamToString​(java.io.InputStream stream)
                                                        throws java.io.IOException
        Reads the specified input stream into a string using UTF-8 character set encoding.
        Parameters:
        stream - The input stream. Must not be null.
        Returns:
        The string.
        Throws:
        java.io.IOException - If an input exception is encountered.
      • readInputStreamToString

        public static java.lang.String readInputStreamToString​(java.io.InputStream stream,
                                                               java.nio.charset.Charset charset)
                                                        throws java.io.IOException
        Reads the specified input stream into a string.
        Parameters:
        stream - The input stream. Must not be null.
        charset - The expected character set. Must not be null.
        Returns:
        The string.
        Throws:
        java.io.IOException - If an input exception is encountered.
      • readFileToString

        public static java.lang.String readFileToString​(java.io.File file)
                                                 throws java.io.IOException
        Reads the content of the specified file into a string using UTF-8 character set encoding.
        Parameters:
        file - The file. Must not be null.
        Returns:
        The string.
        Throws:
        java.io.IOException - If an input exception is encountered.
      • readFileToString

        public static java.lang.String readFileToString​(java.io.File file,
                                                        java.nio.charset.Charset charset)
                                                 throws java.io.IOException
        Reads the content of the specified file into a string.
        Parameters:
        file - The file. Must not be null.
        charset - The expected character set. Must not be null.
        Returns:
        The string.
        Throws:
        java.io.IOException - If an input exception is encountered.
      • closeSilently

        public static void closeSilently​(java.io.Closeable closeable)
        Closes a Closeable without throwing an IOException.
        Parameters:
        closeable - The closeable.