public class FlexFileUtils
extends FlexFileBase
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 |
convertBase64EncodedString(java.lang.String pEncodedString) |
static void |
convertBase64EncodedStringToFile(java.lang.String pEncodedString,
java.io.File pFile)
Deprecated.
Use java 8 Base64 when java 6 dependency is removed.
|
static java.lang.String |
convertByteArrayToHexString(byte[] arrayBytes) |
static java.lang.String |
convertFileToBase64String(java.io.File pFile) |
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 its 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.lang.String |
getExtensionFromFileName(java.lang.String pFileNamePath) |
static java.lang.String |
getExtensionFromFileName(java.lang.String pFileNamePath,
java.lang.String pDefaultExtension) |
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 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)
in Java 11+, need to include javax.activation as a dependency to use this method.
|
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 specified 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
|
static java.io.InputStream |
zipInputStreamsToInputStream(java.util.Map<java.lang.String,java.io.InputStream> pInputStreams)
Combines multiple input streams into a single compressed input stream
|
static java.io.ByteArrayOutputStream |
zipInputStreamsToOutputStream(java.util.Map<java.lang.String,java.io.InputStream> pInputStreams)
Combines multiple input streams into a single zip 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 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)
resultsFile
- - 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 java.io.ByteArrayOutputStream zipInputStreamsToOutputStream(java.util.Map<java.lang.String,java.io.InputStream> pInputStreams) throws java.io.IOException
pInputStreams
- Map of [fileName: InputStream] to include in the zipjava.io.IOException
public static java.io.InputStream zipInputStreamsToInputStream(java.util.Map<java.lang.String,java.io.InputStream> pInputStreams) throws java.io.IOException
pInputStreams
- Map of [fileName: InputStream] to include in the zipjava.io.IOException
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 directorypDirectory
- 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
This method was copied from ArtifactUtil of FlexDeployPluginCore.
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)
public static java.lang.String convertFileToBase64String(java.io.File pFile)
public static void convertBase64EncodedStringToFile(java.lang.String pEncodedString, java.io.File pFile) throws FlexCheckedException
pEncodedString
- pFile
- FlexCheckedException
public static java.lang.String convertBase64EncodedString(java.lang.String pEncodedString)
public static java.lang.String getExtensionFromFileName(java.lang.String pFileNamePath)
public static java.lang.String getExtensionFromFileName(java.lang.String pFileNamePath, java.lang.String pDefaultExtension)