- java.lang.Object
-
- org.hsqldb.lib.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileUtil.FileSync
-
Field Summary
Fields Modifier and Type Field Description booleanfsIsIgnoreCasebooleanfsNormalizesPosixSeparator-
Fields inherited from interface org.hsqldb.lib.FileAccess
ELEMENT_READ, ELEMENT_READWRITE, ELEMENT_SEEKABLEREAD, ELEMENT_TRUNCATE, ELEMENT_WRITE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringabsolutePath(java.lang.String path)Retrieves the absolute path, given some path specification.java.io.FilecanonicalFile(java.io.File f)Retrieves the canonical file for the given file, in a JDK 1.1 compliant way.java.io.FilecanonicalFile(java.lang.String path)Retrieves the canonical file for the given path, in a JDK 1.1 compliant way.java.lang.StringcanonicalOrAbsolutePath(java.lang.String path)Retrieves the canonical path for the given path, or the absolute path if attempting to retrieve the canonical path fails.java.lang.StringcanonicalPath(java.io.File f)Retrieves the canonical path for the given File, in a JDK 1.1 compliant way.java.lang.StringcanonicalPath(java.lang.String path)Retrieves the canonical path for the given path, in a JDK 1.1 compliant way.voidcreateParentDirs(java.lang.String filename)booleandelete(java.lang.String filename)Delete the named filevoiddeleteOnExit(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.static booleandeleteOrRenameDatabaseFiles(java.lang.String dbNamePath)Utility method for user applications.booleanexists(java.lang.String filename)Return true or false based on whether the named file exists.booleanexists(java.lang.String fileName, boolean resource, java.lang.Class cla)static java.io.File[]getDatabaseFileList(java.lang.String dbNamePath)Utility method for user applications.static java.io.File[]getDatabaseMainFileList(java.lang.String dbNamePath)Returns a list of existing main files for a database.static FileAccessgetFileAccess(boolean isResource)FileAccess.FileSyncgetFileSync(java.io.OutputStream os)static FileUtilgetFileUtil()booleanisStreamElement(java.lang.String elementName)static java.lang.StringmakeDirectories(java.lang.String path)voidmakeParentDirectories(java.io.File f)static java.lang.StringnewDiscardFileName(java.lang.String filename)java.io.InputStreamopenInputStreamElement(java.lang.String streamName)java.io.OutputStreamopenOutputStreamElement(java.lang.String streamName)java.io.OutputStreamopenOutputStreamElementAppend(java.lang.String streamName)booleanremoveElement(java.lang.String filename)booleanrenameElement(java.lang.String oldName, java.lang.String newName)booleanrenameElementOrCopy(java.lang.String oldName, java.lang.String newName, EventLogInterface logger)
-
-
-
Method Detail
-
getFileUtil
public static FileUtil getFileUtil()
-
getFileAccess
public static FileAccess getFileAccess(boolean isResource)
-
isStreamElement
public boolean isStreamElement(java.lang.String elementName)
- Specified by:
isStreamElementin interfaceFileAccess
-
openInputStreamElement
public java.io.InputStream openInputStreamElement(java.lang.String streamName) throws java.io.IOException- Specified by:
openInputStreamElementin interfaceFileAccess- Throws:
java.io.IOException
-
createParentDirs
public void createParentDirs(java.lang.String filename)
- Specified by:
createParentDirsin interfaceFileAccess
-
removeElement
public boolean removeElement(java.lang.String filename)
- Specified by:
removeElementin interfaceFileAccess
-
renameElement
public boolean renameElement(java.lang.String oldName, java.lang.String newName)- Specified by:
renameElementin interfaceFileAccess
-
renameElementOrCopy
public boolean renameElementOrCopy(java.lang.String oldName, java.lang.String newName, EventLogInterface logger)- Specified by:
renameElementOrCopyin interfaceFileAccess
-
openOutputStreamElement
public java.io.OutputStream openOutputStreamElement(java.lang.String streamName) throws java.io.IOException- Specified by:
openOutputStreamElementin interfaceFileAccess- Throws:
java.io.IOException
-
openOutputStreamElementAppend
public java.io.OutputStream openOutputStreamElementAppend(java.lang.String streamName) throws java.io.IOException- Specified by:
openOutputStreamElementAppendin interfaceFileAccess- 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.IOExceptionRetrieves 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.IOExceptionRetrieves 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.IOExceptionRetrieves 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.IOExceptionRetrieves 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)
-
getFileSync
public FileAccess.FileSync getFileSync(java.io.OutputStream os) throws java.io.IOException
- Specified by:
getFileSyncin interfaceFileAccess- Throws:
java.io.IOException
-
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)
-
-