Package ucar.nc2.iosp
Class AbstractIOServiceProvider
- java.lang.Object
-
- ucar.nc2.iosp.AbstractIOServiceProvider
-
- All Implemented Interfaces:
IOServiceProvider
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:
- Write your own open(...) and close() methods that keep track of the RandomAccessFile, be sure to close the RandomAccessFile in your close() method.
- Write your own open(...) and close() methods that call the open(...) and close() methods defined here, use the "raf" variable also defined here.
- Don't write an open(...) or close() method, so that those defined here are used.
-
-
Field Summary
Fields Modifier and Type Field Description protected Stringlocationprotected NetcdfFilencfileprotected RandomAccessFilerafSubclasses that use AbstractIOServiceProvider.open(...) or .close() should use this (instead of their own private variable).protected intrafOrder
-
Constructor Summary
Constructors Constructor Description AbstractIOServiceProvider()
-
Method Summary
All Methods Instance Methods Concrete 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 detailsStringgetFileTypeVersion()Get the version of this file type.longgetLastModified()Returns the time that the underlying file(s) were last modified.StructureDataIteratorgetStructureIterator(Structure s, int bufferSize)Get the structure iterator.booleanisBuilder()If this iosp implements build().voidopen(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask)Open existing file, and populate ncfile with it.voidreacquire()Reacquire any resources like file handles Used when reactivating in cache.ArrayreadSection(ParsedSectionSpec cer)Allows reading sections of nested variableslongreadToByteChannel(Variable v2, Section section, WritableByteChannel channel)Read data from a top level Variable and send data to a WritableByteChannel.longreadToOutputStream(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.voidsetNetcdfFile(NetcdfFile ncfile)longstreamToByteChannel(Variable v2, Section section, WritableByteChannel channel)booleansyncExtend()Extend the NetcdfFile if the underlying dataset has changed in a way that is compatible with the current metadata.StringtoStringDebug(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).
-
location
protected String location
-
rafOrder
protected int rafOrder
-
ncfile
protected NetcdfFile ncfile
-
-
Method Detail
-
open
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException
Description copied from interface:IOServiceProviderOpen 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:
openin interfaceIOServiceProvider- 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
-
setNetcdfFile
public void setNetcdfFile(NetcdfFile ncfile)
-
isBuilder
public boolean isBuilder()
Description copied from interface:IOServiceProviderIf this iosp implements build().- Specified by:
isBuilderin interfaceIOServiceProvider
-
build
public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException
Description copied from interface:IOServiceProviderOpen 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.- Specified by:
buildin interfaceIOServiceProvider- 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
public void buildFinish(NetcdfFile ncfile)
Description copied from interface:IOServiceProviderSometimes the builder needs access to the finished objects. This is called after ncfile.build()- Specified by:
buildFinishin interfaceIOServiceProvider
-
close
public void close() throws IOExceptionDescription copied from interface:IOServiceProviderClose 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:
closein interfaceIOServiceProvider- Throws:
IOException- if read error
-
release
public void release() throws IOExceptionDescription copied from interface:IOServiceProviderRelease any system resources like file handles. Optional, implement only if you are able to reacquire. Used when object is made inactive in cache.- Specified by:
releasein interfaceIOServiceProvider- Throws:
IOException
-
reacquire
public void reacquire() throws IOExceptionDescription copied from interface:IOServiceProviderReacquire any resources like file handles Used when reactivating in cache.- Specified by:
reacquirein interfaceIOServiceProvider- Throws:
IOException
-
readToByteChannel
public long readToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
Description copied from interface:IOServiceProviderRead data from a top level Variable and send data to a WritableByteChannel. Must be in big-endian order.- Specified by:
readToByteChannelin interfaceIOServiceProvider- 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
-
readToOutputStream
public long readToOutputStream(Variable v2, Section section, OutputStream out) throws IOException, InvalidRangeException
Description copied from interface:IOServiceProviderRead 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.- Specified by:
readToOutputStreamin interfaceIOServiceProvider- 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
-
streamToByteChannel
public long streamToByteChannel(Variable v2, Section section, WritableByteChannel channel) throws IOException, InvalidRangeException
- Specified by:
streamToByteChannelin interfaceIOServiceProvider- Throws:
IOExceptionInvalidRangeException
-
readSection
public Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException
Description copied from interface:IOServiceProviderAllows reading sections of nested variables- Specified by:
readSectionin interfaceIOServiceProvider- Parameters:
cer- section specification : what data is wanted- Returns:
- requested data array
- Throws:
IOException- on read errorInvalidRangeException- if section spec is invalid
-
getStructureIterator
public StructureDataIterator getStructureIterator(Structure s, int bufferSize) throws IOException
Description copied from interface:IOServiceProviderGet the structure iterator. iosps with top level sequences must override. Not threadsafe; do not use multiple StructureDataIterator for the same iosp.- Specified by:
getStructureIteratorin interfaceIOServiceProvider- Parameters:
s- the StructurebufferSize- the buffersize- Returns:
- the data iterator
- Throws:
IOException- if problem reading data
-
sendIospMessage
@Nullable public Object sendIospMessage(@Nullable Object message)
Description copied from interface:IOServiceProviderA way to communicate arbitrary information to and from an iosp.- Specified by:
sendIospMessagein interfaceIOServiceProvider- Parameters:
message- opaque message sent to the IOSP object when its opened (not when isValidFile() is called)- Returns:
- opaque Object, may be null.
-
syncExtend
public boolean syncExtend() throws IOExceptionDescription copied from interface:IOServiceProviderExtend 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:
syncExtendin interfaceIOServiceProvider- Returns:
- true if the NetcdfFile was extended.
- Throws:
IOException- if a read error occured when accessing the underlying dataset.
-
getLastModified
public long getLastModified()
Returns the time that the underlying file(s) were last modified. If they've changed since they were stored in the cache, they will be closed and reopened withFileFactory.- Returns:
- a
longvalue representing the time the file(s) were last modified or0Lif the last-modified time couldn't be determined for any reason.
-
toStringDebug
public String toStringDebug(Object o)
Description copied from interface:IOServiceProviderDebug info for this object.- Specified by:
toStringDebugin interfaceIOServiceProvider- Parameters:
o- which object- Returns:
- debug info for this object
-
getDetailInfo
public String getDetailInfo()
Description copied from interface:IOServiceProviderShow debug / underlying implementation details- Specified by:
getDetailInfoin interfaceIOServiceProvider- Returns:
- debug info
-
getFileTypeVersion
public String getFileTypeVersion()
Description copied from interface:IOServiceProviderGet the version of this file type.- Specified by:
getFileTypeVersionin interfaceIOServiceProvider- Returns:
- version of the file type
- See Also:
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
-