ucar.nc2.iosp
Class AbstractIOServiceProvider

java.lang.Object
  extended by ucar.nc2.iosp.AbstractIOServiceProvider
All Implemented Interfaces:
IOServiceProvider
Direct Known Subclasses:
AbstractLightningIOSP, AreaServiceProvider, BufrIosp, Cinrad2IOServiceProvider, DMSPiosp, Doradeiosp, Fysatiosp, GempakStationFileIOSP, Ghcnm, Ghcnm2, Giniiosp, GradsBinaryGridServiceProvider, GridServiceProvider, GtopoIosp, H4iosp, H5iosp, IgraPor, JniIosp, N3iosp, NcStreamIosp, Nexrad2IOServiceProvider, Nidsiosp, NmcObsLegacy, NOWRadiosp, SigmetIOServiceProvider, UAMIVServiceProvider, UFiosp, Vis5DIosp

public abstract class AbstractIOServiceProvider
extends Object
implements IOServiceProvider

Abstract base class for IOSP implementations that provides default implementations of readToByteChannel(...) and readSection(...).

Implementations should make sure to handle the RandomAccessFile properly by doing one of the following:

  1. Write your own open(...) and close() methods that keep track of the RandomAccessFile, be sure to close the RandomAccessFile in your close() method.
  2. Write your own open(...) and close() methods that call the open(...) and close() methods defined here, use the "raf" variable also defined here.
  3. Don't write an open(...) or close() method, so that those defined here are used.


Field Summary
protected  RandomAccessFile raf
          Subclasses that use AbstractIOServiceProvider.open(...) or .close() should use this (instead of their own private variable).
 
Constructor Summary
AbstractIOServiceProvider()
           
 
Method Summary
 void close()
          Close the file.
 String getDetailInfo()
          Show debug / underlying implementation details
 String getFileTypeVersion()
          Get the version of this file type.
 StructureDataIterator getStructureIterator(Structure s, int bufferSize)
           
 void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask)
          Open existing file, and populate ncfile with it.
 Array readSection(ParsedSectionSpec cer)
          Allows reading sections of nested variables
 long readToByteChannel(Variable v2, Section section, WritableByteChannel channel)
          Read data from a top level Variable and send data to a WritableByteChannel.
 Object sendIospMessage(Object message)
          A way to communicate arbitrary information to an iosp.
 boolean sync()
          Update the metadata in the NetcdfFile if the underlying dataset has changed.
 boolean syncExtend()
          Extend the NetcdfFile if the underlying dataset has changed in a way that is compatible with the current metadata.
 String toStringDebug(Object o)
          Debug info for this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ucar.nc2.iosp.IOServiceProvider
getFileTypeDescription, getFileTypeId, isValidFile, readData
 

Field Detail

raf

protected RandomAccessFile raf
Subclasses that use AbstractIOServiceProvider.open(...) or .close() should use this (instead of their own private variable).

Constructor Detail

AbstractIOServiceProvider

public AbstractIOServiceProvider()
Method Detail

open

public void open(RandomAccessFile raf,
                 NetcdfFile ncfile,
                 CancelTask cancelTask)
          throws IOException
Description copied from interface: IOServiceProvider
Open existing file, and populate ncfile with it. This method is only called by the NetcdfFile constructor on itself. The provided NetcdfFile object will be empty except for the location String and the IOServiceProvider associated with this NetcdfFile object.

Specified by:
open in interface IOServiceProvider
Parameters:
raf - the file to work on, it has already passed the isValidFile() test.
ncfile - add objects to this empty NetcdfFile
cancelTask - used to monitor user cancellation; may be null.
Throws:
IOException - if read error

close

public void close()
           throws IOException
Description copied from interface: IOServiceProvider
Close the file. It is the IOServiceProvider's job to close the file (even though it didnt open it), and to free any other resources it has used.

Specified by:
close in interface IOServiceProvider
Throws:
IOException - if read error

readToByteChannel

public long readToByteChannel(Variable v2,
                              Section section,
                              WritableByteChannel channel)
                       throws IOException,
                              InvalidRangeException
Description copied from interface: IOServiceProvider
Read data from a top level Variable and send data to a WritableByteChannel. Must be in big-endian order.

Specified by:
readToByteChannel in interface IOServiceProvider
Parameters:
v2 - a top-level Variable
section - the section of data to read. There must be a Range for each Dimension in the variable, in order. Note: no nulls allowed. IOSP may not modify.
channel - write data to this WritableByteChannel
Returns:
the number of bytes written to the channel
Throws:
IOException - if read error
InvalidRangeException - if invalid section

readSection

public Array readSection(ParsedSectionSpec cer)
                  throws IOException,
                         InvalidRangeException
Description copied from interface: IOServiceProvider
Allows reading sections of nested variables

Specified by:
readSection in interface IOServiceProvider
Parameters:
cer - section specification : what data is wanted
Returns:
requested data array
Throws:
IOException - on read error
InvalidRangeException - if section spec is invalid

getStructureIterator

public StructureDataIterator getStructureIterator(Structure s,
                                                  int bufferSize)
                                           throws IOException
Specified by:
getStructureIterator in interface IOServiceProvider
Throws:
IOException

sendIospMessage

public Object sendIospMessage(Object message)
Description copied from interface: IOServiceProvider
A way to communicate arbitrary information to an iosp.

Specified by:
sendIospMessage in interface IOServiceProvider
Parameters:
message - opaque message.
Returns:
opaque return, may be null.

syncExtend

public boolean syncExtend()
                   throws IOException
Description copied from interface: IOServiceProvider
Extend the NetcdfFile if the underlying dataset has changed in a way that is compatible with the current metadata. For example, if the unlimited dimension has grown.

Specified by:
syncExtend in interface IOServiceProvider
Returns:
true if the NetcdfFile was extended.
Throws:
IOException - if a read error occured when accessing the underlying dataset.

sync

public boolean sync()
             throws IOException
Description copied from interface: IOServiceProvider
Update the metadata in the NetcdfFile if the underlying dataset has changed.

Specified by:
sync in interface IOServiceProvider
Returns:
true if the NetcdfFile was changed.
Throws:
IOException - if a read error occured when accessing the underlying dataset.

toStringDebug

public String toStringDebug(Object o)
Description copied from interface: IOServiceProvider
Debug info for this object.

Specified by:
toStringDebug in interface IOServiceProvider
Parameters:
o - which object
Returns:
debug info for this object

getDetailInfo

public String getDetailInfo()
Description copied from interface: IOServiceProvider
Show debug / underlying implementation details

Specified by:
getDetailInfo in interface IOServiceProvider
Returns:
debug info

getFileTypeVersion

public String getFileTypeVersion()
Description copied from interface: IOServiceProvider
Get the version of this file type.

Specified by:
getFileTypeVersion in interface IOServiceProvider
Returns:
version of the file type
See Also:
"http://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.