|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jtheque.utils.io.FileUtils
public final class FileUtils
An utility class for file manipulation.
Method Summary | |
---|---|
static InputStream |
asInputStream(String path)
Return an input stream to the path. |
static void |
clearFolder(File folder)
Clear the folder. |
static void |
close(Closeable closable)
Close a closable resource. |
static void |
close(ZipFile zipFile)
Close a zip file. |
static void |
copy(File source,
File target)
This method copy a source's file to a destination's file. |
static void |
copy(String sourcePath,
String targetPath)
Copy a file. |
static void |
createEmptyFile(String path)
Create an empty file. |
static void |
createIfNotExists(File file)
Create the file if not exists. |
static void |
delete(File file)
Delete a file. |
static void |
delete(String path)
Delete a file. |
static void |
downloadFile(String filePath,
String destination)
Download a file. |
static String |
encryptKey(String key)
Encrypt the string with the SHA-256 Algorithm. |
static File |
getAnExistingFile()
Return an existing file. |
static long |
getFileSize(File file)
Return the size of the specified file. |
static long |
getFileSize(String path)
Return the size of the file specified by the path. |
static Collection<File> |
getFilesOfFolder(File folder,
FileFilter fileFilter)
Return all the files of the folder include the sub files and folders with no level limit. |
static String |
getFreeName(String folder,
String name)
Return the next free name for the specified name in the specified folder. |
static Date |
getLastModifiedDate(File file)
Return the date of the last modification of the specified file. |
static Date |
getLastModifiedDate(String path)
Return the date of the last modification of the file denoted by the specified path. |
static Collection<String> |
getLinesOf(InputStream stream)
Return the lines of a stream. |
static String |
getTextOf(String path)
Return the text of the file referenced by the specified path. |
static String |
getTextOfSystemResource(String path)
Return the text of the file. |
static boolean |
isFileInDirectory(File file,
File folder)
Test if a file is in a directory. |
static void |
move(String sourcePath,
String targetPath)
Move a file. |
static boolean |
putFileInDirectoryIfNot(File file,
File folder)
Put the file into the directory. |
static Collection<File> |
unzip(InputStream source,
String destinationFolder)
Unzip a compressed file. |
static void |
zip(Iterable<File> files,
BufferedOutputStream buffer)
Zip files to a destination stream. |
static void |
zip(Iterable<File> files,
File destination)
Zip files to a destination. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void createIfNotExists(File file)
file
- The file to create.public static String getTextOfSystemResource(String path)
path
- The path to the file.
public static String getTextOf(String path)
path
- The path to the file.
public static Collection<String> getLinesOf(InputStream stream)
stream
- The stream to count the lines from.
public static void downloadFile(String filePath, String destination) throws FileException
filePath
- The path to the file to download.destination
- The path to the destination's file.
FileException
- If an error occurs during the downloading processpublic static void copy(String sourcePath, String targetPath) throws CopyException
sourcePath
- The path of the source.targetPath
- The path of the destination.
CopyException
- Thrown if an error occurs during the copy.public static void copy(File source, File target) throws CopyException
source
- The source's file.target
- The destination's file.
CopyException
- Thrown when a problem occurs during the copy.public static void move(String sourcePath, String targetPath) throws CopyException
sourcePath
- The path of the source.targetPath
- The path of the destination.
CopyException
- Thrown if an error occurs during the move.public static Collection<File> unzip(InputStream source, String destinationFolder)
source
- The source bufferdestinationFolder
- The destination folder.
public static void zip(Iterable<File> files, File destination)
files
- The files we have to zip.destination
- The archive destination file.public static void zip(Iterable<File> files, BufferedOutputStream buffer)
files
- The files we have to zip.buffer
- The destination stream.public static void delete(String path)
path
- The path to the file.public static void delete(File file)
file
- The file.public static void createEmptyFile(String path)
path
- The path to the empty file.public static String encryptKey(String key)
key
- The string to encrypt.
public static boolean isFileInDirectory(File file, File folder)
file
- The file to test.folder
- The folder to test.
public static void clearFolder(File folder)
folder
- The folder to clean.public static boolean putFileInDirectoryIfNot(File file, File folder)
file
- The file.folder
- The folder.
public static InputStream asInputStream(String path) throws FileNotFoundException
path
- The path to get an input stream for.
FileNotFoundException
- If the path doesn't represent an existing file.public static void close(Closeable closable)
closable
- The closable resource to close.public static void close(ZipFile zipFile)
zipFile
- The zip file to close.public static File getAnExistingFile()
public static long getFileSize(String path)
path
- The path to the file.
public static long getFileSize(File file)
file
- The file to calc the size.
public static Date getLastModifiedDate(String path)
path
- The path to the file.
public static Date getLastModifiedDate(File file)
file
- The file.
public static String getFreeName(String folder, String name)
folder
- The folder to search free name in.name
- The name to add.
public static Collection<File> getFilesOfFolder(File folder, FileFilter fileFilter)
folder
- The folder to get the files from.fileFilter
- The filter to use to select the files.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |