Package ucar.nc2.iosp

Interface IOServiceProvider

All Superinterfaces:
Comparable<IOServiceProvider>
All Known Subinterfaces:
IOServiceProviderWriter
All Known Implementing Classes:
AbstractIOServiceProvider

public interface IOServiceProvider extends Comparable<IOServiceProvider>
This is the service provider interface for the low-level I/O access classes (read only). This is only used by service implementors. An implementation must have a no-argument constructor. The NetcdfFile class manages all registered IOServiceProvider classes. When NetcdfFiles.open() is called:
  1. the file is opened as a ucar.unidata.io.RandomAccessFile;
  2. the file is handed to the isValidFile() method of each registered IOServiceProvider class (until one returns true, which means it can read the file).
  3. the open() method on the resulting IOServiceProvider class is handed the file.
  • Method Details

    • isValidFile

      boolean isValidFile(RandomAccessFile raf) throws IOException
      Check if this is a valid file for this IOServiceProvider. You must make this method thread safe, ie dont keep any state.
      Parameters:
      raf - RandomAccessFile
      Returns:
      true if valid.
      Throws:
      IOException - if read error
    • open

      @Deprecated void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException
      Deprecated.
      Use build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask)
      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.
      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
    • isBuilder

      boolean isBuilder()
      If this iosp implements build().
    • build

      void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException
      Open existing file, and populate it. Note that you cannot reference the NetcdfFile within this routine. This is the bridge to immutable objects that will be used exclusively in version 6.
      Parameters:
      raf - the file to work on, it has already passed the isValidFile() test.
      rootGroup - add objects to the root group.
      cancelTask - used to monitor user cancellation; may be null.
      Throws:
      IOException - if read error
    • buildFinish

      void buildFinish(NetcdfFile ncfile)
      Sometimes the builder needs access to the finished objects. This is called after ncfile.build()
    • readData

      Array readData(Variable v2, Section section) throws IOException, InvalidRangeException
      Read data from a top level Variable and return a memory resident Array. This Array has the same element type as the Variable, and the requested shape.
      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.
      Returns:
      the requested data in a memory-resident Array
      Throws:
      IOException - if read error
      InvalidRangeException - if invalid section
      See Also:
    • readToByteChannel

      @Deprecated long readToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
      Deprecated.
      do not use
      Read data from a top level Variable and send data to a WritableByteChannel. Must be in big-endian order.
      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
    • streamToByteChannel

      @Deprecated long streamToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
      Deprecated.
      do not use
      Throws:
      IOException
      InvalidRangeException
    • readToOutputStream

      long readToOutputStream(Variable v2, Section section, OutputStream out) throws IOException, InvalidRangeException
      Read data from a top level Variable and send data to a OutputStream. Must be in big-endian order, following ncstream conventions. Default implementation just reads to memory and writes to stream. Allow override for possible performance improvements.
      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.
      out - write data to this OutputStream
      Returns:
      the number of bytes written to the channel
      Throws:
      IOException - if read error
      InvalidRangeException - if invalid section
    • readSection

      Allows reading sections of nested variables
      Parameters:
      cer - section specification : what data is wanted
      Returns:
      requested data array
      Throws:
      IOException - on read error
      InvalidRangeException - if section spec is invalid
    • getStructureIterator

      StructureDataIterator getStructureIterator(Structure s, int bufferSize) throws IOException
      Get the structure iterator. iosps with top level sequences must override. Not threadsafe; do not use multiple StructureDataIterator for the same iosp.
      Parameters:
      s - the Structure
      bufferSize - the buffersize
      Returns:
      the data iterator
      Throws:
      IOException - if problem reading data
    • close

      void close() throws IOException
      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.
      Throws:
      IOException - if read error
    • syncExtend

      @Deprecated boolean syncExtend() throws IOException
      Deprecated.
      Do not use.
      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.
      Returns:
      true if the NetcdfFile was extended.
      Throws:
      IOException - if a read error occured when accessing the underlying dataset.
    • release

      void release() throws IOException
      Release any system resources like file handles. Optional, implement only if you are able to reacquire. Used when object is made inactive in cache.
      Throws:
      IOException
    • reacquire

      void reacquire() throws IOException
      Reacquire any resources like file handles Used when reactivating in cache.
      Throws:
      IOException
    • sendIospMessage

      @Nullable Object sendIospMessage(@Nullable Object message)
      A way to communicate arbitrary information to and from an iosp.
      Parameters:
      message - opaque message sent to the IOSP object when its opened (not when isValidFile() is called)
      Returns:
      opaque Object, may be null.
    • toStringDebug

      String toStringDebug(Object o)
      Debug info for this object.
      Parameters:
      o - which object
      Returns:
      debug info for this object
    • getDetailInfo

      String getDetailInfo()
      Show debug / underlying implementation details
      Returns:
      debug info
    • getFileTypeId

      String getFileTypeId()
      Get a unique id for this file type.
      Returns:
      registered id of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • getFileTypeVersion

      String getFileTypeVersion()
      Get the version of this file type.
      Returns:
      version of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • getFileTypeDescription

      String getFileTypeDescription()
      Get a human-readable description for this file type.
      Returns:
      description of the file type
      See Also:
      • "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
    • getSortGroup

      default IOServiceProvider.SortGroup getSortGroup()
      Get the SortGroup for this IOServiceProvider. This determines the order in which the dynamically loaded IOServiceProviders are checked to see if they can open a file with isValidFile().
      Returns:
      SortGroup, by default the SortGroup.LAST_GROUP will be used.
    • compareTo

      default int compareTo(IOServiceProvider other)
      Use the SortGroup to determine the ordering for dynamically loaded IOServiceProviders.
      Specified by:
      compareTo in interface Comparable<IOServiceProvider>