Package org.xipki.util
Class IoUtil
- java.lang.Object
-
- org.xipki.util.IoUtil
-
public class IoUtil extends java.lang.ObjectIO 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.Stringbase64Encode(byte[] data, boolean withLineBreak)static voidcloseQuietly(java.io.Closeable closable)static java.lang.StringconvertSequenceName(java.lang.String sequenceName)static booleandeleteDir(java.io.File dir)static booleandeleteDir(java.io.File dir, boolean prependBaseDir)static booleandeleteFile(java.io.File file)static booleandeleteFile(java.io.File file, boolean prependBaseDir)static booleandeleteFile(java.lang.String path)static booleandeleteFile(java.lang.String path, boolean prependBaseDir)static voiddeleteFile0(java.io.File file)static java.lang.StringdetectPath(java.lang.String path)static java.io.FileexpandFilepath(java.io.File file)static java.io.FileexpandFilepath(java.io.File file, boolean prependBaseDir)static java.lang.StringexpandFilepath(java.lang.String path)static java.lang.StringexpandFilepath(java.lang.String path, boolean prependBaseDir)static java.lang.StringgetHostAddress()static intgetIndex(byte[] arrayA, byte[] arrayB)static ConfigurablePropertiesloadProperties(java.lang.String path)static ConfigurablePropertiesloadProperties(java.lang.String path, boolean prependBaseDir)static voidmkdirs(java.io.File dir)static voidmkdirsParent(java.nio.file.Path path)static java.net.HttpURLConnectionopenHttpConn(java.net.URL url)static intparseInt(byte[] bytes, int offset)static shortparseShort(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.StringreadLastNonBlankLine(java.io.File file)static java.lang.StringreadLineFromConsole(java.lang.String prompt)static char[]readPasswordFromConsole(java.lang.String prompt)static voidrenameTo(java.io.File srcFile, java.io.File destFile)static voidsave(java.io.File file, byte[] content)static voidsave(java.io.File file, byte[] content, boolean prependBaseDir)static voidsave(java.lang.String fileName, byte[] encoded)static voidsave(java.lang.String fileName, byte[] encoded, boolean prependBaseDir)static voidwriteInt(int value, byte[] dest, int destOffset)static voidwriteShort(short value, byte[] dest, int destOffset)
-
-
-
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.IOExceptionRead 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.IOExceptionRead 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
-
-