bb.io
Class FileParent

java.lang.Object
  extended by bb.io.FileParent

 class FileParent
extends Object

This package-private class supports by classes like TarUtil and ZipUtil. The getRelativePath method defines the essential functionality.

This class is multithread safe: its static state is guarded by synchronization, while its instance state is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer

Field Summary
private static int count
           
private  File file
          File that this instance is for.
private  File parent
          The parent directory of file.
private  String rootName
          If parent is null, then this field holds a made up name for an imaginary root directory containing file.
 
Constructor Summary
FileParent(File file)
           
 
Method Summary
(package private)  String getRelativePath(File descendant, char separator)
          Returns descendant's relative path.
private static String nextRootName(File parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

private static int count

file

private final File file
File that this instance is for. Every File passed to the getRelativePath method must equal or be contained inside this value.

Contract: is never null.


parent

private final File parent
The parent directory of file.

Contract: is null if and only if file is a root directory.


rootName

private final String rootName
If parent is null, then this field holds a made up name for an imaginary root directory containing file.

Contract: is null if file is a filesystem root directory. Otherwise, is non-null and the value is unique across all instances of this class in a given JVM session.

Constructor Detail

FileParent

FileParent(File file)
     throws IllegalArgumentException
Throws:
IllegalArgumentException
Method Detail

nextRootName

private static String nextRootName(File parent)

getRelativePath

String getRelativePath(File descendant,
                       char separator)
                 throws IllegalArgumentException
Returns descendant's relative path. If parent is non-null, then the result is relative to parent. Otherwise, the result begins with rootName, followed by descendant's path relative to file.

The result always uses separator to distinguish path elements.

Furthermore, if descendant is a directory, then the result is guaranteed to end with separator (since classes like ZipEntry identify directories based on this).

To understand the motivation for this behavior, see, for example, ZipUtil.archive(File, FileFilter, File[]).

Throws:
IllegalArgumentException - if descendant == null