Package ucar.nc2.iosp
Interface IOServiceProvider
-
- All Known Subinterfaces:
IOServiceProviderWriter
- All Known Implementing Classes:
AbstractIOServiceProvider,H4iosp,H4iosp,H5iosp,H5iospNew,N3iosp,N3iospNew,N3iospWriter,N3raf,NcStreamIosp
public interface IOServiceProviderThis 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:- the file is opened as a ucar.unidata.io.RandomAccessFile;
- the file is handed to the isValidFile() method of each registered IOServiceProvider class (until one returns true, which means it can read the file).
- the open() method on the resulting IOServiceProvider class is handed the file.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidbuild(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask)Open existing file, and populate it.voidbuildFinish(NetcdfFile ncfile)Sometimes the builder needs access to the finished objects.voidclose()Close the file.StringgetDetailInfo()Show debug / underlying implementation detailsStringgetFileTypeDescription()Get a human-readable description for this file type.StringgetFileTypeId()Get a unique id for this file type.StringgetFileTypeVersion()Get the version of this file type.StructureDataIteratorgetStructureIterator(Structure s, int bufferSize)Get the structure iterator.booleanisBuilder()If this iosp implements build().booleanisValidFile(RandomAccessFile raf)Check if this is a valid file for this IOServiceProvider.voidopen(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask)Deprecated.Use build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask)voidreacquire()Reacquire any resources like file handles Used when reactivating in cache.ArrayreadData(Variable v2, Section section)Read data from a top level Variable and return a memory resident Array.ArrayreadSection(ParsedSectionSpec cer)Allows reading sections of nested variableslongreadToByteChannel(Variable v2, Section section, WritableByteChannel channel)Deprecated.do not uselongreadToOutputStream(Variable v2, Section section, OutputStream out)Read data from a top level Variable and send data to a OutputStream.voidrelease()Release any system resources like file handles.ObjectsendIospMessage(Object message)A way to communicate arbitrary information to and from an iosp.longstreamToByteChannel(Variable v2, Section section, WritableByteChannel channel)Deprecated.do not usebooleansyncExtend()Deprecated.Do not use.StringtoStringDebug(Object o)Debug info for this object.
-
-
-
Method Detail
-
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 NetcdfFilecancelTask- 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 Variablesection- 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 errorInvalidRangeException- if invalid section- See Also:
Range
-
readToByteChannel
@Deprecated long readToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
Deprecated.do not useRead data from a top level Variable and send data to a WritableByteChannel. Must be in big-endian order.- Parameters:
v2- a top-level Variablesection- 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 errorInvalidRangeException- if invalid section
-
streamToByteChannel
@Deprecated long streamToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
Deprecated.do not use- Throws:
IOExceptionInvalidRangeException
-
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 Variablesection- 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 errorInvalidRangeException- if invalid section
-
readSection
Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException
Allows reading sections of nested variables- Parameters:
cer- section specification : what data is wanted- Returns:
- requested data array
- Throws:
IOException- on read errorInvalidRangeException- 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 StructurebufferSize- the buffersize- Returns:
- the data iterator
- Throws:
IOException- if problem reading data
-
close
void close() throws IOExceptionClose 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 IOExceptionRelease 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 IOExceptionReacquire 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"
-
-