public class FileUtilities
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileUtilities.Access |
static class |
FileUtilities.DateType |
static class |
FileUtilities.FileAttribute
To model the file attribute.
|
static class |
FileUtilities.FileAttributeFilter
Note:
To form a new instance of class FileAttributeFilter,please use
one of the following file attribute's code or their combination:
FileUtilities.FileAttribute.Type.NORMALFILE
FileUtilities.FileAttribute.Type.READONLYFILE
FileUtilities.FileAttribute.Type.HIDDENFILE
FileUtilities.FileAttribute.Type.SYSTEMFILE
FileUtilities.FileAttribute.Type.DIRECTORY
FileUtilities.FileAttribute.Type.ARCHIVEFILE
For example:
//this filter will help to get all normal files, all hidden files and all archive files. |
static class |
FileUtilities.FileType |
static class |
FileUtilities.FilterMode |
static class |
FileUtilities.ImageFilterMode |
static class |
FileUtilities.Mode |
static class |
FileUtilities.PatternFilterMode |
static class |
FileUtilities.Placement |
static interface |
FileUtilities.Predicate<T>
Provides one method test() returning boolean.
A copy from Java 8, this interface could be removed when using Java 8 or later. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
ARCHIVEFILESUFFIX
A list of suffix for archive file in link http://en.wikipedia.org/wiki/List_of_archive_formats
|
static char |
ATTRIBUTE_ARCHIVE
'A'
|
static char |
ATTRIBUTE_HIDDEN
'H'
|
static char |
ATTRIBUTE_READONLY
'R'
|
static char |
ATTRIBUTE_SYSTEM
'S'
|
static java.lang.String[] |
ATTRIBUTES_ARRAY
An array containing "R" "S" "H" "A"
|
static java.lang.String |
DOS_COMMAND_ATTRIB
"attrib"
|
static java.lang.String |
FILE_SEP_UNIX
"/"
|
static java.lang.String |
FILE_SEP_WIN
"\\"
|
static int |
FILE_TYPE_BENCH |
static int |
FILE_TYPE_DATAPOOL |
static int |
FILE_TYPE_DIFF |
static int |
FILE_TYPE_PROJECT |
static int |
FILE_TYPE_TEST |
static int |
PARAM_ALL_CHARACTERS
-1, means all characters will be written.
|
static java.lang.String |
PARAM_CASE_INSENSITIVE
"CaseInsensitive"
|
static java.lang.String |
PARAM_CASE_SENSITIVE
"CaseSensitive"
|
static java.lang.String |
PARAM_NO_VERIYF
"NoVerify"
|
static java.lang.String |
VAR_SAFSBENCHDIRECTORY |
static java.lang.String |
VAR_SAFSDATAPOOLDIRECTORY |
static java.lang.String |
VAR_SAFSDIFDIRECTORY |
static java.lang.String |
VAR_SAFSLOGSDIRECTORY |
static java.lang.String |
VAR_SAFSPROJECTDIRECTORY |
static java.lang.String |
VAR_SAFSTESTDIRECTORY |
Constructor and Description |
---|
FileUtilities() |
Modifier and Type | Method and Description |
---|---|
static java.util.Properties |
appendProperties(java.util.Properties target,
java.net.URL url)
Open a new Properties file located at the provided URL and add its entries
to those in the target Properties file.
|
static int |
copyDirectoryRecursively(java.io.File srcDir,
java.io.File destDir)
Careful what you wish for...
|
static void |
copyFile(java.io.InputStream in,
java.io.OutputStream out) |
static void |
copyFileToFile(java.io.BufferedReader reader,
java.io.BufferedWriter writer)
Copy one file (BufferedReader) to another file (BufferedWriter).
|
static void |
copyFileToFile(java.io.File source,
java.io.File dest)
Attempt to copy a source File to a destination File location.
|
static void |
copySystemToUTF8File(java.lang.String systemFile,
java.lang.String utf8File)
Copy a default system codepage file to a file in UTF-8 format.
|
static void |
copyUTF8ToSystemFile(java.lang.String utf8File,
java.lang.String systemFile)
Copy a UTF-8 format file to a file in the default system codepage.
|
static java.io.File |
deduceBenchFile(java.lang.String filename,
RuntimeDataInterface data)
Deduce the absolute full path bench-relative file.
|
static java.io.File |
deduceDatapoolFile(java.lang.String filename,
RuntimeDataInterface data)
Deduce the absolute full path datapool-relative file.
|
static java.io.File |
deduceDiffFile(java.lang.String filename,
RuntimeDataInterface data)
Deduce the absolute full path Diff-relative file.
|
static java.io.File |
deduceFile(java.lang.String filename,
int type,
RuntimeDataInterface data)
Deduce the absolute full path to a project-relative, test-relative, bench-relative, diff-relative filename.
|
static java.lang.String |
deduceMatchingUUIDFilename(java.lang.String benchFilename)
Create a unique test/actual filename matching the benchFilename but with a UUID String embedded.
|
static java.io.File |
deduceProjectFile(java.lang.String filename,
RuntimeDataInterface data)
Deduce the absolute full path to a project-relative file.
|
static java.io.File |
deduceTestFile(java.lang.String filename,
RuntimeDataInterface data)
Deduce the absolute full path test-relative file.
|
static int |
deleteDirectoryRecursively(java.lang.String directory,
boolean verbose)
Remove directory recursively by JAVA API
|
static java.lang.String |
detectFileEncoding(java.lang.String filename)
Detects file's encoding.
This depends on class FileUtilitiesByThirdParty , which requires jar
juniversalchardet |
static java.lang.String |
detectStringEncoding(java.lang.String str)
Detects String encoding.
This depends on class FileUtilitiesByThirdParty , which requires jar
juniversalchardet |
static java.io.BufferedReader |
getBufferedFileReader(java.lang.String filename,
java.lang.String encoding)
Provides a BufferedReader for a FileInputStream with encoding.
|
static java.io.BufferedWriter |
getBufferedFileWriter(java.lang.String filename,
java.lang.String encoding)
Provides a BufferedWriter for a FileOutputStream with encoding.
|
static java.lang.String |
getExtension(java.io.File file)
Return the lower-case file extension portion of the provided logical file.
|
static FileUtilities.FileAttribute |
getFileAttribute(java.io.File file) |
static java.lang.String |
getPlatformName() |
static java.io.BufferedReader |
getSystemBufferedFileReader(java.lang.String filename)
Provides a BufferedReader for a FileInputStream opened with an InputStreamReader using the
default System codepage\charset.
|
static java.io.BufferedWriter |
getSystemBufferedFileWriter(java.lang.String filename)
Provides a BufferedWriter for a FileOutputStream opened with an OutputStreamWriter using the
default System codepage\charset.
|
static java.io.BufferedWriter |
getSystemBufferedFileWriter(java.lang.String filename,
boolean append)
Provides a BufferedWriter for a FileOutputStream opened with an OutputStreamWriter using the
default System codepage\charset.
|
static java.io.BufferedReader |
getUTF8BufferedFileReader(java.lang.String filename)
Provides a BufferedReader for a FileInputStream opened with a UTF-8 InputStreamReader.
|
static java.io.BufferedWriter |
getUTF8BufferedFileWriter(java.lang.String filename)
Provides a BufferedWriter for a FileOutputStream opened with a UTF-8 OutputStreamWriter.
|
static java.io.BufferedWriter |
getUTF8BufferedFileWriter(java.lang.String filename,
boolean append)
Provides a BufferedWriter for a FileOutputStream opened with a UTF-8 OutputStreamWriter.
|
static boolean |
isArchive(java.io.File file)
Return true, if the file has a suffix as one of
ARCHIVEFILESUFFIX . |
static boolean |
isArchive(java.lang.String filename)
Return true, if the file has a suffix as one of
ARCHIVEFILESUFFIX . |
static boolean |
isFileUTF8(java.lang.String filename)
Opens a FileInputStream and checks for UTF-8 0xEF 0xBB 0xBF marker bytes and closes the file.
|
static boolean |
isReadOnly(java.io.File file)
If file can be read and can NOT be wrote, then return true.
|
static boolean |
isWindowPlatform() |
static java.lang.String |
normalizeFileSeparators(java.lang.String filename)
Attempt to replace all filename path separators ( "\" or "/" ) with the correct ones for
the current environment.
|
static java.lang.String[] |
readLinesFromFile(java.lang.String filepath)
Read file lines into a String[].
|
static java.lang.String |
readStringFromEncodingFile(java.lang.String filename,
java.lang.String encoding)
Read file contents into a String.
|
static java.lang.String |
readStringFromFile(java.io.BufferedReader reader)
Read file contents into a String.
|
static java.lang.String |
readStringFromSystemFile(java.lang.String filename)
Read file contents into a String.
|
static java.lang.String |
readStringFromUTF8File(java.lang.String filename)
Read file contents into a String.
|
static void |
replaceAllSubdirectoryFilesSubstrings(java.lang.String directory,
java.lang.String[] fileEndings,
java.lang.String findString,
java.lang.String replaceString,
boolean isCaseSensitive)
Recursively replaceDirectoryFileSubstrings in all matching files in the directory and all
sub-directories.
|
static void |
replaceDirectoryFilesSubstrings(java.lang.String directory,
java.lang.String[] fileEndings,
java.lang.String findString,
java.lang.String replaceString,
boolean isCaseSensitive)
Examine the contents of each file in the specified directory whose filename matches any one of the provided fileEndings.
|
static boolean |
setFileAttribute(FileUtilities.FileAttribute attribute,
java.io.File file) |
static void |
unzipFile(java.lang.String zipFileName,
java.io.File root,
boolean verbose)
Calls unzipJAR with noMETATDir as false.
|
static void |
unzipJAR(java.lang.String zipFileName,
java.io.File root,
boolean verbose,
boolean noMETADir) |
static void |
unzipJAR(java.lang.String zipFileName,
java.io.File root,
boolean verbose,
FileUtilities.Predicate<java.lang.String> skipPredicator) |
static void |
writeCollectionToFile(java.io.BufferedWriter writer,
java.util.Collection<?> list)
Output the toString() values in a Collection as separate lines in a new file.
|
static void |
writeCollectionToFile(java.io.BufferedWriter writer,
java.util.Collection<?> list,
java.lang.String newline)
Output the toString() values in a Collection as separate lines in a new file.
|
static void |
writeCollectionToSystemFile(java.lang.String filename,
java.util.Collection<?> list)
Output the toString() values in a Collection as separate lines in a new file.
|
static void |
writeCollectionToUTF8File(java.lang.String filename,
java.util.Collection<?> list)
Output the toString() values in a Collection as separate lines in a new file.
|
static void |
writePropertiesFile(java.io.BufferedWriter writer,
java.util.Map<java.lang.String,java.lang.String> props)
Purpose: write Properties contents to BufferedWriter in a SAFS Properties file format: |
static void |
writeStringToFile(java.io.BufferedWriter writer,
java.lang.String data)
Output a String to a new file.
|
static void |
writeStringToFile(java.lang.String filename,
java.lang.String encoding,
java.lang.String data)
Output the String in a new file.
|
static void |
writeStringToSystemFile(java.lang.String filename,
java.lang.String data)
Output the toString() values in a Collection as separate lines in a new file.
|
static void |
writeStringToUTF8File(java.lang.String filename,
java.lang.String data)
Output the String in a new file.
|
public static final int FILE_TYPE_TEST
public static final int FILE_TYPE_BENCH
public static final int FILE_TYPE_PROJECT
public static final int FILE_TYPE_DIFF
public static final int FILE_TYPE_DATAPOOL
public static final java.lang.String VAR_SAFSBENCHDIRECTORY
public static final java.lang.String VAR_SAFSDATAPOOLDIRECTORY
public static final java.lang.String VAR_SAFSDIFDIRECTORY
public static final java.lang.String VAR_SAFSLOGSDIRECTORY
public static final java.lang.String VAR_SAFSPROJECTDIRECTORY
public static final java.lang.String VAR_SAFSTESTDIRECTORY
public static java.lang.String FILE_SEP_UNIX
public static java.lang.String FILE_SEP_WIN
public static final java.lang.String PARAM_NO_VERIYF
public static final java.lang.String PARAM_CASE_SENSITIVE
public static final java.lang.String PARAM_CASE_INSENSITIVE
public static final int PARAM_ALL_CHARACTERS
public static final java.lang.String[] ARCHIVEFILESUFFIX
public static final java.lang.String DOS_COMMAND_ATTRIB
public static final char ATTRIBUTE_READONLY
public static final char ATTRIBUTE_SYSTEM
public static final char ATTRIBUTE_HIDDEN
public static final char ATTRIBUTE_ARCHIVE
public static final java.lang.String[] ATTRIBUTES_ARRAY
public static java.io.BufferedWriter getBufferedFileWriter(java.lang.String filename, java.lang.String encoding) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.encoding
- The encoding to be used to create a OutputStreamWriter;
If null, a default encoding indicated by "file.encoding" will be used.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist and cannot be created, cannot be opened for write operations, etc.CaseInsensitiveFile
,
OutputStreamWriter
,
FileOutputStream
public static java.io.BufferedWriter getUTF8BufferedFileWriter(java.lang.String filename) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist and cannot be created, cannot be opened for write operations, etc.CaseInsensitiveFile
,
OutputStreamWriter
,
FileOutputStream
public static java.io.BufferedWriter getUTF8BufferedFileWriter(java.lang.String filename, boolean append) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.append
- if true, append contents to the end of filejava.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist and cannot be created, cannot be opened for write operations, etc.CaseInsensitiveFile
,
OutputStreamWriter
,
FileOutputStream
public static boolean isFileUTF8(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
filename
- case-insensitive absolute filename path.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist, cannot be opened for read operations, etc.java.io.IOException
- if there is an IO problem when attempting to open or read from the file.CaseInsensitiveFile
,
FileInputStream
,
FileOutputStream
public static java.lang.String detectFileEncoding(java.lang.String filename)
FileUtilitiesByThirdParty
, which requires jar
juniversalchardetfilename
- case-insensitive absolute filename path.public static java.lang.String detectStringEncoding(java.lang.String str)
FileUtilitiesByThirdParty
, which requires jar
juniversalchardetstr
- - input as string.public static java.lang.String normalizeFileSeparators(java.lang.String filename)
filename
- that may or may not have separators embedded.public static java.io.BufferedReader getBufferedFileReader(java.lang.String filename, java.lang.String encoding) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.encoding
- The encoding to be used to create a InputStreamReader;
If null, a default encoding indicated by "file.encoding" will be used.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist, cannot be opened for read operations, etc.CaseInsensitiveFile
,
InputStreamReader
,
FileInputStream
public static java.io.BufferedReader getUTF8BufferedFileReader(java.lang.String filename) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist, cannot be opened for read operations, etc.CaseInsensitiveFile
,
InputStreamReader
,
FileInputStream
public static java.io.BufferedWriter getSystemBufferedFileWriter(java.lang.String filename) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist and cannot be created, cannot be opened for write operations, etc.CaseInsensitiveFile
,
OutputStreamWriter
,
FileOutputStream
public static java.io.BufferedWriter getSystemBufferedFileWriter(java.lang.String filename, boolean append) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.append
- if true, append contents to the end of filejava.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist and cannot be created, cannot be opened for write operations, etc.CaseInsensitiveFile
,
OutputStreamWriter
,
FileOutputStream
public static java.io.BufferedReader getSystemBufferedFileReader(java.lang.String filename) throws java.io.FileNotFoundException
filename
- case-insensitive absolute filename path.java.io.FileNotFoundException
- if filename exists but points to a directory instead of a regular file,
does not exist, cannot be opened for read operations, etc.CaseInsensitiveFile
,
InputStreamReader
,
FileInputStream
public static void copyFileToFile(java.io.BufferedReader reader, java.io.BufferedWriter writer) throws java.io.IOException
reader
- BufferedReader to copy from.writer
- BufferedWriter to copy to.java.io.IOException
- if an error occurs reading or writing.public static void copyUTF8ToSystemFile(java.lang.String utf8File, java.lang.String systemFile) throws java.io.FileNotFoundException
utf8File
- full absolute path of readable UTF-8 file to copy to default system codepage.systemFile
- full absolute path to valid output file to be created during copy.java.io.FileNotFoundException
- if filenames exist but points to a directory instead of regular files,
input file does not exist or output file cannot be created, or files cannot be opened for
read or write operations, as appropriate.copyFileToFile(BufferedReader, BufferedWriter)
public static void copySystemToUTF8File(java.lang.String systemFile, java.lang.String utf8File) throws java.io.FileNotFoundException
systemFile
- full absolute path to default system file to be copied to UTF-8.utf8File
- full absolute path of file to be created during copy.java.io.FileNotFoundException
- if filenames exist but point to a directory instead of regular files,
input file does not exist or output file cannot be created, or files cannot be opened for
read or write operations, as appropriate.copyFileToFile(BufferedReader, BufferedWriter)
public static void writeCollectionToFile(java.io.BufferedWriter writer, java.util.Collection<?> list, java.lang.String newline) throws java.io.IOException
The writer is flushed and closed here, upon completion.
writer
- BufferedWriter determines the output character encoding.list
- Collection of objects\lines to writenewline
- String to append to each item in the list.java.io.IOException
- thrown if an IO error occurs during writing.public static void writePropertiesFile(java.io.BufferedWriter writer, java.util.Map<java.lang.String,java.lang.String> props) throws java.io.IOException
:PROPERTY:propertyName property value possibly spanning multiple lines. :PROPERTY:propertyName etc...
writer
- BufferedWriterprops
- Map, the properties to writejava.io.IOException
public static void writeStringToFile(java.io.BufferedWriter writer, java.lang.String data) throws java.io.IOException
writer
- BufferedWriter determines the output character encoding.data
- String text to write.java.io.IOException
- thrown if an IO error occurs during writing.writeStringToSystemFile(String, String)
,
writeStringToUTF8File(String, String)
public static void writeStringToSystemFile(java.lang.String filename, java.lang.String data) throws java.io.FileNotFoundException, java.io.IOException
filename
- absolute system path to the file to be created\overwritten.data
- String text to write.java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs during writing.writeStringToFile(BufferedWriter, String)
public static void writeStringToUTF8File(java.lang.String filename, java.lang.String data) throws java.io.FileNotFoundException, java.io.IOException
filename
- absolute system path to the file to be created\overwritten.data
- String text to write.java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs during writing.writeStringToFile(BufferedWriter, String)
public static void writeStringToFile(java.lang.String filename, java.lang.String encoding, java.lang.String data) throws java.io.FileNotFoundException, java.io.IOException
filename
- absolute system path to the file to be created\overwritten.encoding
- the encoding to be used to write a file.data
- String text to write.java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs during writing.writeStringToFile(BufferedWriter, String)
public static void writeCollectionToFile(java.io.BufferedWriter writer, java.util.Collection<?> list) throws java.io.IOException
writer
- BufferedWriter determines the output character encoding.list
- Collection of objects\lines to writejava.io.IOException
- thrown if an IO error occurs during writing.writeCollectionToFile(BufferedWriter, Collection, String)
,
writeCollectionToFile(BufferedWriter, Collection, String)
public static void writeCollectionToSystemFile(java.lang.String filename, java.util.Collection<?> list) throws java.io.FileNotFoundException, java.io.IOException
filename
- absolute system path to the file to be created\overwritten.list
- java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs during writing.writeCollectionToFile(BufferedWriter, Collection)
public static void writeCollectionToUTF8File(java.lang.String filename, java.util.Collection<?> list) throws java.io.FileNotFoundException, java.io.IOException
filename
- absolute system path to the file to be created\overwritten.list
- java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs during writing.writeCollectionToFile(BufferedWriter, Collection)
public static java.lang.String readStringFromFile(java.io.BufferedReader reader) throws java.io.IOException
reader
- BufferedReader determines the character decoding.java.io.IOException
- thrown if an IO error occurs.readStringFromSystemFile(String)
,
readStringFromUTF8File(String)
public static java.lang.String[] readLinesFromFile(java.lang.String filepath) throws java.io.IOException
filepath
- java.io.IOException
- thrown if an IO error occurs.readStringFromSystemFile(String)
,
readStringFromUTF8File(String)
public static void replaceAllSubdirectoryFilesSubstrings(java.lang.String directory, java.lang.String[] fileEndings, java.lang.String findString, java.lang.String replaceString, boolean isCaseSensitive) throws java.io.IOException
directory
- fileEndings
- findString
- replaceString
- isCaseSensitive
- java.io.IOException
replaceDirectoryFilesSubstrings(String, String[], String, String, boolean)
public static void replaceDirectoryFilesSubstrings(java.lang.String directory, java.lang.String[] fileEndings, java.lang.String findString, java.lang.String replaceString, boolean isCaseSensitive) throws java.io.IOException
directory
- fileEndings
- findString
- replaceString
- isCaseSensitive
- java.io.IOException
readLinesFromFile(String)
,
detectFileEncoding(String)
,
writeStringToFile(String, String, String)
,
writeStringToUTF8File(String, String)
public static java.lang.String readStringFromSystemFile(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
filename
- java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs.getSystemBufferedFileReader(String)
public static java.lang.String readStringFromUTF8File(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
filename
- java.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs.getUTF8BufferedFileReader(String)
public static java.lang.String readStringFromEncodingFile(java.lang.String filename, java.lang.String encoding) throws java.io.FileNotFoundException, java.io.IOException
filename
- encoding
- The encoding to be used to read a filejava.io.FileNotFoundException
java.io.IOException
- thrown if an IO error occurs.getUTF8BufferedFileReader(String)
public static java.util.Properties appendProperties(java.util.Properties target, java.net.URL url)
target
- Properties file to be appended, or null.url
- to Properties file to append.public static boolean isWindowPlatform()
public static java.lang.String getPlatformName()
public static java.lang.String getExtension(java.io.File file)
file
- public static void unzipFile(java.lang.String zipFileName, java.io.File root, boolean verbose) throws java.io.IOException, java.io.FileNotFoundException
zipFileName
- String, the 'zip file' to be uncompressed.root
- File, the directory to store the uncompressed files.verbose
- boolean, if the uncompressed message will be printed to console.java.io.IOException
java.io.FileNotFoundException
unzipJAR(String, File, boolean, boolean)
public static void unzipJAR(java.lang.String zipFileName, java.io.File root, boolean verbose, boolean noMETADir) throws java.io.IOException, java.io.FileNotFoundException
zipFileName
- String, the 'zip' or 'jar' file to be uncompressed.root
- File, the directory to store the uncompressed files.verbose
- boolean, if the uncompressed message will be printed to console.noMETADir
- true to bypass the META-INF directory and MANIFEST.MF file.java.io.IOException
java.io.FileNotFoundException
public static void unzipJAR(java.lang.String zipFileName, java.io.File root, boolean verbose, FileUtilities.Predicate<java.lang.String> skipPredicator) throws java.io.IOException, java.io.FileNotFoundException
zipFileName
- String, the 'zip' or 'jar' file to be uncompressed.root
- File, the directory to store the uncompressed files.verbose
- boolean, if the uncompressed message will be printed to console.skipPredicator
- Predicate, if its method test(T) returns true, then skip the file when unzip files.java.io.IOException
java.io.FileNotFoundException
public static void copyFile(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- InputStream, The InputStream of the source file to be copied.out
- OutputStream, The OutputStream of the destination file.java.io.IOException
public static int deleteDirectoryRecursively(java.lang.String directory, boolean verbose)
directory
- String, the directory to be recursively deleted.verbose
- boolean, if the error message will be printed to console.public static int copyDirectoryRecursively(java.io.File srcDir, java.io.File destDir) throws java.io.IOException, java.lang.IllegalArgumentException
srcDir
- destDir
- java.io.IOException
java.lang.IllegalArgumentException
public static void copyFileToFile(java.io.File source, java.io.File dest) throws java.io.IOException
source
- -- cannot be null and must be a file, not a directory.dest
- -- cannot be null. Will be created if it does not already exist.java.io.IOException
- if an error occurs during the attempt.public static boolean isArchive(java.io.File file) throws SAFSException
ARCHIVEFILESUFFIX
.SAFSException
public static boolean isArchive(java.lang.String filename) throws SAFSException
ARCHIVEFILESUFFIX
.SAFSException
public static boolean isReadOnly(java.io.File file) throws SAFSException
SAFSException
public static boolean setFileAttribute(FileUtilities.FileAttribute attribute, java.io.File file) throws SAFSException
attribute
- FileAttribute, the attribute to setfile
- File, the file for which the attributes will be setSAFSException
public static java.lang.String deduceMatchingUUIDFilename(java.lang.String benchFilename)
benchFilename
- Example: "benchmark.txt"public static java.io.File deduceFile(java.lang.String filename, int type, RuntimeDataInterface data) throws SAFSException
filename
- String, usually a relative path filename.
There is a caveat for test/bench/diff-relative filenames. If there is any File.separator present in the relative path then the path is considered relative to whatever is considered the Datapool directory unless it does not exist, or is already an absolute file path.
If it does not exist as the Datapool directory, or a subdirectory of the Datapool directory, then the path is made relative to the Project directory. A project-relative path is always relative to the actual project root directory unless it is given as an absolute file path.
If the provided filename is an absolute path, and contains a root path that includes the Bench directory, and the filepath sought is of type Test or Diff, then the filename/filepath will be converted to a comparable relative path off the Test or Diff directories as appropriate. This is done to avoid unintentional overwriting of benchmark files by test/actual and diff files.
type
- int, the type of the file: test-relative, bench-relative, project-relative.data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#FILE_TYPE_TEST}
,
#FILE_TYPE_BENCH}
,
#FILE_TYPE_DIFF}
,
#FILE_TYPE_DATAPOOL}
,
#FILE_TYPE_PROJECT}
public static java.io.File deduceTestFile(java.lang.String filename, RuntimeDataInterface data) throws SAFSException
filename
- String, the test/actual file name. If there are any File.separators in the
relative path then the path is actually considered relative to the Datapool
directory unless it does not exist, or is already an absolute file path.
If a relative directory path does not exist relative to the Datapool directory then the final path will be relative to the Project directory.
If it is an absolute path, and contains a root path that includes the Bench directory, then the file will be converted to a comparable relative path off the Test directory.
data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#deduceFile(String, int, RuntimeDataInterface)}
public static java.io.File deduceDiffFile(java.lang.String filename, RuntimeDataInterface data) throws SAFSException
filename
- String, the diff file name. If there are any File.separators in the
relative path then the path is actually considered relative to the Datapool
directory unless it does not exist, or is already an absolute file path.
If a relative directory path does not exist relative to the Datapool directory then the final path will be relative to the Project directory.
If it is an absolute path, and contains a root path that includes the Bench directory, then the file will be converted to a comparable relative path off the Diff directory.
data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#deduceFile(String, int, RuntimeDataInterface)}
public static java.io.File deduceBenchFile(java.lang.String filename, RuntimeDataInterface data) throws SAFSException
filename
- String, the test file name. If there are any File.separators in the
relative path then the path is actually considered relative to the Datapool
directory unless it does not exist, or is already an absolute file path.
If a relative directory path does not exist relative to the Datapool directory then
the final path will be relative to the Project directory.data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#deduceFile(String, int, RuntimeDataInterface)}
public static java.io.File deduceProjectFile(java.lang.String filename, RuntimeDataInterface data) throws SAFSException
filename
- String, the test file name. The path is ALWAYS considered relative
to the project root directory regardless of the absence or presence of File.separators
unless the file is already an absolute path.data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#deduceFile(String, int, RuntimeDataInterface)}
public static java.io.File deduceDatapoolFile(java.lang.String filename, RuntimeDataInterface data) throws SAFSException
filename
- String, the data file name. It can contain sub directories.data
- RuntimeDataInterface to access runtime data (directories). Like a subclass of GenericEngine, or Processor.SAFSException
#deduceFile(String, int, RuntimeDataInterface)}
public static FileUtilities.FileAttribute getFileAttribute(java.io.File file) throws SAFSException
file
- File, the file to extract the attribute information.SAFSException
Copyright © SAS Institute. All Rights Reserved.