TrueZIP 6.8.3

de.schlichtherle.io.util
Class Paths

java.lang.Object
  extended by de.schlichtherle.io.util.Paths
Direct Known Subclasses:
Path

public class Paths
extends Object

Static utility methods for path names. In order to enhance interoperability, the methods in this class always detect Windows drives ("[a-zA-Z]:") and UNCs ("\\") in a path name, even on non-Windows platforms.

Since:
TrueZIP 5.1.4
Author:
Christian Schlichtherle

Constructor Summary
protected Paths()
          You cannot instantiate this class.
 
Method Summary
static String cutTrailingSeparator(String path, char separatorChar)
          Deprecated. This method chops off a single trailing separator only. Use cutTrailingSeparators(java.lang.String, char) to chop off multiple trailing separators.
static String cutTrailingSeparators(String path, char separatorChar)
          Cuts off any separator characters at the end of the path, unless the path contains of only separator characters, in which case a single separator character is retained to denote the root directory.
private static int lastIndexNot(String path, char separatorChar, int last)
           
static String normalize(String path)
          Equivalent to normalize(path, File.separatorChar).
static String normalize(String path, char separatorChar)
          Removes all redundant separators, dot directories (".") and dot-dot directories ("..") from the path name and returns the result.
private static int normalize(String path, char separatorChar, int collapse, int end, StringBuffer buffer)
          This is a recursive call: The top level call should provide 0 as the skip parameter, the length of the path as the end parameter and an empty string buffer as the result parameter.
private static int prefixLength(String path, char separatorChar)
          Returns the length of the file system prefix in path.
static String[] split(String path)
          Equivalent to split(path, File.separatorChar).
static String[] split(String path, char separatorChar)
          Equivalent to split(path, separatorChar, new String[2]).
static String[] split(String path, char separatorChar, String[] result)
          Splits a path into its parent path and its base name, recognizing platform specific file system roots.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Paths

protected Paths()
You cannot instantiate this class.

Method Detail

normalize

public static String normalize(String path)
Equivalent to normalize(path, File.separatorChar).


normalize

public static String normalize(String path,
                               char separatorChar)
Removes all redundant separators, dot directories (".") and dot-dot directories ("..") from the path name and returns the result. If present, a single trailing separator character is retained. An empty path results in ".".

On Windows, a path may be prefixed by a drive letter followed by a colon. On all platforms, a path may be prefixed by two leading separators to indicate a UNC, although this is currently supported on Windows only.

Parameters:
path - the non-null path name to normalize.
separatorChar - the separator character.
Returns:
path if it was already in normalized form. Otherwise, a new String with the normalized form of the given path.
Throws:
NullPointerException - if path is null.

normalize

private static int normalize(String path,
                             char separatorChar,
                             int collapse,
                             int end,
                             StringBuffer buffer)
This is a recursive call: The top level call should provide 0 as the skip parameter, the length of the path as the end parameter and an empty string buffer as the result parameter.

Parameters:
collapse - the number of adjacent dir/.. segments in the path to collapse. This value must not be negative.
end - the current position in path. Only the string to the left of this index is considered. If not positive, nothing happens.
buffer - the non-null string buffer for the result.
Returns:
The number of adjacent segments in the path which have not been collapsed at this position.

cutTrailingSeparators

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

Returns:
path if it's a path without trailing separators or contains the separator only. Otherwise, the substring until the first of at least one separating characters is returned.
Throws:
NullPointerException - If path is null.

cutTrailingSeparator

public static final String cutTrailingSeparator(String path,
                                                char separatorChar)
Deprecated. This method chops off a single trailing separator only. Use cutTrailingSeparators(java.lang.String, char) to chop off multiple trailing separators.

Cuts off a trailing separator character of the pathname, unless the pathname contains of only the separator character (i.e. denotes the root directory).

Returns:
path if it's a path without a trailing separator or contains the separator only. Otherwise, the substring up to the last character is returned.
Throws:
NullPointerException - If path is null.

split

public static String[] split(String path)
Equivalent to split(path, File.separatorChar).


split

public static String[] split(String path,
                             char separatorChar)
Equivalent to split(path, separatorChar, new String[2]).


split

public static String[] split(String path,
                             char separatorChar,
                             String[] result)
Splits a path into its parent path and its base name, recognizing platform specific file system roots.

Parameters:
path - The name of the path which's parent path and base name are to be returned.
separatorChar - The path separator character to use for this operation.
result - An array of at least two String elements to hold the result upon return.
Returns:
An array holding at least two strings:
  1. Index zero holds the parent path or null if the path does not specify a parent. This name compares equal with File.getParent().
  2. Index one holds the base name. This name compares equal with File.getName().
Throws:
NullPointerException - If path is null.

lastIndexNot

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

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 in path.
Returns:
The number of characters in the prefix.
Throws:
NullPointerException - If path is null.

TrueZIP 6.8.3

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