affyfusion-109/src/affymetrix/calvin/data/GenericData.java

Code
Comments
Other
Rev Date Author Line
11 13 Sep 07 nicklas 1 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 2 //
11 13 Sep 07 nicklas 3 // Copyright (C) 2005 Affymetrix, Inc.
11 13 Sep 07 nicklas 4 //
11 13 Sep 07 nicklas 5 // This library is free software; you can redistribute it and/or modify
11 13 Sep 07 nicklas 6 // it under the terms of the GNU Lesser General Public License as published
11 13 Sep 07 nicklas 7 // by the Free Software Foundation; either version 2.1 of the License,
11 13 Sep 07 nicklas 8 // or (at your option) any later version.
11 13 Sep 07 nicklas 9 //
11 13 Sep 07 nicklas 10 // This library is distributed in the hope that it will be useful, but
11 13 Sep 07 nicklas 11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 13 Sep 07 nicklas 12 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 13 Sep 07 nicklas 13 // for more details.
11 13 Sep 07 nicklas 14 //
11 13 Sep 07 nicklas 15 // You should have received a copy of the GNU Lesser General Public License
11 13 Sep 07 nicklas 16 // along with this library; if not, write to the Free Software Foundation, Inc.,
11 13 Sep 07 nicklas 17 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
11 13 Sep 07 nicklas 18 //
11 13 Sep 07 nicklas 19 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 20
11 13 Sep 07 nicklas 21 package affymetrix.calvin.data;
11 13 Sep 07 nicklas 22
11 13 Sep 07 nicklas 23 import java.util.*;
11 13 Sep 07 nicklas 24 import java.io.*;
11 13 Sep 07 nicklas 25 import java.nio.channels.*;
11 13 Sep 07 nicklas 26 import java.nio.channels.FileChannel.*;
11 13 Sep 07 nicklas 27 import java.nio.*;
11 13 Sep 07 nicklas 28
11 13 Sep 07 nicklas 29 import affymetrix.calvin.utils.*;
11 13 Sep 07 nicklas 30 import affymetrix.calvin.parsers.*;
11 13 Sep 07 nicklas 31
11 13 Sep 07 nicklas 32 /** This class provides interfaces to store analysis results and data. */
11 13 Sep 07 nicklas 33 public class GenericData {
11 13 Sep 07 nicklas 34     
11 13 Sep 07 nicklas 35     /** Creates a new instance of GenericData */
11 13 Sep 07 nicklas 36     public GenericData() {
11 13 Sep 07 nicklas 37         header = new FileHeader();
11 13 Sep 07 nicklas 38     }
11 13 Sep 07 nicklas 39     
11 13 Sep 07 nicklas 40     /** Returns a reference to the file identifier.
11 13 Sep 07 nicklas 41      */
11 13 Sep 07 nicklas 42     public AffymetrixGuidType getFileIdentifier() {
11 13 Sep 07 nicklas 43         return header.getGenericDataHdr().getFileId();
11 13 Sep 07 nicklas 44     }
11 13 Sep 07 nicklas 45
11 13 Sep 07 nicklas 46     /** Returns a reference to the parent array identifier.
11 13 Sep 07 nicklas 47      */
11 13 Sep 07 nicklas 48     public AffymetrixGuidType getArrayIdentifier() {
11 13 Sep 07 nicklas 49         // Find the parent array file generic header
11 13 Sep 07 nicklas 50   GenericDataHeader hdr = header.getGenericDataHdr();
11 13 Sep 07 nicklas 51         int n = hdr.getParentCnt();
11 13 Sep 07 nicklas 52         for (int i=0; i<n; i++)
11 13 Sep 07 nicklas 53         {
11 13 Sep 07 nicklas 54             GenericDataHeader dh = hdr.getParent(i);
11 13 Sep 07 nicklas 55             return dh.getFileId();
11 13 Sep 07 nicklas 56         }
11 13 Sep 07 nicklas 57   return null;
11 13 Sep 07 nicklas 58     }
11 13 Sep 07 nicklas 59
11 13 Sep 07 nicklas 60     /** Returns a reference to the file header object
11 13 Sep 07 nicklas 61      * @return File header object 
11 13 Sep 07 nicklas 62      */
11 13 Sep 07 nicklas 63     public FileHeader getHeader() { return header; }
11 13 Sep 07 nicklas 64
11 13 Sep 07 nicklas 65     /** Return the number of DataGroups in the GenericData object.
11 13 Sep 07 nicklas 66      *  @return Number of DataGroups.
11 13 Sep 07 nicklas 67      */
11 13 Sep 07 nicklas 68     public int getDataGroupCnt() {
11 13 Sep 07 nicklas 69         return header.getDataGroupCnt();
11 13 Sep 07 nicklas 70     }
11 13 Sep 07 nicklas 71
11 13 Sep 07 nicklas 72     /** Return the names of the DataGroups in the generic data object.
11 13 Sep 07 nicklas 73      *  @return vector that will receive the names of all DataGroups.
11 13 Sep 07 nicklas 74      */
11 13 Sep 07 nicklas 75     public Vector getDataGroupNames() {
11 13 Sep 07 nicklas 76         Vector names = new Vector();
11 13 Sep 07 nicklas 77         int n = header.getDataGroupCnt();
11 13 Sep 07 nicklas 78         names.setSize(n);
11 13 Sep 07 nicklas 79         for (int i=0; i<n; i++)
11 13 Sep 07 nicklas 80         {
11 13 Sep 07 nicklas 81             DataGroupHeader dgh = header.getDataGroup(i);
11 13 Sep 07 nicklas 82             names.set(i, dgh.getName());
11 13 Sep 07 nicklas 83         }
11 13 Sep 07 nicklas 84         return names;
11 13 Sep 07 nicklas 85     }
11 13 Sep 07 nicklas 86
11 13 Sep 07 nicklas 87     /** Return the number of DataSets in the DataGroup referenced by index.
11 13 Sep 07 nicklas 88      *  @param dataGroupIdx Index of the DataGroup.
11 13 Sep 07 nicklas 89      *  @return Number of DataSets associated with the DataGroup.
11 13 Sep 07 nicklas 90      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 91      */
11 13 Sep 07 nicklas 92     public int getDataSetCnt(int dataGroupIdx) throws DataGroupNotFoundException {
11 13 Sep 07 nicklas 93         DataGroupHeader dch = findDataGroupHeader(dataGroupIdx);
11 13 Sep 07 nicklas 94   if (dch != null)
11 13 Sep 07 nicklas 95             return dch.getDataSetCnt();
11 13 Sep 07 nicklas 96   else
11 13 Sep 07 nicklas 97   {
11 13 Sep 07 nicklas 98             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 99   }
11 13 Sep 07 nicklas 100     }
11 13 Sep 07 nicklas 101
11 13 Sep 07 nicklas 102     /** Return the number of DataSets in the DataGroup referenced by name.
11 13 Sep 07 nicklas 103      *  @param dataGroupName Name of the DataGroup.
11 13 Sep 07 nicklas 104      *  @return Number of DataSets associated with the DataGroup.
11 13 Sep 07 nicklas 105      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 106      */
11 13 Sep 07 nicklas 107     public int getDataSetCnt(String dataGroupName) throws DataGroupNotFoundException {
11 13 Sep 07 nicklas 108         DataGroupHeader dch = findDataGroupHeader(dataGroupName);
11 13 Sep 07 nicklas 109   if (dch != null)
11 13 Sep 07 nicklas 110             return dch.getDataSetCnt();
11 13 Sep 07 nicklas 111   else
11 13 Sep 07 nicklas 112   {
11 13 Sep 07 nicklas 113             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 114   }
11 13 Sep 07 nicklas 115     }
11 13 Sep 07 nicklas 116
11 13 Sep 07 nicklas 117     /** Return the DataSet names associated with a DataGroup.
11 13 Sep 07 nicklas 118      *  @param dataGroupIdx Index of the DataGroup from which to retrieve the DataSet names.
11 13 Sep 07 nicklas 119      *  @return Vector that will receive the names of all DataSets.
11 13 Sep 07 nicklas 120      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 121      */
11 13 Sep 07 nicklas 122     public Vector getDataSetNames(int dataGroupIdx) throws DataGroupNotFoundException {
11 13 Sep 07 nicklas 123         DataGroupHeader dch = findDataGroupHeader(dataGroupIdx);
11 13 Sep 07 nicklas 124   if (dch == null)
11 13 Sep 07 nicklas 125   {
11 13 Sep 07 nicklas 126             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 127   }
11 13 Sep 07 nicklas 128
11 13 Sep 07 nicklas 129         Vector names = new Vector();
11 13 Sep 07 nicklas 130         int n = dch.getDataSetCnt();
11 13 Sep 07 nicklas 131         names.setSize(n);
11 13 Sep 07 nicklas 132   for (int i=0; i<n; i++)
11 13 Sep 07 nicklas 133         {
11 13 Sep 07 nicklas 134             DataSetHeader dsh = dch.getDataSet(i);
11 13 Sep 07 nicklas 135             names.set(i, dsh.getName());
11 13 Sep 07 nicklas 136   }
11 13 Sep 07 nicklas 137         return names;
11 13 Sep 07 nicklas 138     }
11 13 Sep 07 nicklas 139
11 13 Sep 07 nicklas 140     /** Return the DataSet names associated with a DataGroup.
11 13 Sep 07 nicklas 141      *  @param dataGroupName Name of the DataGroup from which to retrieve the DataSet names.
11 13 Sep 07 nicklas 142      *  @return vector that will receive the names of all DataSets.
11 13 Sep 07 nicklas 143      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 144      */
11 13 Sep 07 nicklas 145     public Vector getDataSetNames(String dataGroupName) throws DataGroupNotFoundException {
11 13 Sep 07 nicklas 146         DataGroupHeader dch = findDataGroupHeader(dataGroupName);
11 13 Sep 07 nicklas 147   if (dch == null)
11 13 Sep 07 nicklas 148   {
11 13 Sep 07 nicklas 149             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 150   }
11 13 Sep 07 nicklas 151
11 13 Sep 07 nicklas 152         Vector names = new Vector();
11 13 Sep 07 nicklas 153         int n = dch.getDataSetCnt();
11 13 Sep 07 nicklas 154         names.setSize(n);
11 13 Sep 07 nicklas 155   for (int i=0; i<n; i++)
11 13 Sep 07 nicklas 156         {
11 13 Sep 07 nicklas 157             DataSetHeader dsh = dch.getDataSet(i);
11 13 Sep 07 nicklas 158             names.set(i, dsh.getName());
11 13 Sep 07 nicklas 159   }
11 13 Sep 07 nicklas 160         return names;
11 13 Sep 07 nicklas 161     }
11 13 Sep 07 nicklas 162
11 13 Sep 07 nicklas 163     /** Returns a pointer to the DataSet object by DataGroup and DataSet index.
11 13 Sep 07 nicklas 164      *  Each call will return a new DataSet object.
11 13 Sep 07 nicklas 165      *  The caller should call Delete when finished with the DataSet.
11 13 Sep 07 nicklas 166      *
11 13 Sep 07 nicklas 167      *  @param dataGroupIdx The index of the DataGroup from which to find the DataSet.
11 13 Sep 07 nicklas 168      *  @param dataSetIdx The index of the DataSet to return.
11 13 Sep 07 nicklas 169      *  @return DataSet
11 13 Sep 07 nicklas 170      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 171      *  @exception affymetrix_calvin_exceptions::DataSetNotFoundException DataSet not found.
11 13 Sep 07 nicklas 172      */
11 13 Sep 07 nicklas 173     public DataSet getDataSet(int dataGroupIdx, int dataSetIdx) throws FileNotOpenException, DataSetNotFoundException, DataGroupNotFoundException {
11 13 Sep 07 nicklas 174         open();
11 13 Sep 07 nicklas 175
11 13 Sep 07 nicklas 176   DataGroupHeader dch = findDataGroupHeader(dataGroupIdx);
11 13 Sep 07 nicklas 177   if (dch != null)
11 13 Sep 07 nicklas 178   {
11 13 Sep 07 nicklas 179             DataSetHeader dph = findDataSetHeader(dch, dataSetIdx);
11 13 Sep 07 nicklas 180             if (dph != null)
11 13 Sep 07 nicklas 181             {
11 13 Sep 07 nicklas 182                 return createDataSet(dph);
11 13 Sep 07 nicklas 183             }
11 13 Sep 07 nicklas 184             else
11 13 Sep 07 nicklas 185             {
11 13 Sep 07 nicklas 186                 throw new DataSetNotFoundException();
11 13 Sep 07 nicklas 187             }
11 13 Sep 07 nicklas 188   }
11 13 Sep 07 nicklas 189   else
11 13 Sep 07 nicklas 190   {
11 13 Sep 07 nicklas 191             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 192   }
11 13 Sep 07 nicklas 193     }
11 13 Sep 07 nicklas 194
11 13 Sep 07 nicklas 195     /** Returns a pointer to the DataSet object by DataGroup and DataSet name.
11 13 Sep 07 nicklas 196      *  Each call will return a new DataSet object.
11 13 Sep 07 nicklas 197      *  The caller should call Delete when finished with the DataSet.
11 13 Sep 07 nicklas 198      *
11 13 Sep 07 nicklas 199      *  @param dataGroupName The name of the DataGroup from which to find the DataSet.
11 13 Sep 07 nicklas 200      *  @param dataSetName The name of the DataSet to return.
11 13 Sep 07 nicklas 201      *  @return DataSet
11 13 Sep 07 nicklas 202      *  @exception affymetrix_calvin_exceptions::DataGroupNotFoundException DataGroup not found.
11 13 Sep 07 nicklas 203      *  @exception affymetrix_calvin_exceptions::DataSetNotFoundException DataSet not found.
11 13 Sep 07 nicklas 204      */
11 13 Sep 07 nicklas 205     public DataSet getDataSet(String dataGroupName, String dataSetName) throws FileNotOpenException, DataSetNotFoundException, DataGroupNotFoundException {
11 13 Sep 07 nicklas 206         open();
11 13 Sep 07 nicklas 207         
11 13 Sep 07 nicklas 208   DataGroupHeader dch = findDataGroupHeader(dataGroupName);
11 13 Sep 07 nicklas 209   if (dch != null)
11 13 Sep 07 nicklas 210   {
11 13 Sep 07 nicklas 211             DataSetHeader dph = findDataSetHeader(dch, dataSetName);
11 13 Sep 07 nicklas 212             if (dph != null)
11 13 Sep 07 nicklas 213             {
11 13 Sep 07 nicklas 214                 return createDataSet(dph);
11 13 Sep 07 nicklas 215             }
11 13 Sep 07 nicklas 216             else
11 13 Sep 07 nicklas 217             {
11 13 Sep 07 nicklas 218                 throw new DataSetNotFoundException();
11 13 Sep 07 nicklas 219             }
11 13 Sep 07 nicklas 220   }
11 13 Sep 07 nicklas 221   else
11 13 Sep 07 nicklas 222   {
11 13 Sep 07 nicklas 223             throw new DataGroupNotFoundException();
11 13 Sep 07 nicklas 224   }
11 13 Sep 07 nicklas 225     }
11 13 Sep 07 nicklas 226
11 13 Sep 07 nicklas 227     /** Creates a new DataSet
11 13 Sep 07 nicklas 228      *  @param dsh The DataSetHeader of the DataSet to create.
11 13 Sep 07 nicklas 229      *  @return The new DataSet
11 13 Sep 07 nicklas 230      */
11 13 Sep 07 nicklas 231     public DataSet createDataSet(DataSetHeader dsh)
11 13 Sep 07 nicklas 232     {
11 13 Sep 07 nicklas 233         readFullDataSetHeader(dsh);
11 13 Sep 07 nicklas 234         return new DataSet(header.getFilename(), dsh, fileStream);
11 13 Sep 07 nicklas 235     }
11 13 Sep 07 nicklas 236
11 13 Sep 07 nicklas 237     /** Returns a DataGroup object based on a DataGroup file position.
11 13 Sep 07 nicklas 238      *  This is useful when there are many DataGroups and the file position of each DataGroup is known (Calvin CDF).
11 13 Sep 07 nicklas 239      *  In this case the GenericFileReader::ReadHeader() method should be called with the ReadNoDataGroupHeader flag.
11 13 Sep 07 nicklas 240      *  @param dataGroupFilePos File position of the DataGroup in the current file
11 13 Sep 07 nicklas 241      *  @return DataGroup object.
11 13 Sep 07 nicklas 242     */
11 13 Sep 07 nicklas 243     public DataGroup getDataGroup(int dataGroupFilePos) throws FileNotOpenException {
11 13 Sep 07 nicklas 244
11 13 Sep 07 nicklas 245         // Open a file stream
11 13 Sep 07 nicklas 246         try
11 13 Sep 07 nicklas 247         {
11 13 Sep 07 nicklas 248             open();
11 13 Sep 07 nicklas 249
11 13 Sep 07 nicklas 250             // Read the DataGroupHeader and all DataSetHeaders
11 13 Sep 07 nicklas 251             FileChannel fc = fileStream.getChannel();
11 13 Sep 07 nicklas 252             fc.position(dataGroupFilePos);
11 13 Sep 07 nicklas 253             DataGroupHeader dch = new DataGroupHeader();
11 13 Sep 07 nicklas 254             DataGroupHeaderReader reader = new DataGroupHeaderReader();
11 13 Sep 07 nicklas 255             reader.read(fileStream, dch);
11 13 Sep 07 nicklas 256             
11 13 Sep 07 nicklas 257             return new DataGroup(header.getFilename(), dch, fileStream);
11 13 Sep 07 nicklas 258         }
11 13 Sep 07 nicklas 259         catch (Throwable t)
11 13 Sep 07 nicklas 260         {
11 13 Sep 07 nicklas 261             throw new FileNotOpenException();
11 13 Sep 07 nicklas 262         }
11 13 Sep 07 nicklas 263     }
11 13 Sep 07 nicklas 264
11 13 Sep 07 nicklas 265     /** Read the full DataSetHeader if it has only been parially read.
11 13 Sep 07 nicklas 266      *  @param dph Pointer to the DataSetHeader to read
11 13 Sep 07 nicklas 267      */
11 13 Sep 07 nicklas 268     public void readFullDataSetHeader(DataSetHeader dph) {
11 13 Sep 07 nicklas 269
11 13 Sep 07 nicklas 270   // Check if the DataSet has been read fully.
11 13 Sep 07 nicklas 271   if (isDSHPartiallyRead(dph))
11 13 Sep 07 nicklas 272   {
11 13 Sep 07 nicklas 273             // Open a file stream
11 13 Sep 07 nicklas 274             try
11 13 Sep 07 nicklas 275             {
11 13 Sep 07 nicklas 276                 open();
11 13 Sep 07 nicklas 277
11 13 Sep 07 nicklas 278                 // Read the DataGroupHeader and all DataSetHeaders
11 13 Sep 07 nicklas 279                 FileChannel fc = fileStream.getChannel();
11 13 Sep 07 nicklas 280                 fc.position(dph.getHeaderStartFilePos());
11 13 Sep 07 nicklas 281
11 13 Sep 07 nicklas 282                 // Read the header
11 13 Sep 07 nicklas 283                 DataSetHeaderReader reader = new DataSetHeaderReader();
11 13 Sep 07 nicklas 284                 reader.read(fileStream, dph);
11 13 Sep 07 nicklas 285             }
11 13 Sep 07 nicklas 286             catch (Throwable t)
11 13 Sep 07 nicklas 287             {
11 13 Sep 07 nicklas 288             }
11 13 Sep 07 nicklas 289   }
11 13 Sep 07 nicklas 290     }
11 13 Sep 07 nicklas 291
11 13 Sep 07 nicklas 292     /** Determine if the DataSetHeader has been partially read.
11 13 Sep 07 nicklas 293      *  @param dph Pointer to the DataSetHeader to check
11 13 Sep 07 nicklas 294      *  @return true if the dph has only been partially read or is 0, otherwise false.
11 13 Sep 07 nicklas 295      */
11 13 Sep 07 nicklas 296     public boolean isDSHPartiallyRead(DataSetHeader dph) {
11 13 Sep 07 nicklas 297         if (dph == null)
11 13 Sep 07 nicklas 298             return false;
11 13 Sep 07 nicklas 299   if (dph.getRowCnt() == 0 && dph.getColumnCnt() == 0)
11 13 Sep 07 nicklas 300             return true;
11 13 Sep 07 nicklas 301   return false;
11 13 Sep 07 nicklas 302     }
11 13 Sep 07 nicklas 303
11 13 Sep 07 nicklas 304     /** Finds a DataSetHeader by name.
11 13 Sep 07 nicklas 305      *  @param name The name of the DataGroup
11 13 Sep 07 nicklas 306      *  @return A pointer to the DataGroupHeader.  If not found, the return is 0.
11 13 Sep 07 nicklas 307      */
11 13 Sep 07 nicklas 308     public DataGroupHeader findDataGroupHeader(String name) {
11 13 Sep 07 nicklas 309         return header.findDataGroupHeader(name);
11 13 Sep 07 nicklas 310     }
11 13 Sep 07 nicklas 311
11 13 Sep 07 nicklas 312     /** Finds a DataGroupHeader by index.
11 13 Sep 07 nicklas 313      *  @param index The index of the DataGroup.
11 13 Sep 07 nicklas 314      *  @return A pointer to the DataGroupHeader.  If not found, the return is 0.
11 13 Sep 07 nicklas 315      */
11 13 Sep 07 nicklas 316     public DataGroupHeader findDataGroupHeader(int index) {
11 13 Sep 07 nicklas 317         DataGroupHeader dch = null;
11 13 Sep 07 nicklas 318   if (index >= 0 && index < header.getDataGroupCnt())
11 13 Sep 07 nicklas 319   {
11 13 Sep 07 nicklas 320             dch = header.getDataGroup(index);
11 13 Sep 07 nicklas 321   }
11 13 Sep 07 nicklas 322   return dch;
11 13 Sep 07 nicklas 323     }
11 13 Sep 07 nicklas 324
11 13 Sep 07 nicklas 325     /** Finds a DataSetHeader by index.
11 13 Sep 07 nicklas 326      *  @param dch The DataGroupHeader of the DataGroup to which the DataSet belongs.
11 13 Sep 07 nicklas 327      *  @param dataSetIdx The DataSet index of the DataSetHeader to find.
11 13 Sep 07 nicklas 328      *  @return A pointer to the DataSetHeader if it is found, otherwise 0.
11 13 Sep 07 nicklas 329      */
11 13 Sep 07 nicklas 330     public static DataSetHeader findDataSetHeader(DataGroupHeader dch, int dataSetIdx) {
11 13 Sep 07 nicklas 331         DataSetHeader dph = null;
11 13 Sep 07 nicklas 332   if (dch != null)
11 13 Sep 07 nicklas 333   {
11 13 Sep 07 nicklas 334             if (dataSetIdx >= 0 && dataSetIdx < dch.getDataSetCnt())
11 13 Sep 07 nicklas 335             {
11 13 Sep 07 nicklas 336                 dph = dch.getDataSet(dataSetIdx);
11 13 Sep 07 nicklas 337             }
11 13 Sep 07 nicklas 338   }
11 13 Sep 07 nicklas 339   return dph;
11 13 Sep 07 nicklas 340     }
11 13 Sep 07 nicklas 341
11 13 Sep 07 nicklas 342     /**  Finds a DataSetHeader by name.
11 13 Sep 07 nicklas 343      *  @param dch The DataGroupHeader of the DataGroup to which the DataSet belongs.
11 13 Sep 07 nicklas 344      *  @param dataSetName The DataSet name of the DataSetHeader to find.
11 13 Sep 07 nicklas 345      *  @return A pointer to the DataSetHeader if it is found, otherwise 0.
11 13 Sep 07 nicklas 346      */
11 13 Sep 07 nicklas 347     public static DataSetHeader findDataSetHeader(DataGroupHeader dch, String dataSetName) {
11 13 Sep 07 nicklas 348         DataSetHeader dph = null;
11 13 Sep 07 nicklas 349   if (dch != null)
11 13 Sep 07 nicklas 350   {
11 13 Sep 07 nicklas 351             dph = dch.findDataSetHeader(dataSetName);
11 13 Sep 07 nicklas 352   }
11 13 Sep 07 nicklas 353   return dph;
11 13 Sep 07 nicklas 354     }
11 13 Sep 07 nicklas 355
11 13 Sep 07 nicklas 356     /** Opens the file for access.
11 13 Sep 07 nicklas 357      *  @return True if opened successfully.
11 13 Sep 07 nicklas 358     */
11 13 Sep 07 nicklas 359     public void open() throws FileNotOpenException {
11 13 Sep 07 nicklas 360         // Open a file stream
11 13 Sep 07 nicklas 361         try
11 13 Sep 07 nicklas 362         {
11 13 Sep 07 nicklas 363             if (fileStream == null)
11 13 Sep 07 nicklas 364                 fileStream = new FileInputStream(header.getFilename());
11 13 Sep 07 nicklas 365         }
11 13 Sep 07 nicklas 366         catch (Throwable t)
11 13 Sep 07 nicklas 367         {
11 13 Sep 07 nicklas 368             throw new FileNotOpenException();
11 13 Sep 07 nicklas 369         }
11 13 Sep 07 nicklas 370     }
11 13 Sep 07 nicklas 371
15 17 Sep 07 nicklas 372     /**
15 17 Sep 07 nicklas 373      * Set the FileInputStream to read from
15 17 Sep 07 nicklas 374      * @param fileStream
15 17 Sep 07 nicklas 375      */
15 17 Sep 07 nicklas 376     public void setFileInputStream(FileInputStream fileStream)
15 17 Sep 07 nicklas 377     {
15 17 Sep 07 nicklas 378         this.fileStream = fileStream;
15 17 Sep 07 nicklas 379     }
15 17 Sep 07 nicklas 380     
11 13 Sep 07 nicklas 381     /** Closes the file.
11 13 Sep 07 nicklas 382      */
11 13 Sep 07 nicklas 383     public void close() {
11 13 Sep 07 nicklas 384         fileStream = null;
11 13 Sep 07 nicklas 385     }
11 13 Sep 07 nicklas 386     
11 13 Sep 07 nicklas 387     /** The header and generic header objects */
11 13 Sep 07 nicklas 388     protected FileHeader header;
11 13 Sep 07 nicklas 389
11 13 Sep 07 nicklas 390     /** The map of the file. */
11 13 Sep 07 nicklas 391     private FileInputStream fileStream;
11 13 Sep 07 nicklas 392 }