org.bioquery.bqutils
Class FileUtils

java.lang.Object
  |
  +--org.bioquery.bqutils.FileUtils

public class FileUtils
extends java.lang.Object

Simple file utilities for working with the bioquery file system.

The bioquery file system represents filenames as a path starting with the file separator (specific to the platform of the SERVER, that is '/' for unix, '\' for windows, etc.), followed by the name of the user directory, and then the path the file. If the path points to a directory, it will end with a file separator, if it points to a file, there will be no file separator after the filename:
/username/queries/subDirectory/aDirectory/
/username/queries/subDirectory/aFile

Author:
James Brundege

Constructor Summary
FileUtils()
           
 
Method Summary
static java.lang.String getFileExtension(java.lang.String fileName)
          Returns the file extension for the given filename or path.
static java.lang.String getFileName(java.lang.String filePath)
          Pulls the filename off the end of a full path and returns.
static java.lang.String getFileSeparator(java.lang.String path)
          Returns the file separator used by this path on this server.
static java.lang.String[] getPath(java.lang.String path)
          This method takes a path String representing a file or directory and puts each file or directory name into a String array, discarding all of the File.separators.
static java.lang.String getPathString(java.lang.String path)
          Strips the filename off the end of the path String and returns.
static boolean isDirectory(java.lang.String path)
          Takes a path String representing a file on the server and determines whether it is a file or directory.
static java.lang.String stripFileExtension(java.lang.String fileName)
          Removes the file extension from a filename or full path, including the final period (.).
static java.lang.String stripFirstDirFromPath(java.lang.String path)
          Removes the first directory from the given path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

getFileSeparator

public static java.lang.String getFileSeparator(java.lang.String path)
Returns the file separator used by this path on this server. Assumes the first character is the separator.
for example: /username/queries/filename
If this is not the case, it will return the incorrect char.
Parameters:
path - a path String representing a file on the server.
Returns:
The first character of the path String, assumed to be the File.separator used by the server. Returns null if path is null or 0 length.

getPath

public static java.lang.String[] getPath(java.lang.String path)
This method takes a path String representing a file or directory and puts each file or directory name into a String array, discarding all of the File.separators. The first element in the String (String[0]) will be the top-level directory.
Parameters:
path - a path String representing a file on the server.
Returns:
a String array containing each file or directory name from the path in order (top-level directory down to file).

getPathString

public static java.lang.String getPathString(java.lang.String path)
Strips the filename off the end of the path String and returns. If the path is a directory, returns it unchanged. This method assumes path starts with the server's File.separator
Returns:
the path string without the filename on the end, or an empty string if path is null or zero length.

getFileName

public static java.lang.String getFileName(java.lang.String filePath)
Pulls the filename off the end of a full path and returns.
Parameters:
filePath - the path to a file on the server

getFileExtension

public static java.lang.String getFileExtension(java.lang.String fileName)
Returns the file extension for the given filename or path. The file extension is whatever portion is after the last period (.).
Parameters:
fileName - a filename or full path
Returns:
the file extension, or null if no extension is found.

stripFileExtension

public static java.lang.String stripFileExtension(java.lang.String fileName)
Removes the file extension from a filename or full path, including the final period (.).
Parameters:
fileName - any filename or pathname
Returns:
the fileName without the final period (.) and whatever came after it.

isDirectory

public static boolean isDirectory(java.lang.String path)
Takes a path String representing a file on the server and determines whether it is a file or directory. This is simply based on whether the final character of the String is a File.separator character or not.
Assumes the last character indicates whether this is a directory.
for example: /username/queries/nameis a file, while
/username/queries/name/ is a directory.
Parameters:
path - a path String representing a file on the server.
Returns:
true if this path points to a directory, false if it points to a file.

stripFirstDirFromPath

public static java.lang.String stripFirstDirFromPath(java.lang.String path)
Removes the first directory from the given path. This may be used to remove the user directory from the beginning of a virtual path.
Parameters:
path - path to a file on the server
Returns:
the path without the first directory, or null if the path does not contain at least 2 file separators.