Package com.installshield.util
Class FileUtils
- java.lang.Object
-
- com.installshield.boot.CoreFileUtils
-
- com.installshield.util.FileUtils
-
public class FileUtils extends CoreFileUtils
This class provides the ability to create temporary files or directories in the Multi-Platform temporary directory, which is created when a wizard is started. Any temporary files or directories created through these methods are automatically cleaned up by the deleteTempFiles method, which is called when the wizard is exited.
-
-
Field Summary
-
Fields inherited from class com.installshield.boot.CoreFileUtils
systemLF
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addTempFileOwner(TempFileOwner owner)
In many cases, temporary files are used to read or write files.static void
clearTempFileOwners()
Removes all registered temp file owners.static boolean
compareBytes(byte[] b1, byte[] b2)
static boolean
compareFileNames(java.lang.String name1, java.lang.String name2)
Returns the result of comparing two file names, either case sensitively or case insensitively, depending on the target file system.static byte[]
decodeBytes(byte[] in)
static byte[]
decodeBytes(java.lang.String s)
static boolean
deleteDirectory(java.lang.String dirName)
static java.lang.String[]
deleteTempFiles()
This method deletes the files/directories in the temporary files list.static java.lang.String
formatSizeAsBytes(long bytes)
Formats the specified number of bytes as a human-readable string.static LockedFilesHandler
getLockedFilesHandler()
Returns the current locked files handler.static java.lang.String
getName(java.lang.String fileName)
static java.lang.String
getPartitionName(java.lang.String absolutePath, java.lang.String[] partitionNames)
Deprecated.Use FileService.getPartitionName(String, String[])static java.lang.String
getPartitionName(java.lang.String absolutePath, java.lang.String[] partitionNames, java.lang.String defaultPartition)
Deprecated.Use FileService.getPartitionName(String, String[], String)static java.lang.String
getUniversalTempDir()
static boolean
isFileUnicode(java.io.File file)
static void
main(java.lang.String[] args)
static byte[]
readFully(java.io.InputStream in)
static java.lang.String
readTextFromFile(java.lang.String fileName, java.lang.String encoding)
Returns a String representing the byte[] of the given fileName.static void
removeTempFileOwner(TempFileOwner owner)
This method allows a file "owner" to unregister itself.static java.lang.String
removeTerminalSeparator(java.lang.String path)
Removes all separators from the end of a path, if present.static void
setLockedFilesHandler(LockedFilesHandler handler)
Sets the locked files handler that is used for deleting temporary files that are locked.static java.util.Enumeration
tempFileOwners()
Returns the currently registered temp file owners.static java.util.Enumeration
tempFiles()
Returns an enumeration of String objects for each of the temporary files that are deleted by a call to deleteTempFiles.-
Methods inherited from class com.installshield.boot.CoreFileUtils
addTempFile, appendSeparator, appendSeparator, canonizePath, clearTempFile, clearTempFiles, close, close, comparePaths, copy, copy, copy, copy, createDirs, createFileName, createTempDir, createTempDirName, createTempFile, createTempFile, createTempFile, createTempFileName, deleteTempFile, getIsjeTempDir, getParent, getTempDir, getTempFiles, isAbsolute, isFileSystemCaseSensitive, normalizeFileName, normalizeFileName, resetCurrentTempDir
-
-
-
-
Method Detail
-
setLockedFilesHandler
public static void setLockedFilesHandler(LockedFilesHandler handler)
Sets the locked files handler that is used for deleting temporary files that are locked.
-
getLockedFilesHandler
public static LockedFilesHandler getLockedFilesHandler()
Returns the current locked files handler.
-
main
public static void main(java.lang.String[] args)
-
addTempFileOwner
public static void addTempFileOwner(TempFileOwner owner)
In many cases, temporary files are used to read or write files. In such cases, the file is locked by the reader or writer and, therefore, cannot be deleted. This method allows a file "owner" to register itself with the FileUtils class, and receive notification that the owned file needs to be deleted, and that the owner should immediately close any open readers or writers.
-
removeTempFileOwner
public static void removeTempFileOwner(TempFileOwner owner)
This method allows a file "owner" to unregister itself. This should occur if the owned file is closed.
-
tempFileOwners
public static java.util.Enumeration tempFileOwners()
Returns the currently registered temp file owners.
-
clearTempFileOwners
public static void clearTempFileOwners()
Removes all registered temp file owners.
-
decodeBytes
public static byte[] decodeBytes(byte[] in) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeBytes
public static byte[] decodeBytes(java.lang.String s) throws java.io.IOException
- Throws:
java.io.IOException
-
tempFiles
public static java.util.Enumeration tempFiles()
Returns an enumeration of String objects for each of the temporary files that are deleted by a call to deleteTempFiles. Each of the methods in this class registers its created temporary file(s), so unless clearTempFile, clearTempFiles, or deleteTempFile has been called, this enumeration contains all of the temporary files created by this class since the class was loaded. It also contains any other files that were added through a call to addTempFile.This is the set of files that are deleted from a call to deleteTempFiles.
-
deleteTempFiles
public static java.lang.String[] deleteTempFiles()
This method deletes the files/directories in the temporary files list. If there are any temp file owners registered, they are notified to close their files before deletion begins. Any files/directories that cannot be deleted are passed to the locked files handler for deletion. Successful execution of this method returns an empty array.
-
deleteDirectory
public static boolean deleteDirectory(java.lang.String dirName)
-
removeTerminalSeparator
public static java.lang.String removeTerminalSeparator(java.lang.String path)
Removes all separators from the end of a path, if present.- Parameters:
String
- path to remove separators from- Returns:
- String resulting string.
-
getPartitionName
public static java.lang.String getPartitionName(java.lang.String absolutePath, java.lang.String[] partitionNames)
Deprecated.Use FileService.getPartitionName(String, String[])Maps the specified path into a valid partition out of a list of partition names. If the specified path cannot be mapped into a valid partition, it returns the absolute path itself. For example, given the list of partitions:- /
- /tmp
- /home
- /proc
- Parameters:
absolutePath
- The path whose partition match is being queried.partitioNames
- The list of partition names to query for the path match.- Returns:
- Returns the string indicating the partition determined as the match for the given path.
-
getPartitionName
public static java.lang.String getPartitionName(java.lang.String absolutePath, java.lang.String[] partitionNames, java.lang.String defaultPartition)
Deprecated.Use FileService.getPartitionName(String, String[], String)Maps the specified path into a valid partition out of a list of partition names. If the specified path cannot be mapped into a valid partition, it returns the default partition name, if indicated, or the absolute path itself. For example, given the list of partitions:- /
- /tmp
- /home
- /proc
- Parameters:
absolutePath
- The path whose partition match is being queried.partitioNames
- The list of partition names to query for the path match.defaultPartition
- The partition name used when no partition match is found.- Returns:
- Returns the string indicating the partition determined as the match for the given path.
-
formatSizeAsBytes
public static java.lang.String formatSizeAsBytes(long bytes)
Formats the specified number of bytes as a human-readable string.- Parameters:
bytes
- The number of bytes to format.
-
getName
public static java.lang.String getName(java.lang.String fileName)
-
compareFileNames
public static boolean compareFileNames(java.lang.String name1, java.lang.String name2)
Returns the result of comparing two file names, either case sensitively or case insensitively, depending on the target file system.
-
compareBytes
public static boolean compareBytes(byte[] b1, byte[] b2)
-
readFully
public static byte[] readFully(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
isFileUnicode
public static boolean isFileUnicode(java.io.File file)
-
readTextFromFile
public static java.lang.String readTextFromFile(java.lang.String fileName, java.lang.String encoding)
Returns a String representing the byte[] of the given fileName.- Parameters:
fileName
- - file to read from.encoding
- - The encoding to use when creating the String. Passing in null uses system default.- Returns:
- - String of text from fileName
-
getUniversalTempDir
public static java.lang.String getUniversalTempDir()
-
-