TrueZIP 6.8.3

de.schlichtherle.io
Class Files

java.lang.Object
  extended by de.schlichtherle.io.Files

final class Files
extends Object

Provides static utility methods for Files. Note that in contrast to the File class, the methods in this class accept and return plain java.io.File instances. Full advantage is taken if a parameter is actually an instance of the File class in this package, however.

TODO: Consider making this class public in TrueZIP 7 and remove the stub methods for the same purpose in File.

Since:
TrueZIP 6.5
Author:
Christian Schlichtherle

Nested Class Summary
private static class Files.CopyLock
          A lock used when copying data from one archive to another.
 
Field Summary
private static Files.CopyLock copyLock
          A lock used when copying data from one archive file to another.
 
Constructor Summary
protected Files()
          This class cannot get instantiated.
 
Method Summary
static boolean contains(File a, File b)
           
(package private) static boolean contains(String pathA, String pathB)
          Returns true if and only if the pathA contains pathB.
static void cp_r(boolean preserve, File src, File dst, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          The name of this method is inspired by the Unix command line utility cp with the -r option to operate recursively.
private static void cp_r0(boolean preserve, File src, File dst, ArchiveDetector srcDetector, ArchiveDetector dstDetector)
          Unchecked parameters version.
static void cp(boolean preserve, File src, File dst)
          The name of this method is inspired by the Unix command line utility cp.
static void cp(InputStream in, OutputStream out)
           
private static void cp0(boolean preserve, ArchiveController srcController, String srcEntryName, ArchiveController dstController, String dstEntryName)
          Copies a source file to a destination file, optionally preserving the source's last modification time.
private static void cp0(boolean preserve, ArchiveController srcController, String srcEntryName, File dst)
          Copies a source file to a destination file, optionally preserving the source's last modification time.
private static void cp0(boolean preserve, File src, File dst)
          Unchecked parameters version.
(package private) static void cp0(boolean preserve, File src, InputStream in, ArchiveController dstController, String dstEntryName)
          Copies a source file to a destination file, optionally preserving the source's last modification time.
private static void cp0(boolean preserve, File src, InputStream in, File dst)
          Copies a source file to a destination file, optionally preserving the source's last modification time.
static File getCanOrAbsFile(File file)
          Returns the canonical path of the given file or the normalized absolute path if canonicalizing the path fails due to an IOException.
private static File getCanOrAbsFile0(File file)
           
static boolean isWritableOrCreatable(File file)
          Returns true if the given file exists or can be created and at least one byte can be successfully written to it - the file is restored to its previous state afterwards.
static boolean mv(File src, File dst, ArchiveDetector detector)
          Moves the source to the destination by recursively copying and deleting its files and directories.
private static boolean mv0(File src, File dst, ArchiveDetector detector)
           
static File normalize(File file)
          Removes any "." and ".."
static boolean rm_r(File file)
          Removes the entire directory tree represented by the parameter, regardless whether it's 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyLock

private static final Files.CopyLock copyLock
A lock used when copying data from one archive file to another. This lock must be acquired before any other locks on the controllers are acquired in order to prevent dead locks.

Constructor Detail

Files

protected Files()
This class cannot get instantiated.

Method Detail

contains

public static boolean contains(File a,
                               File b)
See Also:
File.contains(java.io.File)

contains

static boolean contains(String pathA,
                        String pathB)
Returns true if and only if the pathA contains pathB.

Parameters:
pathA - A valid file path.
pathB - A valid file path.
Throws:
NullPointerException - If any parameter is null.

getCanOrAbsFile

public static File getCanOrAbsFile(File file)
Returns the canonical path of the given file or the normalized absolute path if canonicalizing the path fails due to an IOException.

Returns:
The canonical or absolute path of this file as a java.io.File instance.
Throws:
NullPointerException - If file is null.

getCanOrAbsFile0

private static File getCanOrAbsFile0(File file)

normalize

public static File normalize(File file)
Removes any "." and ".." directories from the path wherever possible.

Parameters:
file - The file instance which's path is to be normalized.
Returns:
file if it was already in normalized form. Otherwise, an object which's runtime class is guaranteed to be java.io.File.

isWritableOrCreatable

public static boolean isWritableOrCreatable(File file)
Returns true if the given file exists or can be created and at least one byte can be successfully written to it - the file is restored to its previous state afterwards. This is a much stronger test than File.canWrite().


mv

public static final boolean mv(File src,
                               File dst,
                               ArchiveDetector detector)
Moves the source to the destination by recursively copying and deleting its files and directories. Hence, this file system operation works even with archive files or entries within archive files, but is not atomic.

The name of this method is inspired by the Unix command line utility mv although in most cases it performs a plain rename operation rather than a copy-and-delete operation.

Parameters:
src - The source file or directory. This must exist.
dst - The destination file or directory. This may or may not exist. If it does, its contents are overwritten.
detector - The object used to detect any archive files in the path and configure their parameters.
Returns:
Whether the operation succeeded or not. If it fails, the source and destination may contain only a subset of the source before this operation. However, each file has either been completely moved or not.
See Also:
File.renameTo(java.io.File, ArchiveDetector), Third Party Access using different Archive Detectors

mv0

private static boolean mv0(File src,
                           File dst,
                           ArchiveDetector detector)

cp_r

public static final void cp_r(boolean preserve,
                              File src,
                              File dst,
                              ArchiveDetector srcDetector,
                              ArchiveDetector dstDetector)
                       throws IOException
The name of this method is inspired by the Unix command line utility cp with the -r option to operate recursively.

Throws:
IOException
See Also:
File.copyAllTo(java.io.File, ArchiveDetector, ArchiveDetector), File.archiveCopyAllTo(java.io.File, ArchiveDetector, ArchiveDetector), Third Party Access using different Archive Detectors

cp_r0

private static void cp_r0(boolean preserve,
                          File src,
                          File dst,
                          ArchiveDetector srcDetector,
                          ArchiveDetector dstDetector)
                   throws IOException
Unchecked parameters version.

Throws:
IOException

cp

public static final void cp(boolean preserve,
                            File src,
                            File dst)
                     throws IOException
The name of this method is inspired by the Unix command line utility cp.

Throws:
IOException
See Also:
File.cp(java.io.File, java.io.File), File.cp_p(java.io.File, java.io.File), Third Party Access using different Archive Detectors

cp0

private static void cp0(boolean preserve,
                        File src,
                        File dst)
                 throws IOException
Unchecked parameters version.

Throws:
IOException

cp0

private static void cp0(boolean preserve,
                        File src,
                        InputStream in,
                        File dst)
                 throws IOException
Copies a source file to a destination file, optionally preserving the source's last modification time. We already have an input stream to read the source file, but we know nothing about the destination file yet. Note that this method never closes the given input stream!

Throws:
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.

cp0

private static void cp0(boolean preserve,
                        ArchiveController srcController,
                        String srcEntryName,
                        File dst)
                 throws IOException
Copies a source file to a destination file, optionally preserving the source's last modification time. We know that the source file appears to be an entry in an archive file, but we know nothing about the destination file yet.

Note that this method synchronizes on the class object in order to prevent dead locks by two threads copying archive entries to the other's source archive concurrently!

Throws:
ArchiveController.FalsePositiveException - If the source or the destination is a false positive and the exception cannot get resolved within this method.
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.

cp0

private static void cp0(boolean preserve,
                        ArchiveController srcController,
                        String srcEntryName,
                        ArchiveController dstController,
                        String dstEntryName)
                 throws IOException
Copies a source file to a destination file, optionally preserving the source's last modification time. We know that the source and destination files both appear to be entries in an archive file.

Throws:
ArchiveController.FalsePositiveException - If the source or the destination is a false positive and the exception for the destination cannot get resolved within this method.
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.

cp0

static final void cp0(boolean preserve,
                      File src,
                      InputStream in,
                      ArchiveController dstController,
                      String dstEntryName)
               throws IOException
Copies a source file to a destination file, optionally preserving the source's last modification time. We already have an input stream to read the source file and the destination appears to be an entry in an archive file. Note that this method never closes the given input stream!

Note that this method synchronizes on the class object in order to prevent dead locks by two threads copying archive entries to the other's source archive concurrently!

Throws:
ArchiveController.FalsePositiveException - If the destination is a false positive and the exception cannot get resolved within this method.
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.

cp

public static void cp(InputStream in,
                      OutputStream out)
               throws IOException
Throws:
IOException
See Also:
File.cp(InputStream, OutputStream)

rm_r

public static boolean rm_r(File file)
Removes the entire directory tree represented by the parameter, regardless whether it's 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.

The name of this method is inspired by the Unix command line utility rm with the -r option to operate recursively.

This file system operation is not atomic.

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

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.