public abstract class FileUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES_TO_MB |
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
checkFile(java.lang.String filePath) |
static java.io.ByteArrayInputStream |
copy(java.io.InputStream source) |
static void |
copyStream(java.io.InputStream source,
java.io.File target) |
static void |
copyStream(java.io.InputStream source,
java.io.OutputStream destin) |
static void |
copyStream(java.io.InputStream source,
java.io.OutputStream destin,
java.lang.Boolean closeOutputStream) |
static void |
createFile(java.lang.String content,
java.lang.String parentPath,
java.lang.String fileName) |
static java.io.File |
createTempDir() |
static java.io.File |
createTempFile() |
static boolean |
exist(java.lang.String filePath) |
static void |
forceDelete(java.io.File file)
Deletes an instance of
File even if it is a directory containing files.If the file is a directory and has contents, then executes itself on every content. |
static long |
getDirectorySize(java.io.File directory)
Counts the size of a directory recursively (sum of the length of all files).
|
static float |
getDirectorySizeInMB(java.io.File directory) |
static long |
getFileSize(java.io.File file) |
static float |
getFileSizeInMB(java.io.File file) |
static byte[] |
readAsBytes(java.io.File file)
Reads the file and returns a byte array with all the information
|
static byte[] |
readAsBytes(java.io.InputStream inputStream)
Reads the inputStream and returns a byte array with all the information
|
static boolean |
renameOrMove(java.io.File fileToBeMoved,
java.io.File destination)
Renames or moves a determined
File instance to a destination defined by another File instance.Differs from the File.renameTo(File) method in the fact that this method logs if the operation was
successful. |
static void |
safeClose(java.io.Closeable closeable) |
static java.lang.String |
toString(java.io.File file)
Receives a File and iterates over all its lines and returns a String.
|
static java.lang.String |
toString(java.io.InputStream in)
Receives an InputStream and iterates over all its lines and returns a String.
|
static java.lang.String |
toString(java.io.InputStream in,
java.lang.Boolean closeStream) |
static java.io.File |
toTempFile(java.lang.String content) |
static java.io.File |
zipFile(java.lang.String directoryToZipPath) |
public static final int BYTES_TO_MB
public static byte[] readAsBytes(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The inputStream to be readjava.io.IOException - The exception thrown when an error reading the inputStream happenspublic static byte[] readAsBytes(java.io.File file)
throws java.io.IOException
file - The file to be readjava.io.IOException - The exception thrown when an error reading the file happenspublic static java.io.File checkFile(java.lang.String filePath)
filePath - The path to the filepublic static boolean exist(java.lang.String filePath)
filePath - The file path to the file for verify the existencepublic static void forceDelete(java.io.File file)
File even if it is a directory containing files.file - The File to be deleted.File.delete()public static boolean renameOrMove(java.io.File fileToBeMoved,
java.io.File destination)
File instance to a destination defined by another File instance.File.renameTo(File) method in the fact that this method logs if the operation was
successful.fileToBeMoved - The file to be renamed or moved.destination - The File instance that denotes the new locationFile.renameTo(File)public static java.io.File createTempFile()
public static java.io.File createTempDir()
public static java.io.File toTempFile(java.lang.String content)
public static void createFile(java.lang.String content,
java.lang.String parentPath,
java.lang.String fileName)
public static java.lang.String toString(java.io.File file)
file - The filepublic static java.lang.String toString(java.io.InputStream in,
java.lang.Boolean closeStream)
public static java.lang.String toString(java.io.InputStream in)
in - the InputStream to be convertedpublic static void copyStream(java.io.InputStream source,
java.io.File target)
source - the source InputStreamtarget - the target Filepublic static void copyStream(java.io.InputStream source,
java.io.OutputStream destin,
java.lang.Boolean closeOutputStream)
source - the source InputStreamdestin - the destin OutputStreamcloseOutputStream - public static void copyStream(java.io.InputStream source,
java.io.OutputStream destin)
source - the source InputStreamdestin - the destin OutputStreampublic static java.io.ByteArrayInputStream copy(java.io.InputStream source)
source - the source InputStreamByteArrayInputStreampublic static java.io.File zipFile(java.lang.String directoryToZipPath)
public static void safeClose(java.io.Closeable closeable)
public static long getDirectorySize(java.io.File directory)
directory - directory to inspect, must not be nullpublic static long getFileSize(java.io.File file)
public static float getDirectorySizeInMB(java.io.File directory)
public static float getFileSizeInMB(java.io.File file)