public class FileUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static org.apache.log4j.Logger |
log
Used for logging.
|
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copyDir(java.io.File fromDir,
java.io.File toDir)
Copies the contents of one directory over the contents of another
directory.
|
static void |
copyFile(java.io.File in,
java.io.File out)
Copies a file.
|
static boolean |
copyFile(java.io.File from,
java.io.File to,
long start)
Copies a file from one location to another, leaving the old copy where it was.
|
static void |
deleteDir(java.io.File dir)
Deletes a directory, including all files and sub-directories contained
within it.
|
static void |
deleteFile(java.io.File file)
Deletes a file, if it exists.
|
static java.lang.String |
getFileExtension(java.io.File f)
Returns the file extension for the given File as a String, or an empty String if the File has no extension.
|
static java.lang.String |
getFileExtension(java.lang.String path)
Returns the file extension for the File at the given path as a String, or an empty String if the File has no extension.
|
static java.io.File[] |
getFilesFromDirectory(java.io.File directory)
Returns a list of all files that are children of the given directory.
|
static int |
getImageHeight(java.lang.String imagePath)
Gets the height of an image.
|
static int |
getImageWidth(java.lang.String imagePath)
Gets the width of an image.
|
static void |
resizeImage(java.lang.String originalFile,
java.lang.String thumbnailFile,
int newWidthSize,
int newHeightSize,
boolean deleteOriginalFile)
Creates a thumbnail for an existing image.
|
static void |
unzipFile(java.io.File zippedFile)
Unzips a file.
|
static void |
unzipFile(java.io.File zippedFile,
java.io.File dir)
Unzips the given zip archive to the given directory.
|
static void |
zipDirectory(java.io.File zipFile,
java.io.File rootDirectory,
boolean deleteAfterAdd)
Zips a directory (including all subdirectories)
|
static void |
zipDirectory(java.io.File zipFile,
java.lang.String rootDirectory,
boolean deleteAfterAdd)
Zips a directory (including all subdirectories)
|
static void |
zipDirectory(java.lang.String zipFile,
java.io.File rootDirectory,
boolean deleteAfterAdd)
Zips a directory (including all subdirectories)
|
static void |
zipDirectory(java.lang.String zipFile,
java.lang.String rootDirectory,
boolean deleteAfterAdd)
Zips a directory (including all subdirectories)
|
static void |
zipFiles(java.io.File zipFile,
java.io.File[] filesToZip,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.io.File zipFile,
java.io.File[] filesToZip,
java.io.File rootDirectory)
Zips a list of files
|
static void |
zipFiles(java.io.File zipFile,
java.io.File[] filesToZip,
java.io.File rootDirectory,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.io.File zipFile,
java.io.File[] filesToZip,
java.lang.String rootDirectory)
Zips a list of files
|
static void |
zipFiles(java.io.File zipFile,
java.io.File[] filesToZip,
java.lang.String rootDirectory,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.io.File zipFile,
java.lang.String rootDirectory) |
static void |
zipFiles(java.lang.String zipFile,
java.io.File[] filesToZip,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.lang.String zipFile,
java.io.File[] filesToZip,
java.lang.String rootDirectory,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.lang.String zipFile,
java.lang.String[] filesToZip,
boolean deleteAfterAdd)
Zips a list of files
|
static void |
zipFiles(java.lang.String zipFile,
java.lang.String[] filesToZip,
java.lang.String rootDirectory)
Zips a list of files
|
static void |
zipFiles(java.lang.String zipFile,
java.lang.String[] filesToZip,
java.lang.String rootDirectory,
boolean deleteAfterAdd)
Zips a list of files
|
public static void deleteFile(@NotNull java.io.File file)
file
- The file to deletepublic static void copyFile(@NotNull java.io.File in, @NotNull java.io.File out)
in
- The file to be read in.out
- The file to be written out.public static void unzipFile(@NotNull java.io.File zippedFile) throws java.io.IOException
zippedFile
- The archive to unzip.java.io.IOException
- If an error occurs while unzipping the filepublic static void unzipFile(@NotNull java.io.File zippedFile, @NotNull java.io.File dir) throws java.io.IOException
zippedFile
- the archive to unzip.dir
- the directory to unzip the archive to.java.io.IOException
public static void copyDir(@NotNull java.io.File fromDir, java.io.File toDir)
fromDir
- The directory to copy from.toDir
- The directory to copy to.public static void deleteDir(@NotNull java.io.File dir)
dir
- The directory to delete.public static void resizeImage(@NotNull java.lang.String originalFile, @NotNull java.lang.String thumbnailFile, int newWidthSize, int newHeightSize, boolean deleteOriginalFile) throws java.lang.Exception
originalFile
- The path to the original file.thumbnailFile
- The path where the thumbnail should be created.newWidthSize
- The new width of the image.newHeightSize
- The new height of the image.deleteOriginalFile
- Whether or not the original file should be
deleted after the thumbnail is created.java.lang.Exception
- If an error occurrs while resizing the imagepublic static int getImageHeight(@NotNull java.lang.String imagePath) throws java.lang.Exception
imagePath
- The path to the image.java.lang.Exception
- On error reading the imagepublic static int getImageWidth(@NotNull java.lang.String imagePath) throws java.lang.Exception
imagePath
- The path to the image.java.lang.Exception
- On error reading the imagepublic static boolean copyFile(@NotNull java.io.File from, @NotNull java.io.File to, long start)
from
- The file to be copiedto
- The file to copy into. This should be the full name, not just the directory.start
- The starting location in the file for the copypublic static void zipFiles(java.lang.String zipFile, @Nullable java.lang.String[] filesToZip, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.lang.String zipFile, java.io.File[] filesToZip, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.io.File zipFile, java.io.File[] filesToZip, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.lang.String zipFile, @Nullable java.lang.String[] filesToZip, java.lang.String rootDirectory) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structurejava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.io.File zipFile, java.io.File[] filesToZip, java.lang.String rootDirectory) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structurejava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.io.File zipFile, java.lang.String rootDirectory) throws java.io.IOException
java.io.IOException
public static void zipFiles(java.io.File zipFile, java.io.File[] filesToZip, java.io.File rootDirectory) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structurejava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.io.File zipFile, java.io.File[] filesToZip, java.lang.String rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structuredeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.lang.String zipFile, java.io.File[] filesToZip, java.lang.String rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structuredeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipFiles(java.lang.String zipFile, @Nullable java.lang.String[] filesToZip, java.lang.String rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structuredeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blankpublic static void zipDirectory(java.lang.String zipFile, java.lang.String rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save torootDirectory
- The directory to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filepublic static void zipDirectory(java.io.File zipFile, java.lang.String rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save torootDirectory
- The directory to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filepublic static void zipDirectory(java.io.File zipFile, java.io.File rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save torootDirectory
- The directory to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filepublic static void zipDirectory(java.lang.String zipFile, java.io.File rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save torootDirectory
- The directory to compressdeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the file@InternalOnly public static java.io.File[] getFilesFromDirectory(java.io.File directory)
directory
- the directory.public static void zipFiles(@Nullable java.io.File zipFile, @Nullable java.io.File[] filesToZip, @Nullable java.io.File rootDirectory, boolean deleteAfterAdd) throws java.io.IOException
zipFile
- The zip file to save tofilesToZip
- The file to compressrootDirectory
- The root directory for the zip file, or null to ignore directory structuredeleteAfterAdd
- If true, will delete the file after compressing itjava.io.IOException
- On error writing to the filejava.lang.IllegalArgumentException
- If filesToZip is null or blank@NotNull public static java.lang.String getFileExtension(@NotNull java.io.File f)
f
- the file.@NotNull public static java.lang.String getFileExtension(java.lang.String path)
path
- the path to the File.