de.schlichtherle.io
Class File

java.lang.Object
  extended by java.io.File
      extended by de.schlichtherle.io.File
All Implemented Interfaces:
Serializable, Comparable

public class File
extends File

A drop-in replacement for its subclass which provides transparent read/write access to archive files and their entries as if they were (virtual) directories and files.

Warning:The classes in this package access and manipulate archive files as external resources and may cache some of their state in memory and temporary files. Third parties must not concurrently access these archive files unless some precautions have been taken! For more information please refer to the section "Managing Archive File State" in the package summary.

Copy methods

This class provides a bunch of convenient copy methods which work much faster and more reliable than the usual read-write-in-a-loop approach for individual files and its recursive companion for directory trees. These copy methods fall into the following categories:

  1. The (archiveC|c)opy(All)?(To|From) methods (note the regular expression) simply return a boolean value indicating success or failure. Though this is suboptimal, this is consistent with most methods in the super class.
  2. The cp(_p)? methods return void and throw an IOException on failure. The exception hierarchy is fine grained enough to let a client application differentiate between access restrictions, input exceptions and output exceptions. The method names have been modelled after the Unix "cp -p" utility. None of these methods does recursive copying, however.
  3. The cat(To|From) methods return a boolean value. In contrast to the previous methods, they never close their argument streams, so you can call them multiple times on the same streams to concatenate data. Their name is modelled after the Unix command line utility "cat".
  4. Finally, the cat method is the core engine for all these methods. It performs the asynchronous data transfer from an input stream to an output stream. When used with properly crafted input and output stream implementations, it delivers the same performance as the transfer method in the package java.nio.
All copy methods use asynchronous I/O, pooled large buffers and pooled threads (if run on JSE 1.5) to achieve best performance.

Direct Data Copying (DDC)

If data is copied from an archive file to another archive file of the same type, some of the copy methods use a feature called Direct Data Copying (DDC) to achieve even better performance: DDC copies the raw data from the source archive entry to the destination archive entry without the need to temporarily reproduce, copy and process the original data again.

The benefits of this feature are archive driver specific: In case of ZIP compatible files with compressed entries, it avoids the need to decompress the data from the source entry just to compress it again for the destination entry. In case of TAR compatible files, it avoids the need to create an additional temporary file, but shows no impact otherwise - TAR doesn't support compression.

Identifying Archive Files and False Positives

Whenever an archive file suffix is recognized in a path, TrueZIP treats the corresponding file or directory as a prospective archive file. The word "prospective" suggests that just because a file is named archive.zip it isn't necessarily a valid ZIP file. In fact, it could be anything, even a regular directory!

Such an invalid archive file is called a false positive, which means a file, special file (a Unix concept) or directory which's path has a configured archive file suffix, but is actually something else. TrueZIP correctly identifies all kinds of false positives and treats them according to what they really are: Regular files, special files or directories.

The following table shows how certain methods in this class behave, depending upon a file's path and its true state in the file system:

Path True State isArchive()1 isDirectory() isFile() exists() length()2
archive.zip3 Valid ZIP file true true false true 0
archive.zip False positive: Regular directory true true false true ?
archive.zip False positive: Regular file true false true true ?
archive.zip False positive: Regular special file true false false true ?
archive.zip File or directory does not exist true false false false 0
 
archive.tzp4 Valid RAES encrypted ZIP file with valid key (e.g. password) true true false true 0
archive.tzp Valid RAES encrypted ZIP file with unknown key5 true false false true ?
archive.tzp False positive: Regular directory true true false true ?
archive.tzp False positive: Regular file true false true true ?
archive.tzp False positive: Regular special file true false false true ?
archive.tzp File or directory does not exist true false false false 0
 
other Regular directory false true false true ?
other Regular file false false true true ?
other Regular special file false false false true ?
other File or directory does not exist false false false false 0
  1. isArchive() doesn't check the true state of the file - it just looks at its path: If the path ends with a configured archive file suffix, isArchive() always returns true.
  2. length() always returns 0 if the path denotes a valid archive file. Otherwise, the return value of length() depends on the platform and file system, which is indicated by ?. For regular directories on Windows/NTFS for example, the return value would be 0.
  3. archive.zip is just an example: If TrueZIP is configured to recognize TAR.GZ files, the same behavior applies to archive.tar.gz.
  4. This assumes that .tzp is configured as an archive file suffix for RAES encrypted ZIP files. By default, this is not the case.
  5. The methods behave exactly the same for both archive.zip and archive.tzp with one exception: If the key for a RAES encrypted ZIP file remains unknown (e.g. because the user cancelled password prompting), then these methods behave as if the true state of the path were a special file: Both isDirectory() and isFile() return false, while exists() returns true.

Miscellaneous

  1. Since TrueZIP 6.4, this class is serializable in order to meet the requirements of its super class. However, it's not recommended to serialize File instances: Together with the instance, its archive detector and all associated archive drivers are serialized, too, which is pretty inefficient for a single instance. Serialization might even fail since it's not a general requirement for the interface implementations to be serializable - although the default implementations in TrueZIP 6.4 are all serializable. Instead of serializing File instances, a client application should serialize paths (which are simply String instances) and leave it up to the receiver to create a new File instance from it with archive files recognized by a suitable local archive detector - usually the default archive detector.

Version:
TrueZIP 6.7
Author:
Christian Schlichtherle
See Also:
API reference for configuring archive type recognition, Serialized Form

Field Summary
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
File(File template)
          Copy constructor.
File(File template, ArchiveDetector detector)
          Constructs a new File instance which may use the given ArchiveDetector to detect any archive files in its path.
File(File delegate, File innerArchive, ArchiveDetector detector)
          This constructor is not for public use - do not use it!
File(File template, File delegate, File enclArchive)
          This constructor is not for public use - do not use it!
File(File parent, String child)
          Equivalent to File(parent, child, null).
File(File parent, String child, ArchiveDetector detector)
          Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path and configure their parameters.
File(String path)
          Equivalent to File(path, getDefaultArchiveDetector()).
File(String path, ArchiveDetector detector)
          Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path.
File(String parent, String child)
          Equivalent to File(parent, child, getDefaultArchiveDetector()).
File(String parent, String child, ArchiveDetector detector)
          Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path.
File(URI uri)
          Constructs a new File instance from the given uri.
 
