|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.deduced.utilities.FileUtilities
public class FileUtilities

Utility methods used on files.
| Field Summary | |
|---|---|
static int |
CREATE_CODE
code returned when a file was created |
private static int |
DIRECTORY_DELETE_RETRY_COUNT
directory delete retry count |
private static int |
DIRECTORY_DELETE_RETRY_DELAY
delay between directory delete attempts in milliseconds. |
static java.lang.String |
DOT
Dot file name |
static java.lang.String |
FOLDER_SEPARATOR
folder separator constant |
static int |
IGNORED_CODE
code returned when a file was ignored |
private static java.lang.String |
JAR_FILE_NAME_REGULAR_EXPRESSION
regular expression used to find JAR file names. |
private static java.util.logging.Logger |
LOGGER
logger |
static int |
MODIFIED_CODE
code returned when a file was modified |
static int |
READ_BUFFER_SIZE
buffer size used to read files |
| Constructor Summary | |
|---|---|
FileUtilities()
|
|
| Method Summary | |
|---|---|
static void |
checkForErrorOnWriter(java.io.PrintWriter writer)
check For Error On Writer. |
static void |
closeQuietly(java.util.zip.ZipFile input)
close a zip file quietly. |
protected static void |
copyPathSkipDot(java.lang.String[] path,
java.util.List<java.lang.String> target)
copy a list of path fragments into a target list and skip all the useless parts (such as the "." path) |
static java.lang.String |
extractRelativePath(java.lang.String sourcePath,
java.lang.String targetPath)
extract a relative path between a source directory and a target directory or file. |
static java.lang.String |
extractRelativePathToWorkingDirectory(java.lang.String filePath)
extract a relative file path from the current working directory |
static boolean |
fileExists(java.lang.String filePath)
test if a file exists based on a path |
static void |
forceCreateDirectory(java.lang.String folderName)
force a directory creation |
static void |
forceDeleteDirectory(java.io.File directoryToDelete)
force Delete Directory through a retry mechanism |
static java.util.List<java.lang.String> |
getCanonicalFilePathList(java.io.File[] fileList)
get Canonical File Path List, ignoring any files from which we fail to get the path. |
static java.lang.String |
getCanonicalPathSilent(java.io.File currentFile)
get Canonical Path and log any exception that might occur. |
static java.lang.ClassLoader |
getCurrentThreadClassLoader()
get the Current Thread Class Loader |
static java.lang.String |
getCurrentWorkingDirectory()
|
static java.io.InputStream |
getFileContentStream(java.lang.String fileName)
get File Content Stream using either a system resource or a file system reference. |
static java.io.File[] |
getJarListFromFolder(java.lang.String folderName)
get the Jar List From a folder name. |
static java.io.InputStream |
getMandatoryFileContentStream(java.lang.String fileName)
get File Content Stream using either a system resource or a file system reference. |
static boolean |
isFileReadOnly(java.lang.String filePath)
test if a file is read only. |
static boolean |
isFileResource(java.lang.String filePath)
test if a file can be reached as a resource. |
static boolean |
isStreamContentEqual(java.io.InputStream readStream,
java.io.InputStream secondStream)
check if 2 streams have the same content |
static java.lang.String |
mergeFolderName(java.lang.String parentFolderName,
java.lang.String subFolderName)
merge two folder names together. |
static void |
overwriteFileContent(java.lang.String fileName,
byte[] content)
overwrite the content of a file, whatever the previous content was |
static byte[] |
stringToByteArray(java.lang.String content)
convert a string To a ByteArray |
static int |
writeFileContent(java.lang.String fileName,
byte[] content)
write the file content |
static int |
writeFileContent(java.lang.String fileName,
java.lang.String content)
write the file content |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger LOGGER
private static final java.lang.String JAR_FILE_NAME_REGULAR_EXPRESSION
private static final int DIRECTORY_DELETE_RETRY_COUNT
private static final int DIRECTORY_DELETE_RETRY_DELAY
public static final java.lang.String FOLDER_SEPARATOR
public static final java.lang.String DOT
public static final int READ_BUFFER_SIZE
public static final int CREATE_CODE
public static final int MODIFIED_CODE
public static final int IGNORED_CODE
| Constructor Detail |
|---|
public FileUtilities()
| Method Detail |
|---|
public static int writeFileContent(java.lang.String fileName,
java.lang.String content)
throws java.io.IOException
fileName - the name of the filecontent - content of the file
java.io.IOException - any error generated when accessing the filepublic static byte[] stringToByteArray(java.lang.String content)
content - the string content
public static int writeFileContent(java.lang.String fileName,
byte[] content)
throws java.io.IOException
fileName - the name of the filecontent - content of the file
java.io.IOException - any error generated when accessing the file
public static void overwriteFileContent(java.lang.String fileName,
byte[] content)
throws java.io.IOException
fileName - the file namecontent - the file content
java.io.IOException - any error that occurred while accessing the file
public static boolean isStreamContentEqual(java.io.InputStream readStream,
java.io.InputStream secondStream)
readStream - the first streamsecondStream - the second stream
public static java.lang.String extractRelativePath(java.lang.String sourcePath,
java.lang.String targetPath)
sourcePath - the source folder to extract a relative path, must be
an absolute pathtargetPath - the target file or folder to extract a relative path,
must be an absolute path
protected static void copyPathSkipDot(java.lang.String[] path,
java.util.List<java.lang.String> target)
path - the path fragmentstarget - the target list that receives the path fragmentspublic static java.lang.String extractRelativePathToWorkingDirectory(java.lang.String filePath)
filePath - the absolute file path to differentiate from the current
working directory
public static java.lang.String getCurrentWorkingDirectory()
public static boolean isFileReadOnly(java.lang.String filePath)
filePath - the file path
public static boolean isFileResource(java.lang.String filePath)
filePath - the file path
public static boolean fileExists(java.lang.String filePath)
filePath - the file path
public static java.lang.String mergeFolderName(java.lang.String parentFolderName,
java.lang.String subFolderName)
Execution example:
mergeFolderName("", "abc/def") = "abc/def"
mergeFolderName(null, "abc/def") = "abc/def"
mergeFolderName("test/me", null) = "test/me"
mergeFolderName("test/me", "abc/def") = "test/me/abc/def"
mergeFolderName("test/me/", "abc/def") = "test/me/abc/def"
parentFolderName - the parent folder namesubFolderName - the child folder name
public static void forceCreateDirectory(java.lang.String folderName)
throws java.io.IOException
folderName - the folder name
java.io.IOException - any error encountered during the creation
public static java.io.InputStream getFileContentStream(java.lang.String fileName)
throws java.io.IOException
fileName - file name
java.io.IOException - for read errors.public static java.lang.ClassLoader getCurrentThreadClassLoader()
public static java.io.InputStream getMandatoryFileContentStream(java.lang.String fileName)
throws java.io.IOException
fileName - file name
java.io.IOException - for read errors.public static void closeQuietly(java.util.zip.ZipFile input)
input - the zip file to close
public static void forceDeleteDirectory(java.io.File directoryToDelete)
throws java.io.IOException
directoryToDelete - the directory to delete
java.io.IOException - the last errorpublic static void checkForErrorOnWriter(java.io.PrintWriter writer)
writer - the writer to verify.public static java.io.File[] getJarListFromFolder(java.lang.String folderName)
folderName - the folder name to scan
public static java.util.List<java.lang.String> getCanonicalFilePathList(java.io.File[] fileList)
fileList - the file list from which to get the canonical path.
public static java.lang.String getCanonicalPathSilent(java.io.File currentFile)
currentFile - the file from which to get the canonical path
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||