net.sourceforge.cobertura.javancss.ccl
Class FileUtil

java.lang.Object
  extended by net.sourceforge.cobertura.javancss.ccl.FileUtil

public class FileUtil
extends java.lang.Object

Utility class for file operations.

Simple but most commonly used methods of this class are:
- readFile
- concatPath
Other less frequently used but still handy methods are:
- normalizeFileName to take the current user directory into account via the 'user.dir' system property

Version:
$Id: FileUtil.java 384 2006-03-17 20:10:49Z thekingant $
Author:
Chr. Clemens Lee < clemens@kclee.com >

Constructor Summary
private FileUtil()
          Utility class which should never instanciate itself.
 
Method Summary
static java.lang.String concatPath(java.lang.String sPath_, java.lang.String sFile_)
          Concatenates a file path with the file name.
static java.lang.String getAbsoluteFileName(java.lang.String sFileName_)
           
private static boolean isAbsolute(java.lang.String sFileName_)
          Tests if the file represented by this File object is an absolute pathname.
static java.lang.String normalizeFileName(java.lang.String sFile)
          This method returns an absolute (canonical) file name.
private static java.lang.String normalizeFileName(java.lang.String sFile, java.lang.String sUserDir)
          This method returns an absolute (canonical) file name.
static java.lang.String readFile(java.lang.String sFileName_)
          Reads a File and returns the content in a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

private FileUtil()
Utility class which should never instanciate itself.

Method Detail

concatPath

public static java.lang.String concatPath(java.lang.String sPath_,
                                          java.lang.String sFile_)
Concatenates a file path with the file name. If necessary it adds a File.separator between the path and file name. For example "/home" or "/home/" and "clemens" both become "/home/clemens".

This method is inspired from the FrIJDE project out of the gCollins.File.FileTools class.

FrIJDE Homepage: http://amber.wpi.edu/~thethe/Document/Besiex/Java/FrIJDE/

Parameters:
sPath_ - a directory path. Is not allowed to be null.
sFile_ - the base name of a file.
Returns:
sPath_ if sFile_ is empty.

readFile

public static java.lang.String readFile(java.lang.String sFileName_)
                                 throws java.io.IOException,
                                        java.io.FileNotFoundException
Reads a File and returns the content in a String. CRLF -> LF conversion takes place. This is a convenience method so you don't need to bother creating a file reader object and closing it after it has been used.

Parameters:
sFileName_ - the name of the file to read.
Returns:
a string with the content of the file but without any CR characters.
Throws:
java.io.FileNotFoundException - if file does not exist.
java.io.IOException - if any file operation fails.

getAbsoluteFileName

public static java.lang.String getAbsoluteFileName(java.lang.String sFileName_)
Returns:
It's the canonical path of sFileName_.

normalizeFileName

public static java.lang.String normalizeFileName(java.lang.String sFile)
This method returns an absolute (canonical) file name. The difference to getAbsoluteFileName is that this method uses the system property "user.dir" instead of the native system's current directory. This way you get a chance of changing the current directory inside Java and let your program reflect that change.


normalizeFileName

private static java.lang.String normalizeFileName(java.lang.String sFile,
                                                  java.lang.String sUserDir)
This method returns an absolute (canonical) file name. The difference to getAbsoluteFileName is that this method uses the system property sUserDir instead of the native system's current directory. This way you get a chance of changing the current directory inside Java and let your program reflect that change.


isAbsolute

private static boolean isAbsolute(java.lang.String sFileName_)
Tests if the file represented by this File object 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.