TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.io
Class Paths

java.lang.Object
  extended by de.schlichtherle.truezip.io.Paths

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class Paths
extends Object

Provides static utility methods for path names.

Author:
Christian Schlichtherle

Nested Class Summary
static class Paths.Normalizer
          A normalizer for path names.
static class Paths.Splitter
          A splitter for path names.
 
Constructor Summary
private Paths()
          You cannot instantiate this class.
 
Method Summary
static boolean contains(String a, String b, char separatorChar)
          Returns true if and only if the path name represented by a contains the path name represented by b.
static String cutTrailingSeparators(String path, char separatorChar)
          Cuts off any separator characters at the end of the given path name, unless the path name contains of only separator characters, in which case a single separator character is retained to denote the root directory.
static boolean isAbsolute(String path, char separatorChar)
          Returns true iff the given path name is absolute.
static boolean isRoot(String path)
          Returns true iff the given path name refers to the root directory, i.e. if it's empty.
private static int lastIndexNot(String path, char separatorChar, int last)
           
static String normalize(String path, char separatorChar)
          Equivalent to new Normalizer(separatorChar).
private static int prefixLength(String path, char separatorChar)
          Returns the length of the file system prefix in path.
static Paths.Splitter split(String path, char separatorChar)
          Equivalent to {@code return new Splitter(separatorChar).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Paths

private Paths()
You cannot instantiate this class.

Method Detail

normalize

public static String normalize(String path,
                               char separatorChar)
Equivalent to new Normalizer(separatorChar).Paths.Normalizer.normalize(String).


cutTrailingSeparators

public static String cutTrailingSeparators(String path,
                                           char separatorChar)
Cuts off any separator characters at the end of the given path name, unless the path name contains of only separator characters, in which case a single separator character is retained to denote the root directory.

Parameters:
path - The path name to chop.
separatorChar - The file name separator character.
Returns:
path if it's a path name without trailing separators or contains the separator character only. Otherwise, the substring until the first of at least one separating characters is returned.

split

public static Paths.Splitter split(String path,
                                   char separatorChar)
Equivalent to return new Splitter(separatorChar).{@link Splitter#split(String) split(path)};.


lastIndexNot

private static int lastIndexNot(String path,
                                char separatorChar,
                                int last)

isRoot

public static boolean isRoot(String path)
Returns true iff the given path name refers to the root directory, i.e. if it's empty.


isAbsolute

public static boolean isAbsolute(String path,
                                 char separatorChar)
Returns true iff the given path name is absolute. Windows drives and UNC's are always recognized by this method, even on non-Windows platforms in order to ease interoperability.

Parameters:
path - The path name to test.
separatorChar - The file name separator character.
Returns:
Whether or not path is prefixed and the prefix ends with a separator character.
Throws:
NullPointerException - If path is null.

prefixLength

private static int prefixLength(String path,
                                char separatorChar)
Returns the length of the file system prefix in path. File system prefixes are:
  1. A letter followed by a colon and an optional separator. On Windows, this is the notation for a drive.
  2. Two leading separators. On Windows, this is the notation for a UNC.
  3. A single leading separator. On Windows and POSIX, this is the notation for an absolute path.
This method works identical on all platforms, so even if the separator is '/', two leading separators would be considered to be a UNC and hence the return value would be 2.

Parameters:
path - The file system path.
separatorChar - The file name separator character.
Returns:
The number of characters in the prefix.
Throws:
NullPointerException - If path is null.

contains

public static boolean contains(String a,
                               String b,
                               char separatorChar)
Returns true if and only if the path name represented by a contains the path name represented by b.

Parameters:
a - A non-null String reference.
b - A non-null String reference.
separatorChar - The file name separator character.
Throws:
NullPointerException - If any parameter is null.

TrueZIP Kernel 7.0-rc1

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