类 IoUtils

java.lang.Object
com.alibaba.nacos.common.utils.IoUtils

public class IoUtils extends Object
IO related tool methods.
作者:
nacos
  • 构造器详细资料

    • IoUtils

      public IoUtils()
  • 方法详细资料

    • tryDecompress

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

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

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

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

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

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

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

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

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

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

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

      If is file, delete file.

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

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

      public static void copyFile(String source, String target) throws IOException
      Copy File.
      参数:
      source - source file path
      target - target file path
      抛出:
      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(HttpURLConnection connection)
      Close http connection quietly.
      参数:
      connection - http connection
    • closeQuietly

      public static void closeQuietly(InputStream input)
    • closeQuietly

      public static void closeQuietly(OutputStream output)
    • closeQuietly

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