public final class IOToolkit
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static int[] |
MAGIC_GZ
Magic bytes for recognizing GZip.
|
private static int[] |
MAGIC_LZ4
Magic bytes for recognizing LZ4.
|
private static int[] |
MAGIC_ZIP
Magic bytes for recognizing Zip.
|
| Modifier | Constructor and Description |
|---|---|
private |
IOToolkit() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
calculateFileHash(java.io.File file)
Calculates an MD5 hash on ten evenly distributed 1kB blocks from the file.
|
static void |
closeSilently(java.io.Closeable closeable)
Closes a closeable.
|
static void |
copy(java.io.InputStream is,
java.io.OutputStream os)
Copy all data from an input stream to an output stream.
|
static void |
copy(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
Copy all data from an input stream to an output stream.
|
static void |
copyFile(java.io.File srcFile,
java.io.File targetFile)
Copies srcFile to targetFile.
|
static int[] |
getGzipMagic()
Returns the magic bytes for identifying Gzip.
|
static int[] |
getLz4Magic()
Returns the magic bytes for identifying LZ4.
|
static int[] |
getZipMagic()
Returns the magic bytes for identifying Zip.
|
static boolean |
hasMagic(java.io.File file,
int[] magic)
Checks if a file begins with a specified array of bytes.
|
static boolean |
hasMagic(java.io.InputStream is,
int[] magic)
Checks if an input stream begins with a specified array of bytes.
|
static boolean |
isCompressedFile(java.io.File file)
Checks if the file is compressed in a way compatible with
openUncompressedStream(File). |
static boolean |
isGZipFile(java.io.File file)
Returns true if the file is GZip file.
|
static boolean |
isLZ4File(java.io.File file)
Returns true if the file is LZ4 compressed.
|
static boolean |
isZipFile(java.io.File file)
Checks if the file is a ZIP archive.
|
static java.util.List<java.lang.String> |
loadFromFile(java.io.File file)
Read lines from a text file.
|
private static java.util.List<java.lang.String> |
loadFromReader(java.io.Reader reader) |
static java.util.List<java.lang.String> |
loadFromStream(java.io.InputStream is)
Read lines from an input stream.
|
static java.io.InputStream |
openUncompressedStream(java.io.File file)
Get an input stream for a optionally compressed file.
|
static java.io.InputStream |
openUncompressedStream(java.io.InputStream stream)
Get an input stream for a optionally compressed input stream.
|
static void |
saveToFile(java.io.File file,
java.util.List<java.lang.String> lines)
Write lines to a text file.
|
static void |
write(java.io.InputStream in,
java.io.File toOutput,
boolean append)
Copy all data from an input stream to a file.
|
private static final int[] MAGIC_ZIP
private static final int[] MAGIC_GZ
private static final int[] MAGIC_LZ4
public static void closeSilently(java.io.Closeable closeable)
closeable - object to close, may be nullpublic static java.io.InputStream openUncompressedStream(java.io.File file)
throws java.io.IOException
file - file to read fromjava.io.IOException - on I/O errorpublic static java.io.InputStream openUncompressedStream(java.io.InputStream stream)
throws java.io.IOException
stream - input stream to read fromjava.io.IOException - on I/O errorpublic static boolean hasMagic(java.io.File file,
int[] magic)
throws java.io.IOException
file - the file to examinemagic - the magic data, an array with values between 0 and 255true if the file begins with the magic, false otherwisejava.io.IOException - if an error occurred when trying to read from the filepublic static boolean hasMagic(java.io.InputStream is,
int[] magic)
throws java.io.IOException
is - the input stream to examinemagic - the magic data, an array with values between 0 and 255true if the input stream begins with the magic, false otherwisejava.io.IOException - if an error occurred when trying to read from the streampublic static boolean isGZipFile(java.io.File file)
throws java.io.IOException
file - the file to examinetrue if it is a GZip file, false otherwisejava.io.IOException - if an error occurred when trying to read from the filepublic static boolean isLZ4File(java.io.File file)
throws java.io.IOException
file - the file to examinetrue if it is an LZ4 compressed file, false otherwisejava.io.IOException - if an error occurred when trying to read from the filepublic static boolean isZipFile(java.io.File file)
throws java.io.IOException
file - the file to examinetrue if it's a ZIP archive, false otherwisejava.io.IOException - if an error occurred when trying to read from the filepublic static int[] getGzipMagic()
public static int[] getZipMagic()
public static int[] getLz4Magic()
public static boolean isCompressedFile(java.io.File file)
throws java.io.IOException
openUncompressedStream(File).file - the file to examinetrue if the file is compressed in a manner which can be uncompressed by
openUncompressedStream(File), false otherwisejava.io.IOException - if an error occurred when trying to read from the filepublic static java.util.List<java.lang.String> loadFromFile(java.io.File file)
throws java.io.IOException
file - file to read lines fromjava.io.IOException - on I/O errorsaveToFile(File, List)private static java.util.List<java.lang.String> loadFromReader(java.io.Reader reader)
throws java.io.IOException
java.io.IOExceptionpublic static void saveToFile(java.io.File file,
java.util.List<java.lang.String> lines)
throws java.io.IOException
file - file to write lines tolines - a list of strings that will be written on one line eachjava.io.IOException - on I/O errorloadFromFile(File)public static java.util.List<java.lang.String> loadFromStream(java.io.InputStream is)
throws java.io.IOException
is - input stream to read lines fromjava.io.IOException - on I/O errorsaveToFile(File, List)public static void write(java.io.InputStream in,
java.io.File toOutput,
boolean append)
throws java.io.IOException
in - input stream to read fromtoOutput - file to write toappend - true if the file should be appended to, false if it should be
overwrittenjava.io.IOException - on I/O errorpublic static void copy(java.io.InputStream is,
java.io.OutputStream os)
throws java.io.IOException
is - input stream to read fromos - output stream to write tojava.io.IOException - on I/O errorpublic static void copy(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
throws java.io.IOException
is - input stream to read fromos - output stream to write tobufferSize - size of the buffer used when copying datajava.io.IOException - on I/O errorpublic static void copyFile(java.io.File srcFile,
java.io.File targetFile)
throws java.io.IOException
srcFile - source file to copy data fromtargetFile - target file to copy data tojava.io.IOException - if something goes wrong during the copypublic static java.lang.String calculateFileHash(java.io.File file)
throws java.io.IOException
file - file to calculate hash forjava.io.IOException - if something goes wrong when reading file data