Class FileUtil
- java.lang.Object
-
- org.apache.derby.iapi.services.io.FileUtil
-
public abstract class FileUtil extends java.lang.Object
A set of public static methods for dealing with File objects.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
copyDirectory(StorageFactory storageFactory, StorageFile from, java.io.File to, byte[] buffer, java.lang.String[] filter, boolean copySubDirs)
static boolean
copyDirectory(WritableStorageFactory storageFactory, java.io.File from, StorageFile to)
static boolean
copyDirectory(WritableStorageFactory storageFactory, java.io.File from, StorageFile to, byte[] buffer, java.lang.String[] filter)
static boolean
copyFile(java.io.File from, java.io.File to, byte[] buf)
static boolean
copyFile(StorageFactory storageFactory, StorageFile from, java.io.File to)
static boolean
copyFile(StorageFactory storageFactory, StorageFile from, java.io.File to, byte[] buf)
static boolean
copyFile(WritableStorageFactory storageFactory, java.io.File from, StorageFile to)
static boolean
copyFile(WritableStorageFactory storageFactory, java.io.File from, StorageFile to, byte[] buf)
static boolean
copyFile(WritableStorageFactory storageFactory, StorageFile from, StorageFile to)
static void
limitAccessToOwner(java.io.File file)
Use when creating new files.private static boolean
limitAccessToOwnerViaFile(java.io.File file)
Limit access to owner using methods in thejava.io.File
class.private static boolean
limitAccessToOwnerViaFileAttributeView(java.io.File file)
Limit access to owner using ajava.nio.file.attribute.FileAttributeView
.static boolean
removeDirectory(java.io.File directory)
Remove a directory and all of its contents.static java.lang.String
stripProtocolFromFileName(java.lang.String originalName)
Remove the leading 'file://' protocol from a filename which has been expressed as an URL.
-
-
-
Field Detail
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
removeDirectory
public static boolean removeDirectory(java.io.File directory)
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
public static boolean copyFile(java.io.File from, java.io.File to, byte[] buf)
-
copyDirectory
public static boolean copyDirectory(StorageFactory storageFactory, StorageFile from, java.io.File to, byte[] buffer, java.lang.String[] filter, boolean copySubDirs)
-
copyFile
public static boolean copyFile(StorageFactory storageFactory, StorageFile from, java.io.File to)
-
copyFile
public static boolean copyFile(StorageFactory storageFactory, StorageFile from, java.io.File to, byte[] buf)
-
copyDirectory
public static boolean copyDirectory(WritableStorageFactory storageFactory, java.io.File from, StorageFile to)
-
copyDirectory
public static boolean copyDirectory(WritableStorageFactory storageFactory, java.io.File from, StorageFile to, byte[] buffer, java.lang.String[] filter)
-
copyFile
public static boolean copyFile(WritableStorageFactory storageFactory, java.io.File from, StorageFile to)
-
copyFile
public static boolean copyFile(WritableStorageFactory storageFactory, java.io.File from, StorageFile to, byte[] buf)
-
copyFile
public static boolean copyFile(WritableStorageFactory storageFactory, StorageFile from, StorageFile to)
-
stripProtocolFromFileName
public static java.lang.String stripProtocolFromFileName(java.lang.String originalName)
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
public static void limitAccessToOwner(java.io.File file) throws java.io.IOException
Use when creating new files. If running on Unix, limit read and write permissions on
file
to 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.attribute
package.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.File
methods (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:
java.io.IOException
- if an I/O error happens when trying to change the file permissions
-
limitAccessToOwnerViaFile
private static boolean limitAccessToOwnerViaFile(java.io.File file)
Limit access to owner using methods in thejava.io.File
class. 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:
true
on success, orfalse
if some of the permissions could not be changed
-
limitAccessToOwnerViaFileAttributeView
private static boolean limitAccessToOwnerViaFileAttributeView(java.io.File file) throws java.io.IOException
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:
true
on success, orfalse
if some of the permissions could not be changed- Throws:
java.io.IOException
-
-