Class IoUtil


  • public class IoUtil
    extends java.lang.Object
    IO utility class.
    Since:
    2.0.0
    Author:
    Lijun Liao (xipki)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String base64Encode​(byte[] data, boolean withLineBreak)  
      static void closeQuietly​(java.io.Closeable closable)  
      static java.lang.String convertSequenceName​(java.lang.String sequenceName)  
      static boolean deleteDir​(java.io.File dir)  
      static boolean deleteDir​(java.io.File dir, boolean prependBaseDir)  
      static boolean deleteFile​(java.io.File file)  
      static boolean deleteFile​(java.io.File file, boolean prependBaseDir)  
      static boolean deleteFile​(java.lang.String path)  
      static boolean deleteFile​(java.lang.String path, boolean prependBaseDir)  
      static void deleteFile0​(java.io.File file)  
      static java.lang.String detectPath​(java.lang.String path)  
      static java.io.File expandFilepath​(java.io.File file)  
      static java.io.File expandFilepath​(java.io.File file, boolean prependBaseDir)  
      static java.lang.String expandFilepath​(java.lang.String path)  
      static java.lang.String expandFilepath​(java.lang.String path, boolean prependBaseDir)  
      static java.lang.String getHostAddress()  
      static int getIndex​(byte[] arrayA, byte[] arrayB)  
      static ConfigurableProperties loadProperties​(java.lang.String path)  
      static ConfigurableProperties loadProperties​(java.lang.String path, boolean prependBaseDir)  
      static void mkdirs​(java.io.File dir)  
      static void mkdirsParent​(java.nio.file.Path path)  
      static java.net.HttpURLConnection openHttpConn​(java.net.URL url)  
      static int parseInt​(byte[] bytes, int offset)  
      static short parseShort​(byte[] bytes, int offset)  
      static byte[] read​(java.io.File file)  
      static byte[] read​(java.io.File file, boolean prependBaseDir)  
      static byte[] read​(java.lang.String fileName)  
      static byte[] read​(java.lang.String fileName, boolean prependBaseDir)  
      static byte[] readAllBytes​(java.io.InputStream in)
      Read all bytes from the input stream.
      static byte[] readAllBytesAndClose​(java.io.InputStream in)
      Read all bytes from the input stream and close the stream.
      static java.lang.String readLastNonBlankLine​(java.io.File file)  
      static java.lang.String readLineFromConsole​(java.lang.String prompt)  
      static char[] readPasswordFromConsole​(java.lang.String prompt)  
      static void renameTo​(java.io.File srcFile, java.io.File destFile)  
      static void save​(java.io.File file, byte[] content)  
      static void save​(java.io.File file, byte[] content, boolean prependBaseDir)  
      static void save​(java.lang.String fileName, byte[] encoded)  
      static void save​(java.lang.String fileName, byte[] encoded, boolean prependBaseDir)  
      static void writeInt​(int value, byte[] dest, int destOffset)  
      static void writeShort​(short value, byte[] dest, int destOffset)  
      • 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.Closeable closable)
      • read

        public static byte[] read​(java.lang.String fileName)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public static byte[] read​(java.lang.String fileName,
                                  boolean prependBaseDir)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public static byte[] read​(java.io.File file)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public static byte[] read​(java.io.File file,
                                  boolean prependBaseDir)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readAllBytesAndClose

        public static byte[] readAllBytesAndClose​(java.io.InputStream in)
                                           throws java.io.IOException
        Read all bytes from the input stream and close the stream. The specified stream is closed after this method returns.
        Parameters:
        in - the input stream.
        Returns:
        the byte array contained in the input stream.
        Throws:
        java.io.IOException - if error occurs while reading the bytes.
      • readAllBytes

        public static byte[] readAllBytes​(java.io.InputStream in)
                                   throws java.io.IOException
        Read all bytes from the input stream. The specified stream remains open after this method returns.
        Parameters:
        in - the input stream.
        Returns:
        the byte array contained in the input stream.
        Throws:
        java.io.IOException - if error occurs while reading the bytes.
      • save

        public static void save​(java.lang.String fileName,
                                byte[] encoded)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • save

        public static void save​(java.lang.String fileName,
                                byte[] encoded,
                                boolean prependBaseDir)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • save

        public static void save​(java.io.File file,
                                byte[] content)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • save

        public static void save​(java.io.File file,
                                byte[] content,
                                boolean prependBaseDir)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • mkdirsParent

        public static void mkdirsParent​(java.nio.file.Path path)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • mkdirs

        public static void mkdirs​(java.io.File dir)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • renameTo

        public static void renameTo​(java.io.File srcFile,
                                    java.io.File destFile)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getHostAddress

        public static java.lang.String getHostAddress()
                                               throws java.net.SocketException
        Throws:
        java.net.SocketException
      • deleteFile

        public static boolean deleteFile​(java.lang.String path)
      • deleteFile

        public static boolean deleteFile​(java.lang.String path,
                                         boolean prependBaseDir)
      • deleteFile

        public static boolean deleteFile​(java.io.File file)
      • deleteFile0

        public static void deleteFile0​(java.io.File file)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteFile

        public static boolean deleteFile​(java.io.File file,
                                         boolean prependBaseDir)
      • deleteDir

        public static boolean deleteDir​(java.io.File dir)
      • deleteDir

        public static boolean deleteDir​(java.io.File dir,
                                        boolean prependBaseDir)
      • expandFilepath

        public static java.lang.String expandFilepath​(java.lang.String path)
      • expandFilepath

        public static java.lang.String expandFilepath​(java.lang.String path,
                                                      boolean prependBaseDir)
      • expandFilepath

        public static java.io.File expandFilepath​(java.io.File file)
      • expandFilepath

        public static java.io.File expandFilepath​(java.io.File file,
                                                  boolean prependBaseDir)
      • convertSequenceName

        public static java.lang.String convertSequenceName​(java.lang.String sequenceName)
      • writeShort

        public static void writeShort​(short value,
                                      byte[] dest,
                                      int destOffset)
      • parseShort

        public static short parseShort​(byte[] bytes,
                                       int offset)
      • writeInt

        public static void writeInt​(int value,
                                    byte[] dest,
                                    int destOffset)
      • parseInt

        public static int parseInt​(byte[] bytes,
                                   int offset)
      • getIndex

        public static int getIndex​(byte[] arrayA,
                                   byte[] arrayB)
      • base64Encode

        public static java.lang.String base64Encode​(byte[] data,
                                                    boolean withLineBreak)
      • openHttpConn

        public static java.net.HttpURLConnection openHttpConn​(java.net.URL url)
                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readPasswordFromConsole

        public static char[] readPasswordFromConsole​(java.lang.String prompt)
      • readLineFromConsole

        public static java.lang.String readLineFromConsole​(java.lang.String prompt)
      • loadProperties

        public static ConfigurableProperties loadProperties​(java.lang.String path)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • loadProperties

        public static ConfigurableProperties loadProperties​(java.lang.String path,
                                                            boolean prependBaseDir)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • detectPath

        public static java.lang.String detectPath​(java.lang.String path)
      • readLastNonBlankLine

        public static java.lang.String readLastNonBlankLine​(java.io.File file)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException