com.starteam.util
Class FileUtils

java.lang.Object
  extended by com.starteam.util.FileUtils

public final class FileUtils
extends java.lang.Object

Utility class for accessing file info.


Method Summary
static long cmp(java.io.File f1, java.io.File f2)
          compare two files
static java.lang.String condenseFilePaths(java.lang.String parentFolderPath, java.lang.String childFolderPath, boolean caseSensitive, java.lang.String delimiter)
          Compares the two paths and returns a relative path that represents the childFolderPath relative to parentFolderPath or null if either of the paths passed in are already relative or invalid, or if childFolderPath cannot be expressed relative to parentFolderPath.
static java.lang.String convertUnicodeEol(java.lang.String eol, Encoding enc)
          Convert an end-of-line string that is assumed to be in ANSI format, to one of our known and supported Unicode encodings.
static java.lang.String fullyResolvedPath(java.lang.String name, java.lang.String pathDelim)
          returns a fully resolved path name
static java.lang.String getAbsolutePath(java.lang.String path)
          Returns the absolute pathname of the given pathname.
static java.lang.String getCanonicalPathName(java.lang.String aPathName, boolean bCaseSensitive)
          returns the canonical path name
static File.CharacterSet getCharacterSet(java.io.File f)
          Determines the character set used by the given file.
static Encoding getEncoding(byte[] buf, int count)
          Return the detected encoding for the byte buffer, or US_ASCII if we can't determine the encoding.
static Encoding getEncoding(java.io.File f)
          Return the detected encoding for the file
static java.lang.String getName(java.lang.String path, java.lang.String pathDelim)
          Returns the name of the file represented by this pathname.
static java.lang.String getParent(java.lang.String path, java.lang.String pathDelim)
          Returns the parent part of the given pathname, or null if the name has no parent part.
static boolean isAbsolute(java.lang.String path)
          Tests if the given pathname is an absolute pathname.
static boolean isBinary(java.io.File f)
          Returns true if the file is considered to be binary.
static boolean isUnicode(byte[] buf, int count)
          Returns true if the byte buffer indicates Unicode.
static boolean isUnicode(java.io.File f)
          Returns true if the file is considered to be Unicode.
static boolean match(java.lang.String pattern, java.lang.String file, boolean caseSensitive)
          match the file name to the pattern
static boolean matchesAnyPattern(java.lang.String filename, java.lang.String[] patterns, boolean caseSensitive)
          match a file name against a set of patterns
static boolean matchPatternList(java.lang.String filename, java.lang.String patternList, boolean caseSensitive)
          match a file name against a set of patterns
static java.lang.String[] parsePatternList(java.lang.String patternList)
          parse the given comma, space or semicolon delimited pattern list
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertUnicodeEol

public static java.lang.String convertUnicodeEol(java.lang.String eol,
                                                 Encoding enc)
Convert an end-of-line string that is assumed to be in ANSI format, to one of our known and supported Unicode encodings. If we're unable to confidently convert it, the original string is returned.

Parameters:
eol - an end-of-line string in ANSI format. Should be one of "\r\n", "\r", "\n".
enc - the encoding to convert to. Must be one of UTF-16LE, UTF-16BE, UTF-32LE or UTF-32BE to be converted.
Returns:
the converted end-of-line string.

getCharacterSet

public static File.CharacterSet getCharacterSet(java.io.File f)
                                         throws java.io.IOException
Determines the character set used by the given file.

Parameters:
f - File
Returns:
A CharacterSet.
Throws:
java.io.IOException

getEncoding

public static Encoding getEncoding(byte[] buf,
                                   int count)
Return the detected encoding for the byte buffer, or US_ASCII if we can't determine the encoding.

Parameters:
buf - the byte buffer to check.
count - length of the buffer.
Returns:
the detected encoding.

getEncoding

public static Encoding getEncoding(java.io.File f)
                            throws java.io.IOException
Return the detected encoding for the file

Parameters:
f - A file whose encoding will be detected
Returns:
the Encoding as determined for the file
Throws:
java.io.IOException - if the file cannot be read

isUnicode

public static boolean isUnicode(byte[] buf,
                                int count)
Returns true if the byte buffer indicates Unicode.

Parameters:
buf - the byte buffer to check.
count - length of the buffer.
Returns:
true if the buffer indicates Unicode.

isBinary

public static boolean isBinary(java.io.File f)
                        throws java.io.IOException
Returns true if the file is considered to be binary. The definition of binary is that the file has at least one null (0x0) character and has not been identified as a unicode text file.

Parameters:
f - the file to test
Returns:
true if the file is considered binary
Throws:
java.io.IOException

isUnicode

public static boolean isUnicode(java.io.File f)
                         throws java.io.IOException
Returns true if the file is considered to be Unicode.

Parameters:
f - the file to test
Returns:
true if the file is considered unicode
Throws:
java.io.IOException

