Module org.hsqldb

Class FileUtil

  • All Implemented Interfaces:
    FileAccess

    public class FileUtil
    extends java.lang.Object
    implements FileAccess
    A collection of file management methods.

    Also provides the default FileAccess implementation

    Since:
    1.7.2
    Author:
    Campbell Burnet (campbell-burnet@users dot sourceforge.net), Fred Toussi (fredt@users dot sourceforge.net), Ocke Janssen oj@openoffice.org
    • Field Detail

      • fsIsIgnoreCase

        public final boolean fsIsIgnoreCase
      • fsNormalizesPosixSeparator

        public final boolean fsNormalizesPosixSeparator
    • Method Detail

      • getFileUtil

        public static FileUtil getFileUtil()
      • getFileAccess

        public static FileAccess getFileAccess​(boolean isResource)
      • isStreamElement

        public boolean isStreamElement​(java.lang.String elementName)
        Specified by:
        isStreamElement in interface FileAccess
      • openInputStreamElement

        public java.io.InputStream openInputStreamElement​(java.lang.String streamName)
                                                   throws java.io.IOException
        Specified by:
        openInputStreamElement in interface FileAccess
        Throws:
        java.io.IOException
      • createParentDirs

        public void createParentDirs​(java.lang.String filename)
        Specified by:
        createParentDirs in interface FileAccess
      • removeElement

        public boolean removeElement​(java.lang.String filename)
        Specified by:
        removeElement in interface FileAccess
      • renameElement

        public boolean renameElement​(java.lang.String oldName,
                                     java.lang.String newName)
        Specified by:
        renameElement in interface FileAccess
      • openOutputStreamElement

        public java.io.OutputStream openOutputStreamElement​(java.lang.String streamName)
                                                     throws java.io.IOException
        Specified by:
        openOutputStreamElement in interface FileAccess
        Throws:
        java.io.IOException
      • openOutputStreamElementAppend

        public java.io.OutputStream openOutputStreamElementAppend​(java.lang.String streamName)
                                                           throws java.io.IOException
        Specified by:
        openOutputStreamElementAppend in interface FileAccess
        Throws:
        java.io.IOException
      • delete

        public boolean delete​(java.lang.String filename)
        Delete the named file
        Parameters:
        filename - String
        Returns:
        true if deleted
      • deleteOnExit

        public void deleteOnExit​(java.io.File f)
        Requests, in a JDK 1.1 compliant way, that the file or directory denoted by the given abstract pathname be deleted when the virtual machine terminates.

        Deletion will be attempted only for JDK 1.2 and greater runtime environments and only upon normal termination of the virtual machine, as defined by the Java Language Specification.

        Once deletion has been sucessfully requested, it is not possible to cancel the request. This method should therefore be used with care.

        Parameters:
        f - the abstract pathname of the file be deleted when the virtual machine terminates
      • exists

        public boolean exists​(java.lang.String filename)
        Return true or false based on whether the named file exists.
        Parameters:
        filename - String
        Returns:
        true if exists
      • exists

        public boolean exists​(java.lang.String fileName,
                              boolean resource,
                              java.lang.Class cla)
      • absolutePath

        public java.lang.String absolutePath​(java.lang.String path)
        Retrieves the absolute path, given some path specification.
        Parameters:
        path - the path for which to retrieve the absolute path
        Returns:
        the absolute path
      • canonicalFile

        public java.io.File canonicalFile​(java.io.File f)
                                   throws java.io.IOException
        Retrieves the canonical file for the given file, in a JDK 1.1 compliant way.
        Parameters:
        f - the File for which to retrieve the absolute File
        Returns:
        the canonical File
        Throws:
        java.io.IOException - on error
      • canonicalFile

        public java.io.File canonicalFile​(java.lang.String path)
                                   throws java.io.IOException
        Retrieves the canonical file for the given path, in a JDK 1.1 compliant way.
        Parameters:
        path - the path for which to retrieve the canonical File
        Returns:
        the canonical File
        Throws:
        java.io.IOException - on error
      • canonicalPath

        public java.lang.String canonicalPath​(java.io.File f)
                                       throws java.io.IOException
        Retrieves the canonical path for the given File, in a JDK 1.1 compliant way.
        Parameters:
        f - the File for which to retrieve the canonical path
        Returns:
        the canonical path
        Throws:
        java.io.IOException - on error
      • canonicalPath

        public java.lang.String canonicalPath​(java.lang.String path)
                                       throws java.io.IOException
        Retrieves the canonical path for the given path, in a JDK 1.1 compliant way.
        Parameters:
        path - the path for which to retrieve the canonical path
        Returns:
        the canonical path
        Throws:
        java.io.IOException - on error
      • canonicalOrAbsolutePath

        public java.lang.String canonicalOrAbsolutePath​(java.lang.String path)
        Retrieves the canonical path for the given path, or the absolute path if attempting to retrieve the canonical path fails.
        Parameters:
        path - the path for which to retrieve the canonical or absolute path
        Returns:
        the canonical or absolute path
      • makeParentDirectories

        public void makeParentDirectories​(java.io.File f)
      • makeDirectories

        public static java.lang.String makeDirectories​(java.lang.String path)
      • deleteOrRenameDatabaseFiles

        public static boolean deleteOrRenameDatabaseFiles​(java.lang.String dbNamePath)
        Utility method for user applications. Attempts to delete all the files for the database as listed by the getDatabaseFileList() method. If any of the current, main database files cannot be deleted, it is renamed by adding a suffix containing a hexadecimal timestamp portion and the ".old" extension. Also deletes the ".tmp" directory.
        Parameters:
        dbNamePath - full path or name of database (without a file extension)
        Returns:
        currently always true
      • getDatabaseFileList

        public static java.io.File[] getDatabaseFileList​(java.lang.String dbNamePath)
        Utility method for user applications. Returns a list of files that currently exist for a database. The list includes current database files as well as ".new", and ".old" versions of the files, plus any app logs.
        Parameters:
        dbNamePath - full path or name of database (without a file extension)
        Returns:
        File[]
      • getDatabaseMainFileList

        public static java.io.File[] getDatabaseMainFileList​(java.lang.String dbNamePath)
        Returns a list of existing main files for a database. The list excludes non-essential files.
        Parameters:
        dbNamePath - full path or name of database (without a file extension)
        Returns:
        File[]
      • newDiscardFileName

        public static java.lang.String newDiscardFileName​(java.lang.String filename)