Method Summary
 boolean archiveCopyAllFrom(File src)
          Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyAllFrom(File src, ArchiveDetector detector)
          Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyAllFrom(File src, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyAllTo(File dst)
          Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyAllTo(File dst, ArchiveDetector detector)
          Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyAllTo(File dst, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyFrom(File src)
          Copies the file src to this file and tries to preserve all attributes of the source file to the destination file, too.
 boolean archiveCopyTo(File dst)
          Copies this file to the file dst and tries to preserve all attributes of the source file to the destination file, too.
 boolean canRead()
           
 boolean canWrite()
           
static void cat(InputStream in, OutputStream out)
          Copies all data from one stream to another without closing them.
 boolean catFrom(InputStream in)
          Copies the input stream in to this file or entry in an archive file without closing the input stream.
 boolean catTo(OutputStream out)
          Copies this file or entry in an archive file to the output stream out without closing it.
 int compareTo(File other)
          Compares this file's path to the given file's path.
 boolean contains(File file)
          Returns true if and only if the path represented by this instance contains the path represented by the specified file, where a path is said to contain another path if and only if it is equal or a parent of the other path.
static boolean contains(File a, File b)
          Returns true if and only if the path represented by a contains the path represented by b, where a path is said to contain another path if and only if it is equal or a parent of the other path.
 boolean copyAllFrom(File src)
          Recursively copies the file or directory src to this file or directory.
 boolean copyAllFrom(File src, ArchiveDetector detector)
          Recursively copies the file or directory src to this file or directory.
 boolean copyAllFrom(File src, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          Recursively copies the file or directory src to this file or directory.
 boolean copyAllTo(File dst)
          Recursively copies this file or directory to the file or directory dst.
 boolean copyAllTo(File dst, ArchiveDetector detector)
          Recursively copies this file or directory to the file or directory dst.
 boolean copyAllTo(File dst, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          Recursively copies this file or directory to the file or directory dst.
 boolean copyFrom(File src)
          Copies the file src to this file.
 boolean copyFrom(InputStream in)
          Copies the input stream in to this file and closes it.
 boolean copyTo(File dst)
          Copies this file to the file dst.
 boolean copyTo(OutputStream out)
          Copies this file to the output stream out and closes it.
static void cp_p(File src, File dst)
          Copies src to dst and tries to preserve all attributes of the source file to the destination file, too.
static void cp(File src, File dst)
          Copies src to dst.
static void cp(InputStream in, OutputStream out)
          Copies the input stream in to the output stream out.
 boolean createNewFile()
          Creates a new, empty file similar to its superclass implementation.
 boolean delete()
          Deletes an archive entry, archive file or regular node in the real file system.
 boolean deleteAll()
          Deletes the entire directory tree represented by this object, regardless whether this is a file or directory, whether the directory is empty or not or whether the file or directory is actually an archive file, an entry in an archive file or not enclosed in an archive file at all.
 void deleteOnExit()
           
 boolean equals(Object other)
          Tests this abstract path for equality with the given object.
 boolean exists()
          This file system operation is virtually atomic.
 File getAbsoluteFile()
          Behaves like the superclass implementation, but returns a new instance of this class, so you can safely cast it.
 String getAbsolutePath()
           
 ArchiveDetector getArchiveDetector()
          Returns the ArchiveDetector that was used to construct this object - never null.
 File getCanonicalFile()
          Behaves like the superclass implementation, but returns a new instance of this class, so you can safely cast it.
 String getCanonicalPath()
           
 File getCanOrAbsFile()
          This convenience method simply returns the canonical form of this abstract path or the normalized absolute form if resolving the prior fails.
 String getCanOrAbsPath()
          This convenience method simply returns the canonical form of this abstract path or the normalized absolute form if resolving the prior fails.
 Icon getClosedIcon()
          Returns an icon for this file or directory if it is in closed state for JFileTree or null if the default should be used.
static ArchiveDetector getDefaultArchiveDetector()
          Returns the default ArchiveDetector to be used if no archive detector is passed explicitly to the constructor of a File instance.
 File getDelegate()
          This method is not intended for public use!
 File getEnclArchive()
          Returns the enclosing archive file in this path.
 String getEnclEntryName()
          Returns the entry path in the enclosing archive file.
 File getInnerArchive()
          Returns the innermost archive file in this path.
 String getInnerEntryName()
          Returns the entry name in the innermost archive file.
static ArchiveStatistics getLiveArchiveStatistics()
          Returns a proxy instance which encapsulates live statistics about the total set of archives operated by this package.
 String getName()
           
 File getNonArchivedParentFile()
          Returns the first parent directory (starting from this file) which is not an archive file or a file located in an archive file.
 File getNormalizedAbsoluteFile()
          Similar to getAbsoluteFile(), but removes any ".
 String getNormalizedAbsolutePath()
          Similar to getAbsolutePath(), but removes any ".
 File getNormalizedFile()
          Removes any ".
 String getNormalizedPath()
          Removes any ".
 Icon getOpenIcon()
          Returns an icon for this file or directory if it is in open state for JFileTree or null if the default should be used.
 String getParent()
           
 File getParentFile()
          Behaves like the superclass implementation, but actually either returns null or a new instance of this class, so you can safely cast it.
 String getPath()
           
 File getTopLevelArchive()
          Returns The top level archive file in the path or null if this path does not denote an archive.
 int hashCode()
           
 boolean isAbsolute()
           
 boolean isArchive()
          Returns true if and only if the path represented by this instance denotes an archive file.
 boolean isDirectory()
          Similar to its super class implementation, but returns true for a valid archive file.
 boolean isEntry()
          Returns true if and only if the path represented by this instance names an archive file as an ancestor.
 boolean isFile()
          Similar to its super class implementation, but returns false for a valid archive file.
 boolean isFileSystemRoot()
          Returns true if and only if this file denotes a file system root or a UNC (if running on the Windows platform).
 boolean isHidden()
           
static boolean isLenient()
          Returns the value of the class property lenient.
 boolean isParentOf(File file)
          Returns true if and only if the path represented by this instance is a direct or indirect parent of the path represented by the specified file.
 boolean isUNC()
          Returns true if and only if this file denotes a UNC.
protected static boolean isUNC(String path)
          Deprecated. This method will be made private in the next major version.
 long lastModified()
          Returns a long value representing the time this file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs or if this is a ghost directory in an archive file.
 long length()
          Returns the (uncompressed) length of the file.
 String[] list()
          Returns the names of the members in this directory in a newly created array.
 String[] list(FilenameFilter filenameFilter)
          Returns the names of the members in this directory which are accepted by filenameFilter in a newly created array.
 File[] listFiles()
          Equivalent to listFiles((FilenameFilter) null, getArchiveDetector()).
 File[] listFiles(FileFactory factory)
          Returns File objects for the members in this directory in a newly created array.
 File[] listFiles(FileFilter fileFilter)
          Equivalent to listFiles(fileFilter, getArchiveDetector()).
 File[] listFiles(FileFilter fileFilter, FileFactory factory)
          Returns File objects for the members in this directory which are accepted by fileFilter in a newly created array.
 File[] listFiles(FilenameFilter filenameFilter)
          Equivalent to listFiles(filenameFilter, getArchiveDetector()).
 File[] listFiles(FilenameFilter filenameFilter, FileFactory factory)
          Returns File objects for the members in this directory which are accepted by filenameFilter in a newly created array.
 boolean mkdir()
          Creates a new, empty (virtual) directory similar to its superclass implementation.
 boolean mkdirs()
           
 boolean renameTo(File dst)
          Equivalent to renameTo(dst, getArchiveDetector()).
 boolean renameTo(File dst, ArchiveDetector detector)
          Behaves similar to the super class, but renames this file or directory by recursively copying its data if this object or the dst object is either an archive file or an entry located in an archive file.
static void setDefaultArchiveDetector(ArchiveDetector detector)
          This class property controls how archive files are recognized.
 boolean setLastModified(long time)
          Sets the last modification of this file or (virtual) directory.
static void setLenient(boolean lenient)
          This class property controls whether (1) archive files and enclosed directories shall be created on the fly if they don't exist and (2) open archive entry streams should automatically be closed if they are only weakly reachable.
 boolean setReadOnly()
          Like the super class implementation, but is aware of archive files in its path.
 String toString()
           
 URI toURI()
           
 URL toURL()
          Deprecated. This method has been deprecated in JSE 6.
static void umount()
          Equivalent to umount(false, true, false, true).
static void umount(boolean closeStreams)
          Equivalent to umount(false, closeStreams, false, closeStreams).
static void umount(boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams)
          Updates all archive files in the real file system with the contents of their virtual file system, resets all cached state and deletes all temporary files.
static void umount(File archive)
          Equivalent to umount(archive, false, true, false, true).
static void umount(File archive, boolean closeStreams)
          Equivalent to umount(archive, false, closeStreams, false, closeStreams).
static void umount(File archive, boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams)
          Similar to umount(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but will only update the given archive and all its enclosed (nested) archives.
static void update()
          Equivalent to update(false, true, false, true).
static void update(boolean closeStreams)
          Equivalent to update(false, closeStreams, false, closeStreams).
static void update(boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams)
          Like umount(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but may retain some temporary files in order to speed up subsequent access to their archive files again.
static void update(File archive)
          Equivalent to update(archive, false, true, false, true).
static void update(File archive, boolean closeStreams)
          Equivalent to update(archive, false, closeStreams, false, closeStreams).
static void update(File archive, boolean waitInputStreams, boolean closeInputStreams, boolean waitOutputStreams, boolean closeOutputStreams)
          Similar to update(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but will only update the given archive and all its enclosed (nested) archives.
 
Methods inherited from class java.io.File
canExecute, compareTo, createTempFile, createTempFile, getFreeSpace, getTotalSpace, getUsableSpace, listRoots, setExecutable, setExecutable, setReadable, setReadable, setWritable, setWritable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

File

public File(File template)
Copy constructor. Equivalent to File(template, getDefaultArchiveDetector()).


File

public File(File template,
            ArchiveDetector detector)
Constructs a new File instance which may use the given ArchiveDetector to detect any archive files in its path.

Parameters:
template - The file to use as a template. If this is an instance of this class, its fields are copied and the detector parameter is ignored.
detector - The object used to detect any archive files in the path. This parameter is ignored if template is an instance of this class. Otherwise, it must not be null.
Throws:
NullPointerException - If a required parameter is null.
See Also:
Third Party Access using different Archive Detectors

File

public File(String path)
Equivalent to File(path, getDefaultArchiveDetector()).


File

public File(String path,
            ArchiveDetector detector)
Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path.

Parameters:
path - The path of the file.
detector - The object used to detect any archive files in the path.
See Also:
Third Party Access using different Archive Detectors

File

public File(String parent,
            String child)
Equivalent to File(parent, child, getDefaultArchiveDetector()).


File

public File(String parent,
            String child,
            ArchiveDetector detector)
Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path.

Parameters:
parent - The parent path as a String.
detector - The object used to detect any archive files in the path.
child - The child path as a String.
See Also:
Third Party Access using different Archive Detectors

File

public File(File parent,
            String child)
Equivalent to File(parent, child, null).

Parameters:
parent - The parent directory as a File instance. If this parameter is an instance of this class, its ArchiveDetector is used to detect any archive files in the path of this File instance. Otherwise, the getDefaultArchiveDetector() is used. This is used in order to make this File instance behave as if it had been created by one of the listFiles() methods called on parent instead.
child - The child path as a String.

File

public File(File parent,
            String child,
            ArchiveDetector detector)
Constructs a new File instance which uses the given ArchiveDetector to detect any archive files in its path and configure their parameters.

Parameters:
parent - The parent directory as a File instance.
child - The child path as a String.
detector - The object used to detect any archive files in the path. If this is null and parent is an instance of this class, the archive detector is inherited from this instance. If this is null and parent is not an instance of this class, the archive detector returned by getDefaultArchiveDetector() is used.
Throws:
NullPointerException - If child is null.
See Also:
Third Party Access using different Archive Detectors

File

public File(URI uri)
Constructs a new File instance from the given uri. This method behaves similar to new java.io.File(uri) with the following amendment: If the URI matches the pattern (jar:)*file:(path!/)*entry, then the constructed file object treats the URI like a (possibly ZIPped) file.

For example, in a Java application which is running from a JAR in the local file system you could use this constructor to arbitrarily access (and modify) all entries in the JAR file from which the application is currently running by using the following simple method:

 public File getResourceAsFile(String resource) {
   URL url = getClass().getResource(resource);
   try {
     return new File(new URI(url.toExternalForm()));
   } catch (Exception notAJaredFileURI) {
     return null;
   }
 }
 
The newly created File instance uses ArchiveDetector.ALL as its ArchiveDetector.

Parameters:
uri - an absolute, hierarchical URI with a scheme equal to file or jar, a non-empty path component, and undefined authority, query, and fragment components.
Throws:
NullPointerException - if uri is null.
IllegalArgumentException - if the preconditions on the parameter uri do not hold.

File

public File(File delegate,
            File innerArchive,
            ArchiveDetector detector)
This constructor is not for public use - do not use it!

See Also:
FileFactory

File

public File(File template,
            File delegate,
            File enclArchive)
This constructor is not for public use - do not use it!

See Also:
FileFactory
Method Detail

umount

public static final void umount()
                         throws ArchiveException
Equivalent to umount(false, true, false, true).

Throws:
ArchiveException

umount

public static final void umount(boolean closeStreams)
                         throws ArchiveException
Equivalent to umount(false, closeStreams, false, closeStreams).

Throws:
ArchiveException

umount

public static final void umount(boolean waitInputStreams,
                                boolean closeInputStreams,
                                boolean waitOutputStreams,
                                boolean closeOutputStreams)
                         throws ArchiveException
Updates all archive files in the real file system with the contents of their virtual file system, resets all cached state and deletes all temporary files. This method is thread safe.

For a detailed explanation of when and how to use this method, please refer to the section "Managing Archive File State" in the package summary.

Parameters:
waitInputStreams - Suppose any other thread has still one or more archive entry input streams open. Then if and only if this parameter is true, this method will wait until all other threads have closed their archive entry input streams. Archive entry input streams opened (and not yet closed) by the current thread are always ignored. If the current thread gets interrupted while waiting, it will stop waiting and proceed normally as if this parameter were false. Be careful with this parameter value: If a stream has not been closed because the client application does not always properly close its streams, even on an IOException (which is a typical bug in many Java applications), then this method may not return until the current thread gets interrupted!
closeInputStreams - Suppose there are any open input streams for any archive entries because the application has forgot to close all FileInputStream objects or another thread is still busy doing I/O on an archive. Then if this parameter is true, an update is forced and an ArchiveBusyWarningException is finally thrown to indicate that any subsequent operations on these streams will fail with an ArchiveEntryStreamClosedException because they have been forced to close. This may also be used to recover an application from a FileBusyException thrown by a constructor of FileInputStream or FileOutputStream. If this parameter is false, the respective archive file is not updated and an ArchiveBusyException is thrown to indicate that the application must close all entry input streams first.
waitOutputStreams - Similar to waitInputStreams, but applies to archive entry output streams instead.
closeOutputStreams - Similar to closeInputStreams, but applies to archive entry output streams instead. If this parameter is true, then closeInputStreams must be true, too. Otherwise, an IllegalArgumentException is thrown.
Throws:
ArchiveBusyWarningExcepion - If an archive file has been updated while the application is using any open streams to access it concurrently. These streams have been forced to close and the entries of output streams may contain only partial data.
ArchiveWarningException - If only warning conditions occur throughout the course of this method which imply that the respective archive file has been updated with constraints, such as a failure to set the last modification time of the archive file to the last modification time of its implicit root directory.
ArchiveBusyException - If an archive file could not get updated because the application is using an open stream. No data is lost and the archive file can still get updated by calling this method again.
ArchiveException - If any error conditions occur throughout the course of this method which imply loss of data. This usually means that at least one of the archive files has been created externally and was corrupted or it cannot get updated because the file system of the temp file or target file folder is full.
IllegalArgumentException - If closeInputStreams is false and closeOutputStreams is true.
See Also:
update(File), update(), umount(File), Managing Archive File State

umount

public static final void umount(File archive)
                         throws ArchiveException
Equivalent to umount(archive, false, true, false, true).

Throws:
ArchiveException

umount

public static final void umount(File archive,
                                boolean closeStreams)
                         throws ArchiveException
Equivalent to umount(archive, false, closeStreams, false, closeStreams).

Throws:
ArchiveException

umount

public static final void umount(File archive,
                                boolean waitInputStreams,
                                boolean closeInputStreams,
                                boolean waitOutputStreams,
                                boolean closeOutputStreams)
                         throws ArchiveException
Similar to umount(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but will only update the given archive and all its enclosed (nested) archives.

If a client application needs to unmount an individual archive file, the following idiom can be used:

if (file.isArchive() && file.getEnclArchive() == null) // filter top level archive
if (file.isDirectory()) // ignore false positives
File.umount(File); // update archive and all enclosed archives
Again, this will also unmount all archive files which are located within the archive file referred to by the file instance.

Parameters:
archive - A top level archive file.
Throws:
NullPointerException - If archive is null.
IllegalArgumentException - If archive is not an archive or is enclosed in another archive (is not top level).
ArchiveException
See Also:
update(), update(File), umount(), Managing Archive File State

update

public static final void update()
                         throws ArchiveException
Equivalent to update(false, true, false, true).

Throws:
ArchiveException

update

public static final void update(boolean closeStreams)
                         throws ArchiveException
Equivalent to update(false, closeStreams, false, closeStreams).

Throws:
ArchiveException

update

public static final void update(boolean waitInputStreams,
                                boolean closeInputStreams,
                                boolean waitOutputStreams,
                                boolean closeOutputStreams)
                         throws ArchiveException
Like umount(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but may retain some temporary files in order to speed up subsequent access to their archive files again.

Warning: Do not use this method unless you fully understand its implications. In particular, if the client application does not seem to recognize changes made to archive files by third parties, replace the calls to this method with umount(*).

Throws:
ArchiveException
See Also:
update(), umount(), umount(boolean, boolean, boolean, boolean), Managing Archive File State

update

public static final void update(File archive)
                         throws ArchiveException
Equivalent to update(archive, false, true, false, true).

Throws:
ArchiveException

update

public static final void update(File archive,
                                boolean closeStreams)
                         throws ArchiveException
Equivalent to update(archive, false, closeStreams, false, closeStreams).

Throws:
ArchiveException

update

public static final void update(File archive,
                                boolean waitInputStreams,
                                boolean closeInputStreams,
                                boolean waitOutputStreams,
                                boolean closeOutputStreams)
                         throws ArchiveException
Similar to update(waitInputStreams, closeInputStreams, waitOutputStreams, closeOutputStreams), but will only update the given archive and all its enclosed (nested) archives.

Parameters:
archive - A top level archive file.
Throws:
NullPointerException - If archive is null.
IllegalArgumentException - If archive is not an archive or is enclosed in another archive (is not top level).
ArchiveException
See Also:
update(), umount(), umount(File), Managing Archive File State

getLiveArchiveStatistics

public static final ArchiveStatistics getLiveArchiveStatistics()
Returns a proxy instance which encapsulates live statistics about the total set of archives operated by this package. Any call to a method of the returned instance returns an element of the statistics which is lively updated, so there is no need to repeatedly call this method in order to get updated statistics.

Note that this method returns live statistics rather than real time statistics. So there may be a slight delay until the values returned reflect the actual state of this package. This delay increases if the system is under heavy load.

See Also:
ArchiveStatistics

isLenient

public static final boolean isLenient()
Returns the value of the class property lenient. By default, this is the inverse of the boolean system property de.schlichtherle.io.strict. In other words, this returns true unless you set the system property de.schlichtherle.io.strict to true or call setLenient(false).

See Also:
setLenient(boolean)

setLenient

public static final void setLenient(boolean lenient)
This class property controls whether (1) archive files and enclosed directories shall be created on the fly if they don't exist and (2) open archive entry streams should automatically be closed if they are only weakly reachable. By default, this class property is true.
  1. Consider the following path: "a/outer.zip/b/inner.zip/c". Now let's assume that "a" exists as a directory in the real file system, while all other parts of this path don't, and that TrueZIP's default configuration is used which would recognize "outer.zip" and "inner.zip" as ZIP files.

    If this class property is set to false, then the client application would have to call new File("a/outer.zip/b/inner.zip").mkdirs() before it could actually create the innermost "c" entry as a file or directory.

    More formally, before you can access a node in the virtual file system, all its parent directories must exist, including archive files. This emulates the behaviour of real file systems.

    If this class property is set to true however, then any missing parent directories (including archive files) up to the outermost archive file ("outer.zip") are created on the fly when using operations to create the innermost element of the path ("c").

    This allows applications to succeed when doing this: new File("a/outer.zip/b/inner.zip/c").createNewFile(), or that: new FileOutputStream("a/outer.zip/b/inner.zip/c").

    Note that in any case the parent directory of the outermost archive file ("a"), must exist - TrueZIP does not create regular directories in the real file system on the fly.

  2. Many Java applications unfortunately fail to close their streams in all cases, in particular if an IOException occured while accessing it. However, open streams are a limited resource in any operating system and may interfere with other services of the OS (on Windows, you can't delete an open file). This is called the "unclosed streams issue".

    Likewise, in TrueZIP an unclosed archive entry stream may result in an ArchiveBusy(Warning)?Exception to be thrown when umount() or update() is called. In order to prevent this, TrueZIP's archive entry streams have a Object.finalize() method which closes an archive entry stream if its garbage collected.

    Now if this class property is set to false, then TrueZIP maintains a hard reference to all archive entry streams until umount() or update() is called, which will deal with them: If they are not closed, an ArchiveBusy(Warning)?Exception is thrown, depending on the boolean parameters to these methods.

    This setting is useful if you do not want to tolerate the "unclosed streams issue" in a client application.

    If this class property is set to true however, then TrueZIP maintains only a weak reference to all archive entry streams. This allows the garbage collector to finalize them before umount() or update() is called. The finalize() method will then close these archive entry streams, which exempts them, from triggering an ArchiveBusy(Warning)?Exception on the next call to umount() or update(). However, closing an archive entry output stream this way may result in loss of buffered data, so it's only a workaround for this issue.

    Note that for the setting of this class property to take effect, any change must be made before an archive is first accessed. The setting will then persist until the archive is reset by the next call to umount() or update().

    Historical note: Since TrueZIP 6.0 and before TrueZIP 6.4, archive entry streams were always only referenced by a weak reference by TrueZIP. This class property has been overloaded with this semantic in order to allow client applications to test for the "unclosed streams issue".

See Also:
createNewFile(), FileInputStream, FileOutputStream

getDefaultArchiveDetector

public static final ArchiveDetector getDefaultArchiveDetector()
Returns the default ArchiveDetector to be used if no archive detector is passed explicitly to the constructor of a File instance.

This class property is initially set to ArchiveDetector.DEFAULT

See Also:
ArchiveDetector, setDefaultArchiveDetector(de.schlichtherle.io.ArchiveDetector)

setDefaultArchiveDetector

public static final void setDefaultArchiveDetector(ArchiveDetector detector)
This class property controls how archive files are recognized. When a new File instance is created and no ArchiveDetector is provided to the constructor, or when some method of this class are called which accept an ArchiveDetector parameter, then this class property is used. Changing this value affects all newly created File instances, but not any existing ones.

Parameters:
detector - The default ArchiveDetector to use for newly created File instances which have not been constructed with an explicit ArchiveDetector parameter
Throws:
NullPointerException - If detector is null.
See Also:
ArchiveDetector, getDefaultArchiveDetector(), Third Party Access using different Archive Detectors

getParentFile

public File getParentFile()
Behaves like the superclass implementation, but actually either returns null or a new instance of this class, so you can safely cast it.

Overrides:
getParentFile in class File

getNonArchivedParentFile

public File getNonArchivedParentFile()
Returns the first parent directory (starting from this file) which is not an archive file or a file located in an archive file.


getAbsoluteFile

public File getAbsoluteFile()
Behaves like the superclass implementation, but returns a new instance of this class, so you can safely cast it.

Overrides:
getAbsoluteFile in class File

getNormalizedAbsoluteFile

public File getNormalizedAbsoluteFile()
Similar to getAbsoluteFile(), but removes any "." and ".." directories from the path wherever possible. The result is similar to getCanonicalFile(), but symbolic links are not resolved. This may be useful if getCanonicalFile() throws an IOException.

Since:
TrueZIP 6.0
See Also:
getCanonicalFile(), getNormalizedFile()

getNormalizedAbsolutePath

public String getNormalizedAbsolutePath()
Similar to getAbsolutePath(), but removes any "." and ".." directories from the path wherever possible. The result is similar to getCanonicalPath(), but symbolic links are not resolved. This may be useful if getCanonicalPath() throws an IOException.

Since:
TrueZIP 6.0
See Also:
getCanonicalPath(), getNormalizedPath()

getNormalizedFile

public File getNormalizedFile()
Removes any "." and ".." directories from the path wherever possible.

Returns:
If this file is already normalized, it is returned. Otherwise a new instance of this class is returned.

getNormalizedPath

public String getNormalizedPath()
Removes any ".", ".." and empty directories from the path wherever possible.

Returns:
The normalized path of this file as a String.
Since:
TrueZIP 6.0

getCanonicalFile

public File getCanonicalFile()
                      throws IOException
Behaves like the superclass implementation, but returns a new instance of this class, so you can safely cast it.

Overrides:
getCanonicalFile in class File
Throws:
IOException

getCanOrAbsFile

public final File getCanOrAbsFile()
This convenience method simply returns the canonical form of this abstract path or the normalized absolute form if resolving the prior fails.

Returns:
The canonical or absolute path of this file as an instance of this class.

getCanOrAbsPath

public String getCanOrAbsPath()
This convenience method simply returns the canonical form of this abstract path or the normalized absolute form if resolving the prior fails.

Returns:
The canonical or absolute path of this file as a String instance.
Since:
TrueZIP 6.0

isArchive

public final boolean isArchive()
Returns true if and only if the path represented by this instance denotes an archive file. Whether or not this is true solely depends on the ArchiveDetector which was used to construct this File instance: If no ArchiveDetector is explicitly passed to the constructor, getDefaultArchiveDetector() is used.

Please note that no file system tests are performed! If a client application needs to know whether this file really exists as an archive file in the file system (and the correct password has been entered in case it's a RAES encrypted ZIP file), it should subsequently call isDirectory(), too. This will automount the virtual file system from the archive file and return true if and only if it's a valid archive file.

See Also:
Identifying Archive Files and False Positives, isDirectory(), isEntry()

isEntry

public final boolean isEntry()
Returns true if and only if the path represented by this instance names an archive file as an ancestor.

Whether or not this is true depends solely on the ArchiveDetector used to construct this instance. If no ArchiveDetector was explicitly passed to the constructor, getDefaultArchiveDetector() is used.

Please note that no tests on the file's true state are performed! If you need to know whether this file is really an entry in an archive file (and the correct password has been entered in case it's a RAES encrypted ZIP file), you should call getParentFile().isDirectory(), too. This will automount the virtual file system from the archive file and return true if and only if it's a valid archive file.

See Also:
isArchive()

getInnerArchive

public final File getInnerArchive()
Returns the innermost archive file in this path. I.e. if this object is an archive file, then this method returns this object. If this object is a file or directory located within a archive file, then this methods returns the file representing the enclosing archive file, or null otherwise.

This method always returns an undotified path, i.e. all occurences of "." and ".." in the path are removed according to their meaning wherever possible.

In order to support unlimited nesting levels, this method returns a File instance which again could be an entry within another archive file.


getInnerEntryName

public final String getInnerEntryName()
Returns the entry name in the innermost archive file. I.e. if this object is a archive file, then this method returns the empty string "". If this object is a file or directory located within an archive file, then this method returns the relative path of the entry in the enclosing archive file separated by the entry separator character '/', or null otherwise.

This method always returns an undotified path, i.e. all occurences of "." and ".." in the path are removed according to their meaning wherever possible.


getEnclArchive

public final File getEnclArchive()
Returns the enclosing archive file in this path. I.e. if this object is an entry located within an archive file, then this method returns the file representing the enclosing archive file, or null otherwise.

This method always returns an undotified path, i.e. all occurences of "." and ".." in the path are removed according to their meaning wherever possible.

In order to support unlimited nesting levels, this method returns a File instance which again could be an entry within another archive file.


getEnclEntryName

public final String getEnclEntryName()
Returns the entry path in the enclosing archive file. I.e. if this object is an entry located within a archive file, then this method returns the relative path of the entry in the enclosing archive file separated by the entry separator character '/', or null otherwise.

This method always returns an undotified path, i.e. all occurences of "." and ".." in the path are removed according to their meaning wherever possible.


getArchiveDetector

public final ArchiveDetector getArchiveDetector()
Returns the ArchiveDetector that was used to construct this object - never null.


getDelegate

public final File getDelegate()
This method is not intended for public use! Returns the legacy java.io.File object to which some methods of this class delegate if this object does not represent an archive file or an entry in an archive file. This is required to support the stacking of file system implementations. For example, javax.swing.JFileChooser creates instances of sun.awt.shell.ShellFolder, which is a subclass of java.io.File, too. These instances are wrapped as the delegate in instances of this class when using de.schlichtherle.swing.JFileChooser in order to stack the functionality of these different file system implementations.

In case you want to convert an instance of this class which recognized the leaf of its path as an archive file to a file instance which doesn't recognize this archive file, use the following code instead: ArchiveDetector.NULL.createFile((File) file.getParentFile(), file.getName())

Returns:
An instance of the java.io.File class or one of its subclasses, but never an instance of this class or its subclasses and never null.

isParentOf

public boolean isParentOf(File file)
Returns true if and only if the path represented by this instance is a direct or indirect parent of the path represented by the specified file.

Note:

Parameters:
file - The path to test for being a child of this path.
Throws:
NullPointerException - If the parameter is null.

contains

public boolean contains(File file)
Returns true if and only if the path represented by this instance contains the path represented by the specified file, where a path is said to contain another path if and only if it is equal or a parent of the other path.

Note:

Parameters:
file - The path to test for being contained by this path.
Throws:
NullPointerException - If the parameter is null.
Since:
TrueZIP 5.1

contains

public static final boolean contains(File a,
                                     File b)
Returns true if and only if the path represented by a contains the path represented by b, where a path is said to contain another path if and only if it is equal or a parent of the other path.

Note:

Parameters:
a - The path to test for containing b.
b - The path to test for being contained by a.
Throws:
NullPointerException - If any parameter is null.
Since:
TrueZIP 5.1

isFileSystemRoot

public boolean isFileSystemRoot()
Returns true if and only if this file denotes a file system root or a UNC (if running on the Windows platform).


isUNC

public boolean isUNC()
Returns true if and only if this file denotes a UNC. Note that this may be only relevant on the Windows platform.


isUNC

protected static final boolean isUNC(String path)
Deprecated. This method will be made private in the next major version.

Returns true if and only if the given path is a UNC. Note that this may be only relevant on the Windows platform.


hashCode

public int hashCode()
Overrides:
hashCode in class File

equals

public boolean equals(Object other)
Tests this abstract path for equality with the given object. Returns true if and only if the argument is not null and is an abstract path that denotes the same abstract path for a file or directory as this abstract path.

If the given file is not an instance of this class, the call is forwarded to the superclass in order to ensure the required symmetry of Object.equals(Object).

Otherwise, whether or not two abstract paths are equal depends upon the underlying operating and file system: On UNIX systems, alphabetic case is significant in comparing paths. On Microsoft Windows systems it is not unless the path denotes an entry in an archive file. In the latter case, the left part of the path up to the (leftmost) archive file is compared ignoring case while the remainder (the entry name) is compared considering case. This case distinction allows an application on Windows to deal with archive files generated on other platforms which may contain different entry with names that just differ in case (like e.g. hello.txt and HELLO.txt).

Thus, on Windows the following assertions all succeed:

 File a, b;
 a = new File("c:\\any.txt");
 b = new File("C:\\ANY.TXT");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("c:\\any.zip\\test.txt"),
 b = new File("C:\\ANY.ZIP\\test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("c:/any.zip/test.txt");
 b = new File("C:\\ANY.ZIP\\test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("c:\\any.zip\\test.txt");
 b = new File("C:/ANY.ZIP/test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("c:/any.zip/test.txt");
 b = new File("C:/ANY.ZIP/test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("\\\\localhost\\any.zip\\test.txt");
 b = new File("\\\\LOCALHOST\\ANY.ZIP\\test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("//localhost/any.zip/test.txt");
 b = new File("\\\\LOCALHOST\\ANY.ZIP\\test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("\\\\localhost\\any.zip\\test.txt");
 b = new File("//LOCALHOST/ANY.ZIP/test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("//localhost/any.zip/test.txt");
 b = new File("//LOCALHOST/ANY.ZIP/test.txt");
 assert a.equals(b);
 assert b.equals(a);
 a = new File("c:\\any.zip\\test.txt");
 b = new File("c:\\any.zip\\TEST.TXT");
 assert !a.equals(b); // two different entries in same ZIP file!
 assert !b.equals(a);
 

Overrides:
equals in class File
Parameters:
other - The object to be compared with this abstract path.
Returns:
true if and only if the objects are equal, false otherwise
See Also:
File.compareTo(Object), Object.equals(Object)

compareTo

public int compareTo(File other)
Compares this file's path to the given file's path.

If the given file is not an instance of this class, the call is forwarded to the superclass in order to ensure the required symmetry of Comparable.compareTo(Object).

Otherwise, whether or not two abstract paths compare equal depends upon the underlying operating and file system: On UNIX platforms, alphabetic case is significant in comparing paths. On the Windows platform it is not unless the path denotes an entry in an archive file. In the latter case, the left part of the path up to the (leftmost) archive file is compared in platform dependent manner (hence ignoring case) while the remainder (the entry name) is compared considering case. This case distinction allows an application on the Windows platform to deal with archive files generated on other platforms which may contain different entries with names that just differ in case (like e.g. "hello.txt" and "HELLO.txt").

Overrides:
compareTo in class File
Parameters:
other - The file to be compared with this abstract path.
Returns:
A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the given file.
See Also:
equals(Object), Comparable.compareTo(Object)

getTopLevelArchive

public File getTopLevelArchive()
Returns The top level archive file in the path or null if this path does not denote an archive. A top level archive is not enclosed in another archive. If this does not return null, this denotes the longest part of the path which actually may (but does not need to) exist as a regular file in the real file system.


getAbsolutePath

public String getAbsolutePath()
Overrides:
getAbsolutePath in class File

getCanonicalPath

public String getCanonicalPath()
                        throws IOException
Overrides:
getCanonicalPath in class File
Throws:
IOException

getName

public String getName()
Overrides:
getName in class File

getParent

public String getParent()
Overrides:
getParent in class File

getPath

public String getPath()
Overrides:
getPath in class File

isAbsolute

public boolean isAbsolute()
Overrides:
isAbsolute in class File

isHidden

public boolean isHidden()
Overrides:
isHidden in class File

toString

public String toString()
Overrides:
toString in class File

toURI

public URI toURI()
Overrides:
toURI in class File

toURL

public URL toURL()
          throws MalformedURLException
Deprecated. This method has been deprecated in JSE 6.

Overrides:
toURL in class File
Throws:
MalformedURLException
See Also:
File.toURL()

exists

public boolean exists()
This file system operation is virtually atomic.

Overrides:
exists in class File
See Also:
Identifying Archive Files and False Positives

isFile

public boolean isFile()
Similar to its super class implementation, but returns false for a valid archive file.

This file system operation is virtually atomic.

Overrides:
isFile in class File
See Also:
Identifying Archive Files and False Positives

isDirectory

public boolean isDirectory()
Similar to its super class implementation, but returns true for a valid archive file.

In case a RAES encrypted ZIP file is tested which is accessed for the first time, the user is prompted for the password (if password based encryption is used). Note that this is not the only method which would prompt the user for a password: For example, length() would prompt the user and return 0 unless the user cancels the prompting or the file is a false positive archive file.

This file system operation is virtually atomic.

Overrides:
isDirectory in class File
See Also:
Identifying Archive Files and False Positives

getOpenIcon

public Icon getOpenIcon()
Returns an icon for this file or directory if it is in open state for JFileTree or null if the default should be used.


getClosedIcon

public Icon getClosedIcon()
Returns an icon for this file or directory if it is in closed state for JFileTree or null if the default should be used.


canRead

public boolean canRead()
Overrides:
canRead in class File

canWrite

public boolean canWrite()
Overrides:
canWrite in class File

setReadOnly

public boolean setReadOnly()
Like the super class implementation, but is aware of archive files in its path. For entries in a archive file, this is effectively a no-op: The method will only return true if the entry exists and the archive file was mounted read only.

This file system operation is virtually atomic.

Overrides:
setReadOnly in class File

length

public long length()
Returns the (uncompressed) length of the file. The length returned of a valid archive file is 0 in order to correctly emulate virtual directories across all platforms.

In case a RAES encrypted ZIP file is tested which is accessed for the first time, the user is prompted for the password (if password based encryption is used). Note that this is not the only method which would prompt the user for a password: For example, isDirectory() would prompt the user and return true unless the user cancels the prompting or the file is a false positive archive file.

This file system operation is virtually atomic.

Overrides:
length in class File
See Also:
Identifying Archive Files and False Positives

lastModified

public long lastModified()
Returns a long value representing the time this file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs or if this is a ghost directory in an archive file.

This file system operation is virtually atomic.

Overrides:
lastModified in class File
See Also:
Package description for more information about ghost directories

setLastModified

public boolean setLastModified(long time)
Sets the last modification of this file or (virtual) directory. If this is a ghost directory within an archive file, it's reincarnated as a regular directory within the archive file.

Note that calling this method may incur a severe performance penalty if the file is an entry in an archive file which has just been written (such as after a normal copy operation). If you want to copy a file's contents as well as its last modification time, use archiveCopyFrom(java.io.File) or archiveCopyTo(java.io.File) instead.

This file system operation is virtually atomic.

Overrides:
setLastModified in class File
See Also:
archiveCopyFrom(java.io.File), archiveCopyTo(java.io.File), Package description for more information about ghost directories

list

public String[] list()
Returns the names of the members in this directory in a newly created array. The returned array is not sorted. This is the most efficient list method.

Note: Archive entries with absolute paths are ignored by this method and are never returned.

This file system operation is virtually atomic.

Overrides:
list in class File

list

public String[] list(FilenameFilter filenameFilter)
Returns the names of the members in this directory which are accepted by filenameFilter in a newly created array. The returned array is not sorted.

Note: Archive entries with absolute paths are ignored by this method and are never returned.

This file system operation is virtually atomic.

Overrides:
list in class File
Returns:
null if this is not a directory or an archive file, a valid (but maybe empty) array otherwise.

listFiles

public File[] listFiles()
Equivalent to listFiles((FilenameFilter) null, getArchiveDetector()).

Overrides:
listFiles in class File

listFiles

public File[] listFiles(FileFactory factory)
Returns File objects for the members in this directory in a newly created array. The returned array is not sorted.

Since TrueZIP 6.4, the returned array is an array of this class. Previously, the returned array was an array of java.io.File which solely contained instances of this class.

Note that archive entries with absolute paths are ignored by this method and are never returned.

This file system operation is virtually atomic.

Parameters:
factory - The factory used to create the member file of this directory. This could be an ArchiveDetector in order to detect any archives by the member file names.
Returns:
null if this is not a directory or an archive file, a valid (but maybe empty) array otherwise.

listFiles

public File[] listFiles(FilenameFilter filenameFilter)
Equivalent to listFiles(filenameFilter, getArchiveDetector()).

Overrides:
listFiles in class File

listFiles

public File[] listFiles(FilenameFilter filenameFilter,
                        FileFactory factory)
Returns File objects for the members in this directory which are accepted by filenameFilter in a newly created array. The returned array is not sorted.

Since TrueZIP 6.4, the returned array is an array of this class. Previously, the returned array was an array of java.io.File which solely contained instances of this class.

Note that archive entries with absolute paths are ignored by this method and are never returned.

This file system operation is virtually atomic.

Parameters:
factory - The factory used to create the member file of this directory. This could be an ArchiveDetector in order to detect any archives by the member file names.
Returns:
null if this is not a directory or an archive file, a valid (but maybe empty) array otherwise.
See Also:
Third Party Access using different Archive Detectors

listFiles

public final File[] listFiles(FileFilter fileFilter)
Equivalent to listFiles(fileFilter, getArchiveDetector()).

Overrides:
listFiles in class File

listFiles

public File[] listFiles(FileFilter fileFilter,
                        FileFactory factory)
Returns File objects for the members in this directory which are accepted by fileFilter in a newly created array. The returned array is not sorted.

Since TrueZIP 6.4, the returned array is an array of this class. Previously, the returned array was an array of java.io.File which solely contained instances of this class.

Note that archive entries with absolute paths are ignored by this method and are never returned.

This file system operation is virtually atomic.

Parameters:
factory - The factory used to create the member file of this directory. This could be an ArchiveDetector in order to detect any archives by the member file names.
Returns:
null if this is not a directory or an archive file, a valid (but maybe empty) array otherwise.
See Also:
Third Party Access using different Archive Detectors

createNewFile

public boolean createNewFile()
                      throws IOException
Creates a new, empty file similar to its superclass implementation. Note that this method doesn't create archive files because archive files are virtual directories, not files!

This file system operation is virtually atomic.

Overrides:
createNewFile in class File
Throws:
IOException
See Also:
mkdir()

mkdirs

public boolean mkdirs()
Overrides:
mkdirs in class File

mkdir

public boolean mkdir()
Creates a new, empty (virtual) directory similar to its superclass implementation. This method creates an archive file if isArchive() returns true. Example: new File("archive.zip").mkdir();

Alternatively, archive files can be created on the fly by simply creating their entries. Example: new FileOutputStream("archive.zip/README");

These examples assume TrueZIP's default configuration where ZIP file recognition is enabled and isLenient() returns true.

This file system operation is virtually atomic.

Overrides:
mkdir in class File

delete

public boolean delete()
Deletes an archive entry, archive file or regular node in the real file system. If the file is a directory, it must be empty.

This file system operation is virtually atomic.

Overrides:
delete in class File
See Also:
deleteAll()

deleteAll

public boolean deleteAll()
Deletes the entire directory tree represented by this object, regardless whether this is a file or directory, whether the directory is empty or not or whether the file or directory is actually an archive file, an entry in an archive file or not enclosed in an archive file at all.

This file system operation is not atomic.

Returns:
Whether or not the entire directory tree was successfully deleted.

deleteOnExit

public void deleteOnExit()
Overrides:
deleteOnExit in class File

renameTo

public final boolean renameTo(File dst)
Equivalent to renameTo(dst, getArchiveDetector()).

Overrides:
renameTo in class File

renameTo

public boolean renameTo(File dst,
                        ArchiveDetector detector)
Behaves similar to the super class, but renames this file or directory by recursively copying its data if this object or the dst object is either an archive file or an entry located in an archive file. Hence, in these cases only this file system operation is not atomic.

Parameters:
detector - The object used to detect any archive files in the path and configure their parameters.
See Also:
Third Party Access using different Archive Detectors

copyFrom

public boolean copyFrom(InputStream in)
Copies the input stream in to this file and closes it.

Feature Supported
Preserves file attributes None
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams Always
Direct Data Copying (DDC) No
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyFrom

public boolean copyFrom(File src)
Copies the file src to this file.

Feature Supported
Preserves file attributes None
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyAllFrom

public boolean copyAllFrom(File src)
Recursively copies the file or directory src to this file or directory. This version uses the ArchiveDetector which was used to construct this object to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyAllFrom

public boolean copyAllFrom(File src,
                           ArchiveDetector detector)
Recursively copies the file or directory src to this file or directory. This version uses the given archive detector to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
detector - The object used to detect any archive files in the source and destination directory trees.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

copyAllFrom

public boolean copyAllFrom(File src,
                           ArchiveDetector srcDetector,
                           ArchiveDetector dstDetector)
Recursively copies the file or directory src to this file or directory. By using different ArchiveDetectors for the source and destination, this method can be used to do advanced stuff like unzipping any archive file in the source tree to a plain directory in the destination tree (where srcDetector could be ArchiveDetector.DEFAULT and dstDetector must be ArchiveDetector.NULL) or changing the charset by configuring a custom DefaultArchiveDetector.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
srcDetector - The object used to detect any archive files in the source directory tree.
dstDetector - The object used to detect any archive files in the destination directory tree.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

copyTo

public boolean copyTo(OutputStream out)
Copies this file to the output stream out and closes it.

Feature Supported
Preserves file attributes None
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams Always
Direct Data Copying (DDC) No
Deletes partial written files on failure n/a
Deletes partial written directories on failure n/a
Atomic No

Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyTo

public boolean copyTo(File dst)
Copies this file to the file dst.

Feature Supported
Preserves file attributes None
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Returns:
true if the file has been successfully copied.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyAllTo

public boolean copyAllTo(File dst)
Recursively copies this file or directory to the file or directory dst. This version uses the ArchiveDetector which was used to construct this object to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

copyAllTo

public boolean copyAllTo(File dst,
                         ArchiveDetector detector)
Recursively copies this file or directory to the file or directory dst. This version uses the given archive detector to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
detector - The object used to detect any archive files in the source and destination directory trees.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

copyAllTo

public boolean copyAllTo(File dst,
                         ArchiveDetector srcDetector,
                         ArchiveDetector dstDetector)
Recursively copies this file or directory to the file or directory dst. By using different ArchiveDetectors for the source and destination, this method can be used to do advanced stuff like unzipping any archive file in the source tree to a plain directory in the destination tree (where srcDetector could be ArchiveDetector.DEFAULT and dstDetector must be ArchiveDetector.NULL) or changing the charset by configuring a custom DefaultArchiveDetector.

Feature Supported
Preserves file attributes None
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
srcDetector - The object used to detect any archive files in the source directory tree.
dstDetector - The object used to detect any archive files in the destination directory tree.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

archiveCopyFrom

public boolean archiveCopyFrom(File src)
Copies the file src to this file and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

archiveCopyAllFrom

public boolean archiveCopyAllFrom(File src)
Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

This version uses the ArchiveDetector which was used to construct this object to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

archiveCopyAllFrom

public boolean archiveCopyAllFrom(File src,
                                  ArchiveDetector detector)
Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

This version uses the given archive detector to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
detector - The object used to detect any archive files in the source and destination directory trees.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

archiveCopyAllFrom

public boolean archiveCopyAllFrom(File src,
                                  ArchiveDetector srcDetector,
                                  ArchiveDetector dstDetector)
Recursively copies the file or directory src to this file or directory and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

By using different ArchiveDetectors for the source and destination, this method can be used to do advanced stuff like unzipping any archive file in the source tree to a plain directory in the destination tree (where srcDetector could be ArchiveDetector.DEFAULT and dstDetector must be ArchiveDetector.NULL) or changing the charset by configuring a custom DefaultArchiveDetector.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
srcDetector - The object used to detect any archive files in the source directory tree.
dstDetector - The object used to detect archive files in the destination directory tree.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

archiveCopyTo

public boolean archiveCopyTo(File dst)
Copies this file to the file dst and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

archiveCopyAllTo

public boolean archiveCopyAllTo(File dst)
Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

This version uses the ArchiveDetector which was used to construct this object to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods

archiveCopyAllTo

public boolean archiveCopyAllTo(File dst,
                                ArchiveDetector detector)
Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

This version uses the given archive detector to detect any archive files in the source and destination directory trees. This version uses the given archive detector to detect any archive files in the source and destination directory trees.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
detector - The object used to detect any archive files in the source and destination directory trees.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

archiveCopyAllTo

public boolean archiveCopyAllTo(File dst,
                                ArchiveDetector srcDetector,
                                ArchiveDetector dstDetector)
Recursively copies this file or directory to the file or directory dst and tries to preserve all attributes of the source file to the destination file, too. Note that the current implementation only preserves the last modification time.

By using different ArchiveDetectors for the source and destination, this method can be used to do advanced stuff like unzipping any archive file in the source tree to a plain directory in the destination tree (where srcDetector could be ArchiveDetector.DEFAULT and dstDetector must be ArchiveDetector.NULL) or changing the charset by configuring a custom DefaultArchiveDetector.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively Yes
Reads and overwrites special files No
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure No
Atomic No

Parameters:
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive files and entries are only supported for instances of this class.
srcDetector - The object used to detect any archive files in the source directory tree.
dstDetector - The object used to detect any archive files in the destination directory tree.
Returns:
true if and only if the operation succeeded.
Throws:
NullPointerException - If any parameter is null.
See Also:
Copy Methods, Third Party Access using different Archive Detectors

cp

public static final void cp(InputStream in,
                            OutputStream out)
                     throws IOException
Copies the input stream in to the output stream out.

Feature Supported
Preserves file attributes n/a
Copies directories recursively n/a
Reads and overwrites special files n/a
Closes parameter streams Always
Direct Data Copying (DDC) n/a
Deletes partial written files on failure n/a
Deletes partial written directories on failure n/a
Atomic No

Parameters:
in - The input stream.
out - The output stream.
Throws:
InputIOException - If copying the data fails because of an IOException in the input stream.
IOException - If copying the data fails because of an IOException in the output stream.
NullPointerException - If any parameter is null.
See Also:
Copy Methods

cp

public static final void cp(File src,
                            File dst)
                     throws IOException
Copies src to dst.

Feature Supported
Preserves file attributes None
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Throws:
FileBusyException - If an archive entry cannot get accessed because the client application is trying to input or output to the same archive file simultaneously and the respective archive driver does not support this or the archive file needs an automatic update which cannot get performed because the client is still using other open FileInputStreams or FileOutputStreams for other entries in the same archive file.
FileNotFoundException - If either the source or the destination cannot get accessed.
InputIOException - If copying the data fails because of an IOException in the source.
IOException - If copying the data fails because of an IOException in the destination.
NullPointerException - If any parameter is null.
See Also:
Copy Methods

cp_p

public static final void cp_p(File src,
                              File dst)
                       throws IOException
Copies src to dst and tries to preserve all attributes of the source file to the destination file, too. Currently, only the last modification time is preserved.

Feature Supported
Preserves file attributes Best effort
Copies directories recursively No
Reads and overwrites special files Yes
Closes parameter streams n/a
Direct Data Copying (DDC) Yes
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
src - The source file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
dst - The destination file. Note that although this just needs to be a plain java.io.File, archive entries are only supported for instances of this class.
Throws:
FileBusyException - If an archive entry cannot get accessed because the client application is trying to input or output to the same archive file simultaneously and the respective archive driver does not support this or the archive file needs an automatic update which cannot get performed because the client is still using other open FileInputStreams or FileOutputStreams for other entries in the same archive file.
FileNotFoundException - If either the source or the destination cannot get accessed.
InputIOException - If copying the data fails because of an IOException in the source.
IOException - If copying the data fails because of an IOException in the destination.
NullPointerException - If any parameter is null.
See Also:
Copy Methods

catFrom

public boolean catFrom(InputStream in)
Copies the input stream in to this file or entry in an archive file without closing the input stream.

Feature Supported
Preserves file attributes n/a
Copies directories recursively n/a
Reads and overwrites special files Yes
Closes parameter streams Never
Direct Data Copying (DDC) n/a
Deletes partial written files on failure Yes
Deletes partial written directories on failure n/a
Atomic No

Parameters:
in - The input stream.
Returns:
true if and only if the operation succeeded.
See Also:
Copy Methods

catTo

public boolean catTo(OutputStream out)
Copies this file or entry in an archive file to the output stream out without closing it.

Feature Supported
Preserves file attributes n/a
Copies directories recursively n/a
Reads and overwrites special files Yes
Closes parameter streams Never
Direct Data Copying (DDC) n/a
Deletes partial written files on failure n/a
Deletes partial written directories on failure n/a
Atomic No

Parameters:
out - The output stream.
Returns:
true if and only if the operation succeeded.
See Also:
Copy Methods

cat

public static final void cat(InputStream in,
                             OutputStream out)
                      throws IOException
Copies all data from one stream to another without closing them.

Feature Supported
Preserves file attributes n/a
Copies directories recursively n/a
Reads and overwrites special files n/a
Closes parameter streams Never
Direct Data Copying (DDC) n/a
Deletes partial written files on failure n/a
Deletes partial written directories on failure n/a
Atomic No

Parameters:
in - The input stream.
out - The output stream.
Throws:
InputIOException - If copying the data fails because of an IOException in the input stream.
IOException - If copying the data fails because of an IOException in the output stream.
See Also:
Copy Methods