public class FlexFileUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
calculateDirectoryHash(java.io.File pDirToHash)
Calculate directory hash by considering all files in the folder.
|
static java.lang.String |
calculateFileHash(java.io.File pFile)
Calculates hash based on file content.
|
static java.lang.String |
convertByteArrayToHexString(byte[] arrayBytes) |
static java.lang.String |
convertGlobToRegEx(java.lang.String line) |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir)
Contents of SrcDir are copied to DestDir.
|
static void |
copyFile(java.io.File srcFile,
java.io.File destFile)
Copy file.
|
static void |
delete(java.io.File fileOrDirectory)
Delete file or directory represented by supplied file object
|
static void |
deleteDirectory(java.io.File directory)
Delete directory including all of it's contents.
|
static void |
deleteDirectorySafely(java.io.File pDirectory)
Delete a directory safely.
|
static void |
deleteFile(java.io.File file)
Delete file
|
static void |
deleteFileSafely(java.io.File file)
Delete file, ignoring if delete fails
|
static void |
deleteSafely(java.io.File pFileOrDirectory)
Delete File or Directory safely.
|
static void |
ensureDirectory(java.io.File directory) |
static java.util.Collection<java.io.File> |
getListOfFilesMatchingCaseInsensitiveSuffix(java.io.File sourceFolder,
java.lang.String suffix)
Finds files that end with suffix.
|
static java.io.File[] |
getListOfFilesMatchingExt(java.io.File sourceFolder,
java.lang.String pExtension)
Don't put the .
|
static java.lang.String[] |
getListOfFilesMatchingExt(java.lang.String pDirectory,
java.lang.String pExtension)
Returns an empty list if no files are found.
|
static java.util.Collection<java.io.File> |
getListOfFilesMatchingRegex(java.io.File sourceFolder,
java.lang.String regex) |
static java.util.Collection<java.io.File> |
getListOfFilesMatchingSuffix(java.io.File sourceFolder,
java.lang.String suffix)
Finds files that end with suffix.
|
static java.util.Collection<java.io.File> |
getListOfFilesMatchingWildcard(java.io.File sourceFolder,
java.lang.String wildCardExpression) |
static java.lang.String |
hashInputStream(java.io.InputStream inputStream,
java.lang.String pFileName) |
static boolean |
isSymbolicLink(java.io.File file)
Returns true if file represents symbolic link.
|
static java.lang.String[] |
list(java.io.File directory)
checks for access issues, if null is returned from list, it means that this process can not access that folder.
|
static java.io.File[] |
listFiles(java.io.File directory)
checks for access issues, if null is returned from listFiles, it means that this process can not access that
folder.
|
static java.io.File[] |
listFilesNewerThan(java.io.File directory,
long timestamp) |
static java.io.File[] |
listFilesOlderThan(java.io.File directory,
long timestamp) |
static java.lang.String |
listStringToString(java.util.List<java.lang.String> lines) |
static java.lang.String |
probeContentType(java.io.File pFile) |
static java.lang.String |
probeContentType(java.lang.String pFileName) |
static java.util.List<java.lang.String> |
read(java.io.File file)
Reads a File into a List<String>
|
static java.util.List<java.lang.String> |
read(java.io.InputStream is)
Reads an input stream into a List<String>
|
static java.util.Map<java.lang.String,java.lang.String> |
readAsMap(java.io.File file)
This method will not work if the file has 2 or more = signs on a line.
|
static byte[] |
readBytesFromFile(java.io.File file) |
static java.lang.String |
readFileAsMultiLineString(java.io.File file) |
static java.lang.String |
readFileAsMultiLineString(java.io.InputStream is) |
static java.lang.String |
readFileAsString(java.io.File file) |
static java.lang.String |
readFileAsString(java.io.InputStream is) |
static void |
rename(java.io.File from,
java.io.File to) |
static void |
unZip(java.io.File pFileToUnzip,
java.io.File pOutputFolder) |
static void |
unZip(java.io.InputStream pInputStream,
java.io.File pOutputFolder) |
static void |
unZipJar(java.lang.String pJarFileWithPath,
java.lang.String pOutputFolder) |
static void |
unZipJar(java.lang.String pJarFile,
java.lang.String pInputFolder,
java.lang.String pOutputFolder) |
static void |
write(java.io.File file,
java.util.List<java.lang.String> data)
Write a list of strings to a file with UTF-8 charset
|
static void |
write(java.io.File file,
java.util.List<java.lang.String> data,
java.nio.charset.Charset pCharset)
Write list of strings to a file with the specificed charset
|
static void |
writeAsMap(java.io.File file,
java.util.Map<java.lang.String,java.lang.String> map) |
static void |
writeBytesToFile(java.io.File file,
byte[] pData)
Writes a byte array to a file
Throws FlexRuntimeException
|
static void |
writeInputStreamToFile(java.io.File resultsFile,
java.io.InputStream inputStream)
Writes an input stream to a file
Throws FlexRuntimeException
|
static int |
zip(java.io.File pSourceDirectory,
java.lang.String pTargetFile) |
static void |
zipDirectory(java.lang.String pNamePrefix,
java.io.File pDirectory,
java.util.zip.ZipOutputStream pZos)
Add a directory to a ZipOutputStream.
|
static void |
zipFile(java.lang.String pNamePrefix,
java.io.File pFile,
java.util.zip.ZipOutputStream pZipOutputStream)
Add a file into a zip output stream
|
public static void ensureDirectory(java.io.File directory)
public static void deleteDirectory(java.io.File directory)
directory
- public static void deleteDirectorySafely(java.io.File pDirectory)
pDirectory
- public static void deleteFile(java.io.File file)
file
- public static void deleteFileSafely(java.io.File file)
file
- public static void delete(java.io.File fileOrDirectory)
fileOrDirectory
- public static void deleteSafely(java.io.File pFileOrDirectory)
pFileOrDirectory
- public static boolean isSymbolicLink(java.io.File file)
file
- public static java.io.File[] listFiles(java.io.File directory)
directory
- public static java.io.File[] listFilesOlderThan(java.io.File directory, long timestamp)
public static java.io.File[] listFilesNewerThan(java.io.File directory, long timestamp)
public static java.lang.String[] list(java.io.File directory)
directory
- public static void copyFile(java.io.File srcFile, java.io.File destFile)
srcFile
- destFile
- public static void copyDirectory(java.io.File srcDir, java.io.File destDir)
srcDir
- destDir
- public static void rename(java.io.File from, java.io.File to)
public static byte[] readBytesFromFile(java.io.File file)
public static void writeInputStreamToFile(java.io.File resultsFile, java.io.InputStream inputStream)
file
- - file to writeinputStream
- - InputStream to write.
The inputStream is not closed, and should be by the caller.public static void writeBytesToFile(java.io.File file, byte[] pData)
file
- - file to writepData
- - data for file.public static java.util.List<java.lang.String> read(java.io.File file)
file
- - file to read.public static java.util.List<java.lang.String> read(java.io.InputStream is)
is
- - input streampublic static java.lang.String readFileAsString(java.io.File file)
public static java.lang.String readFileAsString(java.io.InputStream is)
public static java.lang.String readFileAsMultiLineString(java.io.File file)
public static java.lang.String readFileAsMultiLineString(java.io.InputStream is)
public static java.lang.String listStringToString(java.util.List<java.lang.String> lines)
public static java.util.Map<java.lang.String,java.lang.String> readAsMap(java.io.File file)
file
- public static void write(java.io.File file, java.util.List<java.lang.String> data)
file
- File to write todata
- List of strings to writepublic static void write(java.io.File file, java.util.List<java.lang.String> data, java.nio.charset.Charset pCharset)
file
- File to write todata
- List of strings to writepCharset
- Charset to write withpublic static void writeAsMap(java.io.File file, java.util.Map<java.lang.String,java.lang.String> map)
public static java.lang.String[] getListOfFilesMatchingExt(java.lang.String pDirectory, java.lang.String pExtension)
pDirectory
- pExtension
- public static java.io.File[] getListOfFilesMatchingExt(java.io.File sourceFolder, java.lang.String pExtension)
sourceFolder
- pExtension
- - NO PERIOD.public static java.util.Collection<java.io.File> getListOfFilesMatchingSuffix(java.io.File sourceFolder, java.lang.String suffix)
sourceFolder
- suffix
- public static java.util.Collection<java.io.File> getListOfFilesMatchingCaseInsensitiveSuffix(java.io.File sourceFolder, java.lang.String suffix)
sourceFolder
- suffix
- public static java.util.Collection<java.io.File> getListOfFilesMatchingRegex(java.io.File sourceFolder, java.lang.String regex)
public static java.util.Collection<java.io.File> getListOfFilesMatchingWildcard(java.io.File sourceFolder, java.lang.String wildCardExpression)
public static int zip(java.io.File pSourceDirectory, java.lang.String pTargetFile) throws FlexCheckedException
FlexCheckedException
public static void unZip(java.io.File pFileToUnzip, java.io.File pOutputFolder) throws FlexCheckedException
FlexCheckedException
public static void unZip(java.io.InputStream pInputStream, java.io.File pOutputFolder) throws FlexCheckedException
FlexCheckedException
public static void unZipJar(java.lang.String pJarFile, java.lang.String pInputFolder, java.lang.String pOutputFolder) throws FlexCheckedException
FlexCheckedException
public static void unZipJar(java.lang.String pJarFileWithPath, java.lang.String pOutputFolder) throws FlexCheckedException
FlexCheckedException
public static void zipDirectory(java.lang.String pNamePrefix, java.io.File pDirectory, java.util.zip.ZipOutputStream pZos) throws java.io.IOException
pNamePrefix
- Name of the directorypFiles
- Directory to zippZos
- Already opened ZipOutputStream. CALLER MUST CLOSE THIS STREAM.java.io.IOException
public static void zipFile(java.lang.String pNamePrefix, java.io.File pFile, java.util.zip.ZipOutputStream pZipOutputStream) throws java.io.IOException
pNamePrefix
- directory before the filepFile
- The file to addpZipOutputStream
- The stream to add the file too. Caller needs to close the stream.java.io.IOException
public static java.lang.String convertGlobToRegEx(java.lang.String line)
public static java.lang.String calculateDirectoryHash(java.io.File pDirToHash) throws FlexCheckedException
pDirToHash
- FlexCheckedException
public static java.lang.String calculateFileHash(java.io.File pFile) throws FlexCheckedException
pFile
- FlexCheckedException
public static java.lang.String hashInputStream(java.io.InputStream inputStream, java.lang.String pFileName) throws FlexCheckedException
FlexCheckedException
public static java.lang.String convertByteArrayToHexString(byte[] arrayBytes)
public static java.lang.String probeContentType(java.lang.String pFileName)
public static java.lang.String probeContentType(java.io.File pFile)