isAbsolute

public static final boolean isAbsolute(java.lang.String path)
Tests if the given pathname is an absolute pathname. The definition of an absolute pathname is system dependent. For example, on UNIX, a pathname is absolute if its first character is the separator character. On Windows platforms, a pathname is absolute if its first character is an ASCII '\' or '/', or if it begins with a letter followed by a colon.

Parameters:
path - A pathname.
Returns:
true if the pathname indicated by the File object is an absolute pathname; false otherwise.

getAbsolutePath

public static final java.lang.String getAbsolutePath(java.lang.String path)
Returns the absolute pathname of the given pathname. If the pathname is an absolute pathname, then return the pathname. Otherwise, return a pathname that is a concatenation of the current user directory, the separator character, and the pathname of this file object.

The system property user.dir contains the current user directory.

Parameters:
path - A pathname.
Returns:
a system-dependent absolute pathname.

getCanonicalPathName

public static final java.lang.String getCanonicalPathName(java.lang.String aPathName,
                                                          boolean bCaseSensitive)
returns the canonical path name

Parameters:
aPathName - the relative path name
bCaseSensitive - true if case sensitive comparison
Returns:
the canonical path name

fullyResolvedPath

public static final java.lang.String fullyResolvedPath(java.lang.String name,
                                                       java.lang.String pathDelim)
returns a fully resolved path name

Parameters:
name - the file name
pathDelim - a path delimiter
Returns:
a fully resolved canonical path name

cmp

public static long cmp(java.io.File f1,
                       java.io.File f2)
                throws java.io.IOException
compare two files

Parameters:
f1 - the first file
f2 - the second file
Returns:
the position where the two files differ or -1
Throws:
java.io.IOException

matchPatternList

public static boolean matchPatternList(java.lang.String filename,
                                       java.lang.String patternList,
                                       boolean caseSensitive)
match a file name against a set of patterns

Parameters:
filename - the file name
patternList - a list of patterns
caseSensitive - true if case sensitive
Returns:
true if at least one match is discovered

matchesAnyPattern

public static boolean matchesAnyPattern(java.lang.String filename,
                                        java.lang.String[] patterns,
                                        boolean caseSensitive)
match a file name against a set of patterns

Parameters:
filename - the file name
patterns - a set of patterns
caseSensitive - true if case sensitive
Returns:
true if at least one match is discovered

parsePatternList

public static java.lang.String[] parsePatternList(java.lang.String patternList)
parse the given comma, space or semicolon delimited pattern list

Parameters:
patternList - the pattern list
Returns:
an array of patterns

match

public static boolean match(java.lang.String pattern,
                            java.lang.String file,
                            boolean caseSensitive)
match the file name to the pattern

Parameters:
pattern - the pattern
file - the file name
caseSensitive - true if case sensitive comaprison is required
Returns:
true if a match is discovered

getParent

public static final java.lang.String getParent(java.lang.String path,
                                               java.lang.String pathDelim)
Returns the parent part of the given pathname, or null if the name has no parent part. The parent part is generally everything leading up to the last occurrence of the separator character, although the precise definition is system dependent. On UNIX, for example, the parent part of "/usr/lib" is "/usr", whose parent part is "/", which in turn has no parent. On Windows platforms, the parent part of "c:\java" is "c:\", which in turn has no parent.

Parameters:
path - A pathname.
pathDelim - The path delimiter.
Returns:
The parent part of the pathname, or null if the name has no parent part.
See Also:
FileUtils.getName(java.lang.String, java.lang.String)

getName

public static final java.lang.String getName(java.lang.String path,
                                             java.lang.String pathDelim)
Returns the name of the file represented by this pathname. The name is everything in the pathame after the last occurrence of the separator character.

Parameters:
path - A pathname.
pathDelim - The path delimiter.
Returns:
the name of the file (without any directory components) represented by this pathname.
See Also:
FileUtils.getParent(java.lang.String, java.lang.String)

condenseFilePaths

public static final java.lang.String condenseFilePaths(java.lang.String parentFolderPath,
                                                       java.lang.String childFolderPath,
                                                       boolean caseSensitive,
                                                       java.lang.String delimiter)
Compares the two paths and returns a relative path that represents the childFolderPath relative to parentFolderPath or null if either of the paths passed in are already relative or invalid, or if childFolderPath cannot be expressed relative to parentFolderPath.

Both c: and \folderName are invalid paths for the purposes of this function. GetCanonicalPathName is called on both paths prior to comparison. This function is essentially Windows-specific, but should work correctly with at least Unix paths.

Parameters:
parentFolderPath - the parent path
childFolderPath - the child path
caseSensitive - true for a case sensistive comparison
delimiter - the inter path separator


StarTeam SDK 14.0, Build 21
Copyright © 2003-2012 Borland Software Corporation. All rights reserved.