Class FileUtil

java.lang.Object
org.apache.derby.iapi.services.io.FileUtil

public abstract class FileUtil extends Object
A set of public static methods for dealing with File objects.
  • Field Details

  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • removeDirectory

      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.
      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(File from, File to, byte[] buf)
    • copyDirectory

      public static boolean copyDirectory(StorageFactory storageFactory, StorageFile from, File to, byte[] buffer, String[] filter, boolean copySubDirs)
    • copyFile

      public static boolean copyFile(StorageFactory storageFactory, StorageFile from, File to)
    • 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

      public static boolean copyFile(WritableStorageFactory storageFactory, File from, StorageFile to)
    • 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

      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'.
    • limitAccessToOwner

      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 - assumed to be just created
      Throws:
      IOException - if an I/O error happens when trying to change the file permissions
    • limitAccessToOwnerViaFile

      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 - the file to limit access to
      Returns:
      true on success, or false if some of the permissions could not be changed
    • limitAccessToOwnerViaFileAttributeView

      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 - the file to limit access to
      Returns:
      true on success, or false if some of the permissions could not be changed
      Throws:
      IOException