Class FileUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancopyDirectory(StorageFactory storageFactory, StorageFile from, File to, byte[] buffer, String[] filter, boolean copySubDirs) static booleancopyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to) static booleancopyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buffer, String[] filter) static booleanstatic booleancopyFile(StorageFactory storageFactory, StorageFile from, File to) static booleancopyFile(StorageFactory storageFactory, StorageFile from, File to, byte[] buf) static booleancopyFile(WritableStorageFactory storageFactory, File from, StorageFile to) static booleancopyFile(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buf) static booleancopyFile(WritableStorageFactory storageFactory, StorageFile from, StorageFile to) static voidlimitAccessToOwner(File file) Use when creating new files.private static booleanLimit access to owner using methods in thejava.io.Fileclass.private static booleanLimit access to owner using ajava.nio.file.attribute.FileAttributeView.static booleanremoveDirectory(File directory) Remove a directory and all of its contents.static StringstripProtocolFromFileName(String originalName) Remove the leading 'file://' protocol from a filename which has been expressed as an URL.
-
Field Details
-
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
removeDirectory
Remove a directory and all of its contents. The results of executing File.delete() on a File object that represents a directory seems to be platform dependent. This method removes the directory and all of its contents.- Returns:
- true if the complete directory was removed, false if it could not be. If false is returned then some of the files in the directory may have been removed.
-
copyFile
-
copyDirectory
public static boolean copyDirectory(StorageFactory storageFactory, StorageFile from, File to, byte[] buffer, String[] filter, boolean copySubDirs) -
copyFile
-
copyFile
public static boolean copyFile(StorageFactory storageFactory, StorageFile from, File to, byte[] buf) -
copyDirectory
public static boolean copyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to) -
copyDirectory
public static boolean copyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buffer, String[] filter) -
copyFile
-
copyFile
public static boolean copyFile(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buf) -
copyFile
public static boolean copyFile(WritableStorageFactory storageFactory, StorageFile from, StorageFile to) -
stripProtocolFromFileName
Remove the leading 'file://' protocol from a filename which has been expressed as an URL. If the filename is not an URL, then nothing is done. Otherwise, an URL like 'file:///tmp/foo.txt' is transformed into the legal file name '/tmp/foo.txt'. -
limitAccessToOwner
Use when creating new files. If running on Unix, limit read and write permissions on
fileto owner ifderby.storage.useDefaultFilePermissions == false.If the property is not specified, we use restrictive permissions anyway iff running with the server server started from the command line.
On Unix, this is equivalent to running with umask 0077.
On Windows, with FAT/FAT32, we lose, since the fs does not support permissions, only a read-only flag.
On Windows, with NTFS with ACLs, we limit access also for Windows using the new
java.nio.file.attributepackage.When restricted file access is enabled (either explicitly or by default) errors are handled like this: When running on JDK 7 or higher, and the file system can be accessed either via a PosixFileAttributeView or via an AclFileAttributeView, any IOException reported when trying to restrict the permissions will also be thrown by this method. In all other cases, it will do its best to limit the permissions using the
java.io.Filemethods (setReadable(),setWritable(),setExecutable()), but it won't throw any exceptions if the permissions cannot be set that way.- Parameters:
file- assumed to be just created- Throws:
IOException- if an I/O error happens when trying to change the file permissions
-
limitAccessToOwnerViaFile
Limit access to owner using methods in thejava.io.Fileclass. Those methods are available on all Java versions from 6 and up, but they are not fully functional on all file systems.- Parameters:
file- the file to limit access to- Returns:
trueon success, orfalseif some of the permissions could not be changed
-
limitAccessToOwnerViaFileAttributeView
Limit access to owner using ajava.nio.file.attribute.FileAttributeView. Such views are only available on Java 7 and higher, and only on file systems that support changing file permissions. Currently, this is supported on POSIX file systems and file systems that maintain access control lists (ACLs).- Parameters:
file- the file to limit access to- Returns:
trueon success, orfalseif some of the permissions could not be changed- Throws:
IOException
-