Top Description Fields Constructors Methods
org.apache.derby.iapi.services.io

public abstract Class FileUtil

extends Object
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .OutputStream, org.apache.derby.io.StorageFactory, .WritableStorageFactory, .StorageFile, java.net.MalformedURLException, .URISyntaxException, .URI, .URL, java.nio.file.Files, .Path, java.nio.file.attribute.AclEntry, .AclEntryPermission, .AclEntryType, .AclFileAttributeView, .PosixFileAttributeView, .PosixFilePermission, java.util.Collections, .EnumSet, org.apache.derby.shared.common.reference.Property, org.apache.derby.iapi.services.property.PropertyUtil

A set of public static methods for dealing with File objects.

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean
copyDirectory(StorageFactory storageFactory, StorageFile from, File to, byte[] buffer, String[] filter, boolean copySubDirs)

public static boolean
public static boolean
copyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buffer, String[] filter)

public static boolean
copyFile(File from, File to, byte[] buf)

public static boolean
copyFile(StorageFactory storageFactory, StorageFile from, File to)

public static boolean
copyFile(StorageFactory storageFactory, StorageFile from, File to, byte[] buf)

public static boolean
copyFile(WritableStorageFactory storageFactory, File from, StorageFile to)

public static boolean
copyFile(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buf)

public static boolean
public static void
limitAccessToOwner(File
assumed to be just created
file
)

Use when creating new files.

private static boolean

Returns:

true on success, or false if some of the permissions could not be changed
limitAccessToOwnerViaFile
(File
the file to limit access to
file
)

Limit access to owner using methods in the java.io.File class.

private static boolean

Returns:

true on success, or false if some of the permissions could not be changed
limitAccessToOwnerViaFileAttributeView
(File
the file to limit access to
file
)

Limit access to owner using a java.nio.file.attribute.FileAttributeView.

public static boolean

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.
removeDirectory
(File
The directory to remove
directory
)

Remove a directory and all of its contents.

public static String

Returns:

the stripped url
stripProtocolFromFileName
(String
The original url
originalName
)

Remove the leading 'file://' protocol from a filename which has been expressed as an URL.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE

Constructor Detail

FileUtilback to summary
public FileUtil()

Method Detail

copyDirectoryback to summary
public static boolean copyDirectory(StorageFactory storageFactory, StorageFile from, File to, byte[] buffer, String[] filter, boolean copySubDirs)
copyDirectoryback to summary
public static boolean copyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to)
copyDirectoryback to summary
public static boolean copyDirectory(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buffer, String[] filter)
copyFileback to summary
public static boolean copyFile(File from, File to, byte[] buf)
copyFileback to summary
public static boolean copyFile(StorageFactory storageFactory, StorageFile from, File to)
copyFileback to summary
public static boolean copyFile(StorageFactory storageFactory, StorageFile from, File to, byte[] buf)
copyFileback to summary
public static boolean copyFile(WritableStorageFactory storageFactory, File from, StorageFile to)
copyFileback to summary
public static boolean copyFile(WritableStorageFactory storageFactory, File from, StorageFile to, byte[] buf)
copyFileback to summary
public static boolean copyFile(WritableStorageFactory storageFactory, StorageFile from, StorageFile to)
limitAccessToOwnerback to summary
public static void limitAccessToOwner(File file) throws IOException

Use when creating new files. If running on Unix, limit read and write permissions on file to owner if derby.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:File

assumed to be just created

Exceptions
IOException:
if an I/O error happens when trying to change the file permissions
limitAccessToOwnerViaFileback to summary
private static boolean limitAccessToOwnerViaFile(File file)

Limit access to owner using methods in the java.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:File

the file to limit access to

Returns:boolean

true on success, or false if some of the permissions could not be changed

limitAccessToOwnerViaFileAttributeViewback to summary
private static boolean limitAccessToOwnerViaFileAttributeView(File file) throws IOException

Limit access to owner using a java.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:File

the file to limit access to

Returns:boolean

true on success, or false if some of the permissions could not be changed

removeDirectoryback to summary
public static boolean removeDirectory(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.

Parameters
directory:File

The directory to remove

Returns:boolean

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.

stripProtocolFromFileNameback to summary
public static String stripProtocolFromFileName(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'.

Parameters
originalName:String

The original url

Returns:String

the stripped url