org.glite.authz.common.util
Class Files

java.lang.Object
  extended by org.glite.authz.common.util.Files

public final class Files
extends java.lang.Object

A utility class for working with files.


Method Summary
static byte[] fileToByteArray(java.io.File file)
          Reads the contents of a file in to a byte array.
static java.io.File getFile(java.lang.String filePath, boolean requireFile, boolean requireExistance, boolean requireReadable, boolean requireWritable)
          Gets the file object associated with the path.
static java.io.File getReadableFile(java.lang.String filePath)
          A convenience method for getting a file and requiring it to be a readable file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getReadableFile

public static java.io.File getReadableFile(java.lang.String filePath)
                                    throws java.io.IOException
A convenience method for getting a file and requiring it to be a readable file. This is equivalent to calling getFile(filePath, true, true, true, false).

Parameters:
filePath - the path to the file
Returns:
the file
Throws:
java.io.IOException - thrown if the file is a directory, does not exist, or can not be read

getFile

public static java.io.File getFile(java.lang.String filePath,
                                   boolean requireFile,
                                   boolean requireExistance,
                                   boolean requireReadable,
                                   boolean requireWritable)
                            throws java.io.IOException
Gets the file object associated with the path.

Parameters:
filePath - the file path
requireFile - whether the given path is required to be a file instead of a directory
requireExistance - whether the given file/directory must exist already
requireReadable - whether the given file/directory must be readable
requireWritable - whether the given file/directory must be writable
Returns:
the created file
Throws:
java.io.IOException - thrown if existance, reabability, or writability is required but not met

fileToByteArray

public static byte[] fileToByteArray(java.io.File file)
                              throws java.io.IOException
Reads the contents of a file in to a byte array.

Parameters:
file - file to read
Returns:
the byte contents of the file
Throws:
java.io.IOException - throw if there is a problem reading the file in to the byte array


Copyright © 2008-2012 EMI - European Middleware Initiative. All Rights Reserved.