类 IoUtils


  • public class IoUtils
    extends java.lang.Object
    IO related tool methods.
    作者:
    nacos
    • 构造器概要

      构造器 
      构造器 说明
      IoUtils()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static void cleanDirectory​(java.io.File directory)
      清理目录下的内容.
      static void closeQuietly​(java.io.Closeable closeable)
      Close closable object quietly.
      static void closeQuietly​(java.io.Closeable... closeable)  
      static void closeQuietly​(java.net.HttpURLConnection connection)
      Close http connection quietly.
      static long copy​(java.io.InputStream input, java.io.OutputStream output)
      Copy data.
      static long copy​(java.io.Reader input, java.io.Writer output)
      Copy data.
      static void copyFile​(java.lang.String source, java.lang.String target)
      Copy File.
      static void delete​(java.io.File fileOrDir)
      Delete file or dir.
      static boolean isGzipStream​(byte[] bytes)
      Judge whether is Gzip stream.
      static java.util.List<java.lang.String> readLines​(java.io.Reader input)
      Read lines.
      private static java.io.BufferedReader toBufferedReader​(java.io.Reader reader)  
      static java.lang.String toString​(java.io.InputStream input, java.lang.String encoding)
      To string from stream.
      static java.lang.String toString​(java.io.Reader reader)
      To string from reader.
      static byte[] tryCompress​(java.lang.String str, java.lang.String encoding)
      Try compress by GZIP for string.
      static byte[] tryDecompress​(byte[] raw)
      Try decompress by GZIP from byte array.
      static byte[] tryDecompress​(java.io.InputStream raw)
      Try decompress by GZIP from stream.
      static void writeStringToFile​(java.io.File file, java.lang.String data, java.lang.String encoding)
      Write string to a file.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • IoUtils

        public IoUtils()
    • 方法详细资料

      • tryDecompress

        public static byte[] tryDecompress​(java.io.InputStream raw)
                                    throws java.io.IOException
        Try decompress by GZIP from stream.
        参数:
        raw - compress stream
        返回:
        byte array after decompress
        抛出:
        java.io.IOException
      • tryDecompress

        public static byte[] tryDecompress​(byte[] raw)
                                    throws java.lang.Exception
        Try decompress by GZIP from byte array.
        参数:
        raw - compressed byte array
        返回:
        byte array after decompress
        抛出:
        java.lang.Exception - exception
      • tryCompress

        public static byte[] tryCompress​(java.lang.String str,
                                         java.lang.String encoding)
        Try compress by GZIP for string.
        参数:
        str - strings to be compressed.
        encoding - encoding.
        返回:
        byte[]
      • toBufferedReader

        private static java.io.BufferedReader toBufferedReader​(java.io.Reader reader)
      • writeStringToFile

        public static void writeStringToFile​(java.io.File file,
                                             java.lang.String data,
                                             java.lang.String encoding)
                                      throws java.io.IOException
        Write string to a file.
        参数:
        file - file
        data - string
        encoding - encoding of string
        抛出:
        java.io.IOException - io exception
      • readLines

        public static java.util.List<java.lang.String> readLines​(java.io.Reader input)
                                                          throws java.io.IOException
        Read lines.
        参数:
        input - reader
        返回:
        list of line
        抛出:
        java.io.IOException - io exception
      • toString

        public static java.lang.String toString​(java.io.InputStream input,
                                                java.lang.String encoding)
                                         throws java.io.IOException
        To string from stream.
        参数:
        input - stream
        encoding - charset of stream
        返回:
        string
        抛出:
        java.io.IOException - io exception
      • toString

        public static java.lang.String toString​(java.io.Reader reader)
                                         throws java.io.IOException
        To string from reader.
        参数:
        reader - reader
        返回:
        string
        抛出:
        java.io.IOException - io exception
      • copy

        public static long copy​(java.io.Reader input,
                                java.io.Writer output)
                         throws java.io.IOException
        Copy data.
        参数:
        input - source
        output - target
        返回:
        copy size
        抛出:
        java.io.IOException - io exception
      • copy

        public static long copy​(java.io.InputStream input,
                                java.io.OutputStream output)
                         throws java.io.IOException
        Copy data.
        参数:
        input - source
        output - target
        返回:
        copy size
        抛出:
        java.io.IOException - io exception
      • delete

        public static void delete​(java.io.File fileOrDir)
                           throws java.io.IOException
        Delete file or dir.

        If is dir, clean directory, do not delete dir.

        If is file, delete file.

        参数:
        fileOrDir - file or dir
        抛出:
        java.io.IOException - io exception
      • cleanDirectory

        public static void cleanDirectory​(java.io.File directory)
                                   throws java.io.IOException
        清理目录下的内容. Clean content under directory.
        参数:
        directory - directory
        抛出:
        java.io.IOException - io exception
      • copyFile

        public static void copyFile​(java.lang.String source,
                                    java.lang.String target)
                             throws java.io.IOException
        Copy File.
        参数:
        source - source file path
        target - target file path
        抛出:
        java.io.IOException - io exception
      • isGzipStream

        public static boolean isGzipStream​(byte[] bytes)
        Judge whether is Gzip stream.
        参数:
        bytes - byte array
        返回:
        true if is gzip, otherwise false
      • closeQuietly

        public static void closeQuietly​(java.net.HttpURLConnection connection)
        Close http connection quietly.
        参数:
        connection - http connection
      • closeQuietly

        public static void closeQuietly​(java.io.Closeable closeable)
        Close closable object quietly.
        参数:
        closeable - http connection
      • closeQuietly

        public static void closeQuietly​(java.io.Closeable... closeable)