igpp.util
Class File

java.lang.Object
  extended by igpp.util.File

public class File
extends Object

File utilities that augment the standard java.io.File class.

Since:
1.0.0
Version:
1.0.0
Author:
Todd King, UCLA/IGPP

Constructor Summary
File()
           
 
Method Summary
static long copy(String source, String destination)
          Copy a file from one location to another.
static boolean delete(String source)
          Remove a file from the file system
static String getBaseName(String pathname)
          Extract the base name of the file from a pathname.
static String getExtension(String pathname)
          Extract the extension of the file from a pathname.
static String getMD5(String pathname)
          Return the MD5 digest for a file.
static String getName(String pathname)
          Extract the name of the file from a pathname.
static String getParent(String pathname)
          Extract the parent of the file from a pathname.
static String getSHA1(String pathname)
          Return the SHA-1 digest for a file.
static String getSHA256(String pathname)
          Return the SHA-256 digest for a file.
static String getSHA512(String pathname)
          Return the SHA-512 digest for a file.
static long getSize(String pathname)
          Return the size of the file in bytes.
static boolean isDirectory(String pathname)
          Determines if a given pathname is to a directory.
static boolean isFile(String pathname)
          Determines if a given pathname is to a file.
static boolean rename(String source, String destination)
          Rename a file.
static boolean setOwner(String pathname, String user, String group)
          Set the owner and group for a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

File

public File()
Method Detail

copy

public static long copy(String source,
                        String destination)
                 throws NullPointerException,
                        IOException,
                        SecurityException
Copy a file from one location to another. The copy is failure safe in that if the copy fails to complete the destination is not over written.

Parameters:
source - the name of the source file.
destination - the name of the file to copy the source file to.
Returns:
the total number of bytes copied.
Throws:
NullPointerException
IOException
SecurityException

delete

public static boolean delete(String source)
Remove a file from the file system

Parameters:
source - the name of the source file.
Returns:
true if the delete is successful. false otherwise.

rename

public static boolean rename(String source,
                             String destination)
                      throws NullPointerException,
                             SecurityException,
                             IOException
Rename a file. If the destination file name is not absolute the file name become relative to the location of the source file name. The destination file is removed if it exists.

Parameters:
source - the name of the source file.
Returns:
true if the rename is successful. false otherwise.
Throws:
IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require file system queries
NullPointerException - If the either pathname argument is null
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to either the old or new pathnames

isDirectory

public static boolean isDirectory(String pathname)
Determines if a given pathname is to a directory.

Parameters:
pathname - the name of the file system object.
Returns:
true if the pathname points to a directory. false otherwise.

isFile

public static boolean isFile(String pathname)
Determines if a given pathname is to a file.

Parameters:
pathname - the name of the filesystem object.
Returns:
true if the pathname points to a directory. false otherwise.

getName

public static String getName(String pathname)
Extract the name of the file from a pathname.

Parameters:
pathname - the name of the file system object.
Returns:
the file name portion of pathname.

getParent

public static String getParent(String pathname)
Extract the parent of the file from a pathname.

Parameters:
pathname - the name of the filesystem object.
Returns:
the parent portion of pathname.

getBaseName

public static String getBaseName(String pathname)
Extract the base name of the file from a pathname.

Parameters:
pathname - the name of the file system object.
Returns:
the base name of the file portion of pathname.

getExtension

public static String getExtension(String pathname)
Extract the extension of the file from a pathname.

Parameters:
pathname - the name of the file system object.
Returns:
the extension portion of pathname.

setOwner

public static boolean setOwner(String pathname,
                               String user,
                               String group)
Set the owner and group for a file. Runs the systems "chown" or "chgrp" command with the correct arguments. If user is null and group is set then "chgrp" is called, otherwise "chown" is called.

Parameters:
pathname - the name of the file system object.
user - the user name in the system.
group - the group name in the system
Returns:
true if successful, otherwise false.

getSize

public static long getSize(String pathname)
Return the size of the file in bytes.

Parameters:
pathname - the name of the file system object.
Returns:
the size of the file in bytes.

getMD5

public static String getMD5(String pathname)
Return the MD5 digest for a file. This is a convenience function and calls igpp.util.Digest.digestFile()

Parameters:
pathname - the name of the filesystem object.
Returns:
a String containing the MD5 digest for a file. If the digest cannot be calculated an empty string is returned.

getSHA1

public static String getSHA1(String pathname)
Return the SHA-1 digest for a file. This is a convenience function and calls igpp.util.Digest.digestFile()

Parameters:
pathname - the name of the filesystem object.
Returns:
a String containing the SHA-1 digest for a file. If the digest cannot be calculated an empty string is returned.

getSHA256

public static String getSHA256(String pathname)
Return the SHA-256 digest for a file. This is a convenience function and calls igpp.util.Digest.digestFile()

Parameters:
pathname - the name of the filesystem object.
Returns:
a String containing the SHA-256 digest for a file. If the digest cannot be calculated an empty string is returned.

getSHA512

public static String getSHA512(String pathname)
Return the SHA-512 digest for a file. This is a convenience function and calls igpp.util.Digest.digestFile()

Parameters:
pathname - the name of the filesystem object.
Returns:
a String containing the SHA-512 digest for a file. If the digest cannot be calculated an empty string is returned.


Copyright © 2008-2009 Regents University of California. All Rights Reserved.