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  

FileOutputStream.java

Go to the documentation of this file.
00001 package org.gridlab.gat.io;
00002 
00003 import java.io.IOException;
00004 import java.io.OutputStream;
00005 
00006 import org.gridlab.gat.GATContext;
00007 import org.gridlab.gat.Preferences;
00008 import org.gridlab.gat.engine.GATEngine;
00009 import org.gridlab.gat.io.cpi.FileOutputStreamCpi;
00010 import org.gridlab.gat.monitoring.Monitorable;
00011 
00012 /**
00013  * A FileStream represents a connection to open file, the file may be either
00014  * remote or local.
00015  * <p>
00016  * A FileStream represents a seekable connection to a file and has semantics
00017  * similar to a standard Unix filedescriptor. It provides methods to query the
00018  * current position in the file and to seek to new positions.
00019  * <p>
00020  * To Write data to a FileStream it is necessary to construct a Buffer and pack
00021  * it with data. Similarly, to read data a buffer must be created to store the
00022  * read data. Writes and reads may either be blocking, or asynchronous.
00023  * Asynchronous writes or reads must be completed by appropriate call.
00024  */
00025 public abstract class FileOutputStream extends OutputStream implements Monitorable  {
00026     protected GATContext gatContext;
00027     protected Preferences preferences;
00028     protected File file;
00029 
00030     /**
00031      * This creates a FileStream attached to the physical file at the specified
00032      * Location. The file may be opened in several modes:
00033      * <ul>
00034      * <li>FileStream.READ --- Open file for reading. The stream is positioned
00035      * at the beginning of the file.</li>
00036      * <li>FileStream.WRITE --- Truncate file to zero length or create file for
00037      * writing. The stream is positioned at the beginning of the file.</li>
00038      * <li>FileStream.READWRITE --- Open for reading and writing. The stream is
00039      * positioned at the beginning of the file.</li>
00040      * <li>FileStream.APPEND --- Open for appending (writing at end of file).
00041      * The file is created if it does not exist. The stream is positioned at the
00042      * end of the file.</li>
00043      * </ul>
00044      * 
00045      * @param gatContext
00046      *            The GATContext used to broker resources
00047      * @param preferences
00048      *            The Preferences for this instance
00049      * @param location
00050      *            The Location of the file to open.
00051      * @param mode
00052      *            The mode to open it --- READ, WRITE, READWRITE, or APPEND,
00053      *            member variables of this class
00054      * @throws java.lang.Exception
00055      *             Thrown upon creation error of some sort
00056      */
00057     protected FileOutputStream(GATContext gatContext, Preferences preferences,
00058             File file) throws IOException {
00059         this.gatContext = gatContext;
00060         this.preferences = preferences;
00061         this.file = file;
00062     }
00063     
00064     /**
00065      * This creates a FileStream attached to the physical file at the specified
00066      * Location. The file may be opened in several modes:
00067      * <ul>
00068      * <li>FileStream.READ --- Open file for reading. The stream is positioned
00069      * at the beginning of the file.</li>
00070      * <li>FileStream.WRITE --- Truncate file to zero length or create file for
00071      * writing. The stream is positioned at the beginning of the file.</li>
00072      * <li>FileStream.READWRITE --- Open for reading and writing. The stream is
00073      * positioned at the beginning of the file.</li>
00074      * <li>FileStream.APPEND --- Open for appending (writing at end of file).
00075      * The file is created if it does not exist. The stream is positioned at the
00076      * end of the file.</li>
00077      * </ul>
00078      * 
00079      * @param gatContext
00080      *            The GATContext used to broker resources
00081      * @param location
00082      *            The Location of the file to open.
00083      * @param mode
00084      *            The mode to open it --- READ, WRITE, READWRITE, or APPEND,
00085      *            member variables of this class
00086      * @throws java.lang.Exception
00087      *             Thrown upon creation error of some sort
00088      */
00089     public FileOutputStream create(GATContext gatContext,
00090                 File file) throws IOException {
00091         return create(gatContext, null, file);
00092     }
00093 
00094     /**
00095      * This creates a FileStream attached to the physical file at the specified
00096      * Location. The file may be opened in several modes:
00097      * <ul>
00098      * <li>FileStream.READ --- Open file for reading. The stream is positioned
00099      * at the beginning of the file.</li>
00100      * <li>FileStream.WRITE --- Truncate file to zero length or create file for
00101      * writing. The stream is positioned at the beginning of the file.</li>
00102      * <li>FileStream.READWRITE --- Open for reading and writing. The stream is
00103      * positioned at the beginning of the file.</li>
00104      * <li>FileStream.APPEND --- Open for appending (writing at end of file).
00105      * The file is created if it does not exist. The stream is positioned at the
00106      * end of the file.</li>
00107      * </ul>
00108      * 
00109      * @param gatContext
00110      *            The GATContext used to broker resources
00111      * @param preferences
00112      *            The Preferences for this instance
00113      * @param location
00114      *            The Location of the file to open.
00115      * @param mode
00116      *            The mode to open it --- READ, WRITE, READWRITE, or APPEND,
00117      *            member variables of this class
00118      * @throws java.lang.Exception
00119      *             Thrown upon creation error of some sort
00120      */
00121     public FileOutputStream create(GATContext gatContext, Preferences preferences,
00122                 File file) throws IOException {
00123         GATEngine gatEngine = GATEngine.getGATEngine();
00124 
00125         Object[] array = new Object[1];
00126         array[0] = file;
00127 
00128         FileOutputStreamCpi f = (FileOutputStreamCpi) gatEngine.getAdaptor(
00129                 FileOutputStreamCpi.class, gatContext, preferences, array);
00130         
00131         return f;
00132     }
00133 }