public class FileIOUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.nio.charset.Charset |
CHARSET_UTF8 |
static java.nio.charset.Charset |
CHARSET_WINDOWS_ISO88591 |
static java.lang.String |
NATIVE_NEWLINE |
| Modifier and Type | Method and Description |
|---|---|
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
compressDir(java.nio.file.Path dirName,
java.nio.file.Path outputFileName)
Compress all the files present in the provided directory and returns a
Future with the
result. |
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
compressFile(java.nio.file.Path fileName,
java.nio.file.Path outputFileName)
Compresses a single file and returns a
Future with the result. |
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
deleteFileIfExists(java.lang.String filename)
Checks if a file exists and if yes, the file will be deleted and the Future will return true,
otherwise it will return false
|
static void |
deleteRecursively(java.nio.file.Path path)
Deletes the given
path recursively, including the path itself as well |
static void |
deleteRecursively(java.lang.String path)
Deletes the given path described by the
path-string recursively, including the path
itself as well |
static void |
extractDir(java.nio.file.Path archive,
java.io.File targetDirectory)
Extracts the given archive to a sub-directory with the same name that the archive has beneath
the target directory.
|
static java.util.concurrent.CompletableFuture<java.nio.file.Path> |
extractDir(java.nio.file.Path archive,
java.nio.file.Path target)
Extracts the given archive to a sub-directory with the same name that the archive has beneath
the target directory.
|
static java.util.concurrent.CompletableFuture<java.nio.file.Path> |
extractFile(java.nio.file.Path zippedFile,
java.nio.file.Path target)
Extracts the given zipped file to a file with the same name that the zipped file has beneath
the target directory.
|
static java.io.BufferedWriter |
getBufferedWriter(java.lang.String filename,
java.nio.charset.Charset charset)
Tries to open the specified file for writing and returns a BufferedWriter for it.
|
static java.io.BufferedWriter |
getBufferedWriter(java.lang.String filename,
java.nio.charset.Charset charset,
boolean append)
Tries to open the specified file for writing and returns a BufferedWriter for it.
|
static java.io.BufferedWriter |
getBufferedWriterUTF8(java.lang.String filename)
Tries to open the specified file for writing and returns a UTF-8 charset encoded BufferedWriter
for it.
|
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
gzip(java.lang.String filename)
Deprecated.
replaced by #compressFile(Path, Path). Add ".gz" to the input path and pass it as
output filepath in compressFile() for a similar functionality.
|
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
gzip(java.lang.String filename,
java.lang.String outputFileName)
Deprecated.
replaced by #compressFile(Path, Path)
|
public static final java.nio.charset.Charset CHARSET_UTF8
public static final java.nio.charset.Charset CHARSET_WINDOWS_ISO88591
public static final java.lang.String NATIVE_NEWLINE
public static java.io.BufferedWriter getBufferedWriterUTF8(java.lang.String filename)
throws java.io.IOException
filename - The filename where to write the data.java.io.IOExceptionpublic static java.io.BufferedWriter getBufferedWriter(java.lang.String filename,
java.nio.charset.Charset charset)
throws java.io.IOException
filename - The filename where to write the data.charset - the encoding to use to write the file.java.io.IOExceptionpublic static java.io.BufferedWriter getBufferedWriter(java.lang.String filename,
java.nio.charset.Charset charset,
boolean append)
throws java.io.IOException
filename - filename and path where to write the data e.g. /tmp/out/sample.csvcharset - the required file encoding the while should be written inappend - true if the file should be opened for appending, instead of
overwriting - only works if filename doesn't end with .gzjava.io.IOException@Deprecated public static java.util.concurrent.CompletableFuture<java.lang.Boolean> gzip(java.lang.String filename)
Future with the result.filename - the file that should be compress (full path + filename + file extension
required!)@Deprecated
public static java.util.concurrent.CompletableFuture<java.lang.Boolean> gzip(java.lang.String filename,
java.lang.String outputFileName)
Future with the result.filename - the file that should be compress (full path + filename + file extension
required!)outputFileName - the optional output filename (full path + filename + file extension
required!) if different from the provided filenamepublic static java.util.concurrent.CompletableFuture<java.lang.Boolean> compressDir(java.nio.file.Path dirName,
java.nio.file.Path outputFileName)
Future with the
result.dirName - path of the directory that should be compressedoutputFileName - path of the output file where the compressed content will be stored (path
should be for a file and filename should have a ".tar.gz" extension)public static java.util.concurrent.CompletableFuture<java.lang.Boolean> compressFile(java.nio.file.Path fileName,
java.nio.file.Path outputFileName)
Future with the result.fileName - path of the file that should be compressedoutputFileName - path of the output file where the compressed content will be stored (path
should be for a file and filename should have a ".gz" extension)public static java.util.concurrent.CompletableFuture<java.nio.file.Path> extractDir(java.nio.file.Path archive,
java.nio.file.Path target)
archive - Compressed tarball archive to extracttarget - Path to the target folderpublic static void extractDir(java.nio.file.Path archive,
java.io.File targetDirectory)
throws FileException
archive - Path of the compressed tarball archive to extracttargetDirectory - File which points to the target directoryFileException - If unable to extract the contents of the archivepublic static java.util.concurrent.CompletableFuture<java.nio.file.Path> extractFile(java.nio.file.Path zippedFile,
java.nio.file.Path target)
zippedFile - Compressed gzip file to extracttarget - Path to the target folderpublic static java.util.concurrent.CompletableFuture<java.lang.Boolean> deleteFileIfExists(java.lang.String filename)
filename - the file that should be deleted (full path + filename)public static void deleteRecursively(java.lang.String path)
throws java.io.IOException
path-string recursively, including the path
itself as wellpath - The path to deletejava.io.IOException - If something goes wrong.public static void deleteRecursively(java.nio.file.Path path)
throws java.io.IOException
path recursively, including the path itself as wellpath - The path to deletejava.io.IOException - If something goes wrong.