Package com.sshtools.common.util
Class IOUtils
java.lang.Object
com.sshtools.common.util.IOUtils
- Author:
- $author$
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intDefault buffer size for stream utility methods -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseStream(Closeable obj) static booleanstatic booleancloseStream(OutputStream out) static voidcopy(File file, OutputStream out) static voidcopy(InputStream in, OutputStream out) Copy from an input stream to an output stream.static voidcopy(InputStream in, OutputStream out, boolean forceFlush) Copy from an input stream to an output stream.static voidcopy(InputStream in, OutputStream out, long count) Copy the specified number of bytes from an input stream to an output stream.static voidcopy(InputStream in, OutputStream out, long count, int bufferSize, boolean forceFlush) Copy the specified number of bytes from an input stream to an output stream.static voidstatic longcopyWithCount(InputStream in, OutputStream out) Copy from an input stream to an output stream.static longcopyWithCount(InputStream in, OutputStream out, boolean forceFlush) Copy from an input stream to an output stream.static longcopyWithCount(InputStream in, OutputStream out, long count) Copy the specified number of bytes from an input stream to an output stream.static longcopyWithCount(InputStream in, OutputStream out, long count, int bufferSize, boolean forceFlush) Copy the specified number of bytes from an input stream to an output stream.static booleanDeprecated, for removal: This API element is subject to removal in a future version.static LongfromByteSize(String val) static StringgetFilenameExtension(String filename) static StringgetFilenameWithoutExtension(String filename) static booleanisOlderThan(File file, Duration duration) static StringreadStringFromFile(File file, String charset) static StringreadStringFromStream(InputStream in, String charset) static StringreadUTF8StringFromFile(File file) static Stringstatic intreadyFully(InputStream in, byte[] buf) static voidDeprecated, for removal: This API element is subject to removal in a future version.static voidrecursiveContentsDelete(File directory, FileVisitOption... options) Recursively delete all contents of the given directory.static voidrecursiveContentsDelete(Path directory, FileVisitOption... options) Recursively delete all contents of the given directory.static voidrecursiveDelete(Path fileOrDirectory, FileVisitOption... options) Recursively delete a file or directory, and all child files and directories if a directory.static voidstatic byte[]sha1Digest(File file) static byte[]static booleansilentRecursiveDelete(File fileOrDirectory, FileVisitOption... options) Recursively delete a file or directory, and all child files and directories if a directory.static booleansilentRecursiveDelete(Path fileOrDirectory, FileVisitOption... options) Recursively delete a file or directory, and all child files and directories if a directory.static StringtoByteSize(double t) static StringtoByteSize(double t, int decimalPlaces) static InputStreamtoInputStream(String value, String charset) static voidwriteBytesToFile(byte[] value, File file) static voidwriteStringToFile(File file, String string, String charset) static voidwriteStringToStream(OutputStream out, String string, String charset) static voidwriteUTF8StringToFile(File file, String string) static voidwriteUTF8StringToStream(OutputStream out, String string)
-
Field Details
-
BUFFER_SIZE
public static int BUFFER_SIZEDefault buffer size for stream utility methods
-
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
copy
Copy from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output stream- Throws:
IOException- on any error
-
copy
Copy from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamforceFlush- force flush of the OutputStream on each block- Throws:
IOException- on any error
-
copy
Copy the specified number of bytes from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamcount- number of bytes to copy- Throws:
IOException- on any error
-
copy
public static void copy(InputStream in, OutputStream out, long count, int bufferSize, boolean forceFlush) throws IOException Copy the specified number of bytes from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamcount- number of bytes to copybufferSize- buffer size- Throws:
IOException- on any error
-
copyWithCount
Copy from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output stream- Throws:
IOException- on any error
-
copyWithCount
public static long copyWithCount(InputStream in, OutputStream out, boolean forceFlush) throws IOException Copy from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamforceFlush- force flush of the OutputStream on each block- Throws:
IOException- on any error
-
copyWithCount
Copy the specified number of bytes from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamcount- number of bytes to copy- Throws:
IOException- on any error
-
copyWithCount
public static long copyWithCount(InputStream in, OutputStream out, long count, int bufferSize, boolean forceFlush) throws IOException Copy the specified number of bytes from an input stream to an output stream. It is up to the caller to close the streams.- Parameters:
in- input streamout- output streamcount- number of bytes to copybufferSize- buffer size- Throws:
IOException- on any error
-
closeStream
- Parameters:
in-- Returns:
-
closeStream
- Parameters:
out-- Returns:
-
recursiveContentsDelete
Recursively delete all contents of the given directory. By default symbolic links will not be followed. The directory itself will NOT be deleted.- Parameters:
directory- directory containing files or directoriesoptions- options- Throws:
UncheckedIOException- on any error
-
recursiveContentsDelete
Recursively delete all contents of the given directory. By default symbolic links will not be followed. The directory itself will NOT be deleted.- Parameters:
directory- directory containing files or directoriesoptions- options- Throws:
UncheckedIOException- on any error
-
silentRecursiveDelete
Recursively delete a file or directory, and all child files and directories if a directory. By default symbolic links will not be followed. An exception will NOT be thrown on error, insteadfalsewill be returned.- Parameters:
fileOrDirectory- directory containing files or directoriesoptions- options- Returns:
- success
-
silentRecursiveDelete
Recursively delete a file or directory, and all child files and directories if a directory. By default symbolic links will not be followed. An exception will NOT be thrown on error, insteadfalsewill be returned.- Parameters:
fileOrDirectory- directory containing files or directoriesoptions- options- Returns:
- success
-
recursiveDelete
Recursively delete a file or directory, and all child files and directories if a directory. By default symbolic links will not be followed.- Parameters:
fileOrDirectory- directory containing files or directoriesoptions- options- Throws:
UncheckedIOException- on any error
-
delTree
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated and unsafe (follows symbolic links), use#recursiveDelete(File, FileVisitOption...).- Parameters:
file- file or directory to completely remove.- Returns:
- success
-
recurseDeleteDirectory
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated and unsafe (follows symbolic links), userecursiveContentsDelete(Path, FileVisitOption...).- Parameters:
dir- directory of contents to remove.
-
copyFile
- Throws:
IOException
-
readyFully
- Throws:
IOException
-
writeUTF8StringToStream
public static void writeUTF8StringToStream(OutputStream out, String string) throws UnsupportedEncodingException, IOException -
writeStringToStream
public static void writeStringToStream(OutputStream out, String string, String charset) throws UnsupportedEncodingException, IOException -
writeUTF8StringToFile
public static void writeUTF8StringToFile(File file, String string) throws UnsupportedEncodingException, IOException -
writeStringToFile
public static void writeStringToFile(File file, String string, String charset) throws UnsupportedEncodingException, IOException -
fromByteSize
-
toByteSize
-
toByteSize
-
sha1Digest
public static byte[] sha1Digest(File file) throws NoSuchAlgorithmException, FileNotFoundException, IOException -
sha1Digest
- Throws:
NoSuchAlgorithmExceptionIOException
-
closeStream
-
getFilenameExtension
-
getFilenameWithoutExtension
-
rollover
- Throws:
IOException
-
readUTF8StringFromFile
- Throws:
IOException
-
readUTF8StringFromStream
- Throws:
IOException
-
readStringFromFile
public static String readStringFromFile(File file, String charset) throws UnsupportedEncodingException, IOException -
readStringFromStream
- Throws:
IOException
-
toInputStream
- Throws:
IOException
-
writeBytesToFile
- Throws:
IOException
-
copy
- Throws:
IOException
-
isOlderThan
-