GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

RandomAccessFile.java

Go to the documentation of this file.
00001 package org.gridlab.gat.io;
00002 
00003 import java.io.FileNotFoundException;
00004 
00005 import org.gridlab.gat.GATContext;
00006 import org.gridlab.gat.Preferences;
00007 import org.gridlab.gat.engine.GATEngine;
00008 import org.gridlab.gat.io.cpi.RandomAccessFileCpi;
00009 import org.gridlab.gat.monitoring.Monitorable;
00010 
00011 /**
00012  * An abstract representation of a physical file.
00013  * <p>
00014  * An instance of this class presents an abstract, system-independent view of a
00015  * physical file. User interfaces and operating systems use system-dependent
00016  * pathname strings to identify physical files. GAT, however, uses an operating
00017  * system independent pathname string to identify a physical file. A physical
00018  * file in GAT is identified by a URI.
00019  * <p>
00020  * An instance of this File class allows for various high-level operations to be
00021  * preformed on a physical file. For example, one can, with a single API call,
00022  * copy a physical file from one location to a second location, move a physical
00023  * file from one location to a second location, delete a physical file, and
00024  * preform various other operations on a physical file. The utility of this
00025  * high-level view of a physical file is multi-fold. The client of an instance
00026  * of this class does not have to concern themselves with the details of reading
00027  * every single byte of a physical file when all they wish to do is copy the
00028  * physical file to a new location. Similarly, a client does not have to deal
00029  * with all the various error states that can occur when moving a physical file (
00030  * Have all the various bytes been read correctly? Have all the various bytes
00031  * been saved correctly? Did the deletion of the original file proceed
00032  * correctly? ); the client simply has to call a single API call and the
00033  * physical file is moved.
00034  */
00035 public abstract class RandomAccessFile extends java.io.RandomAccessFile
00036         implements Monitorable, java.io.Serializable {
00037 
00038     protected File file;
00039 
00040     protected String mode;
00041 
00042     protected GATContext gatContext;
00043 
00044     protected Preferences preferences;
00045 
00046     /**
00047      * Constructs a File instance which corresponds to the physical file
00048      * identified by the passed URI and whose access rights are determined by
00049      * the passed GATContext.
00050      * 
00051      * @param location
00052      *            A URI which represents the URI corresponding to the physical
00053      *            file.
00054      * @param gatContext
00055      *            A GATContext which is used to determine the access rights for
00056      *            this File.
00057      * @param preferences
00058      *            A Preferences which is used to determine the user's
00059      *            preferences for this File.
00060      * @throws java.lang.Exception
00061      *             Thrown upon creation problems
00062      */
00063     protected RandomAccessFile(GATContext gatContext, Preferences preferences,
00064             File file, String mode) throws FileNotFoundException {
00065         super(file, mode);
00066         this.file = file;
00067         this.mode = mode;
00068         this.gatContext = gatContext;
00069         this.preferences = preferences;
00070     }
00071 
00072     /**
00073      * Constructs a File instance which corresponds to the physical file
00074      * identified by the passed URI and whose access rights are determined by
00075      * the passed GATContext.
00076      * 
00077      * @param location
00078      *            A URI which represents the URI corresponding to the physical
00079      *            file.
00080      * @param gatContext
00081      *            A GATContext which is used to determine the access rights for
00082      *            this File.
00083      * @throws java.lang.Exception
00084      *             Thrown upon creation problems
00085      */
00086     public static RandomAccessFile create(GATContext gatContext, File file,
00087             String mode) throws FileNotFoundException {
00088         return create(gatContext, null, file, mode);
00089     }
00090 
00091     /**
00092      * Constructs a File instance which corresponds to the physical file
00093      * identified by the passed URI and whose access rights are determined by
00094      * the passed GATContext.
00095      * 
00096      * @param location
00097      *            A URI which represents the URI corresponding to the physical
00098      *            file.
00099      * @param gatContext
00100      *            A GATContext which is used to determine the access rights for
00101      *            this File.
00102      * @param preferences
00103      *            A Preferences which is used to determine the user's
00104      *            preferences for this File.
00105      * @throws java.lang.Exception
00106      *             Thrown upon creation problems
00107      */
00108     public static RandomAccessFile create(GATContext gatContext,
00109             Preferences preferences, File file, String mode)
00110             throws FileNotFoundException {
00111         GATEngine gatEngine = GATEngine.getGATEngine();
00112         Object[] array = new Object[2];
00113         array[0] = file;
00114         array[1] = mode;
00115         RandomAccessFileCpi f = (RandomAccessFileCpi) gatEngine.getAdaptor(
00116                 RandomAccessFileCpi.class, gatContext, preferences, array);
00117         return f;
00118     }
00119 
00120     /**
00121      * Tests this File for equality with the passed Object.
00122      * <p>
00123      * If the given object is not a File, then this method immediately returns
00124      * false.
00125      * <p>
00126      * If the given object is a File, then it is deemed equal to this instance
00127      * if a URI object constructed from this File's location and a URI object
00128      * constructed from the passed File's URI are equal as determined by the
00129      * Equals method of URI.
00130      * 
00131      * @param object
00132      *            The Object to test for equality
00133      * @return A boolean indicating equality
00134      */
00135     public boolean equals(Object object) {
00136         if (!(object instanceof org.gridlab.gat.io.RandomAccessFile))
00137                 return false;
00138 
00139         org.gridlab.gat.io.RandomAccessFile other = (org.gridlab.gat.io.RandomAccessFile) object;
00140         return file.equals(other.file);
00141     }
00142 }