Package ucar.nc2
Class NetcdfFiles
java.lang.Object
ucar.nc2.NetcdfFiles
Static helper methods for NetcdfFile objects.
These use builders and new versions of Iosp's when available.
- Since:
- 10/3/2019.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NetcdfFilebuild(IOServiceProvider spi, RandomAccessFile raf, String location, CancelTask cancelTask) static StringcanonicalizeUriString(String location) Removes the"file:"or"file://"prefix from the location, if necessary.static booleanFind out if the location can be opened, but dont actually open it.static RandomAccessFileGet the appropriate RandomAccessFile for accessing an object at the provided locationstatic StringCreate a Groups's full name with appropriate backslash escaping.static StringCreate a Variable's full name with appropriate backslash escaping.static StringCreate a Variable's full name with appropriate backslash escaping for use in a section spec.static StringmakeValidCDLName(String vname) Escape special characters in a netcdf short name when it is intended for use in CDL.static StringmakeValidCdmObjectName(String shortName) Create a valid CDM object name.static StringmakeValidPathName(String vname) Escape special characters in a netcdf short name when it is intended for use in a fullnamestatic StringmakeValidSectionSpecName(String vname) Escape special characters in a netcdf short name when it is intended for use in a sectionSpecstatic NetcdfFileOpen an existing netcdf file (read only).static NetcdfFileopen(String location, int buffer_size, CancelTask cancelTask) Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency.static NetcdfFileopen(String location, int buffer_size, CancelTask cancelTask, Object iospMessage) Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency, with an optional special object for the iosp.static NetcdfFileopen(String location, String iospClassName, int bufferSize, CancelTask cancelTask, Object iospMessage) Open an existing file (read only), specifying which IOSP is to be used.static NetcdfFileopen(String location, CancelTask cancelTask) Open an existing file (read only), with option of cancelling.static NetcdfFileopen(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage) Open a RandomAccessFile as a NetcdfFile, if possible.static NetcdfFileopenInMemory(String filename) Read a local CDM file into memory.static NetcdfFileopenInMemory(String name, byte[] data) Open an in-memory netcdf file.static NetcdfFileopenInMemory(String name, byte[] data, String iospClassName) Open an in-memory netcdf file, with a specific iosp.static NetcdfFileopenInMemory(URI uri) Read a remote CDM file into memory.static voidregisterIOProvider(Class iospClass) Register an IOServiceProvider.static voidregisterIOProvider(String className) Register an IOServiceProvider, using its class string name.static voidregisterRandomAccessFileProvider(Class rafClass) Register a RandomAccessFile Provider.static voidregisterRandomAccessFileProvider(String className) Register a RandomAccessFile Provider, using its class string name.
-
Field Details
-
reservedFullName
- See Also:
-
-
Constructor Details
-
NetcdfFiles
public NetcdfFiles()
-
-
Method Details
-
registerIOProvider
public static void registerIOProvider(String className) throws IllegalAccessException, InstantiationException, ClassNotFoundException Register an IOServiceProvider, using its class string name.- Parameters:
className- Class that implements IOServiceProvider.- Throws:
IllegalAccessException- if class is not accessible.InstantiationException- if class doesnt have a no-arg constructor.ClassNotFoundException- if class not found.
-
registerIOProvider
public static void registerIOProvider(Class iospClass) throws IllegalAccessException, InstantiationException Register an IOServiceProvider. A new instance will be created when one of its files is opened.- Parameters:
iospClass- Class that implements IOServiceProvider.- Throws:
IllegalAccessException- if class is not accessible.InstantiationException- if class doesnt have a no-arg constructor.ClassCastException- if class doesnt implement IOServiceProvider interface.
-
registerRandomAccessFileProvider
public static void registerRandomAccessFileProvider(String className) throws IllegalAccessException, InstantiationException, ClassNotFoundException Register a RandomAccessFile Provider, using its class string name.- Parameters:
className- Class that implements RandomAccessFileProvider.- Throws:
IllegalAccessException- if class is not accessible.InstantiationException- if class doesnt have a no-arg constructor.ClassNotFoundException- if class not found.
-
registerRandomAccessFileProvider
public static void registerRandomAccessFileProvider(Class rafClass) throws IllegalAccessException, InstantiationException Register a RandomAccessFile Provider. A new instance will be created when one of its files is opened.- Parameters:
rafClass- Class that implements RandomAccessFileProvider.- Throws:
IllegalAccessException- if class is not accessible.InstantiationException- if class doesnt have a no-arg constructor.ClassCastException- if class doesnt implement IOServiceProvider interface.
-
open
Open an existing netcdf file (read only).- Parameters:
location- location of file.- Returns:
- the NetcdfFile.
- Throws:
IOException- if error
-
open
Open an existing file (read only), with option of cancelling.- Parameters:
location- location of the file.cancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException- if error
-
open
public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask) throws IOException Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency.- Parameters:
location- location of file.buffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException- if error
-
open
public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency, with an optional special object for the iosp.- Parameters:
location- location of file. This may be a- local netcdf-3 filename (with a file: prefix or no prefix)
- remote netcdf-3 filename (with an http: prefix)
- local netcdf-4 filename (with a file: prefix or no prefix)
- local hdf-5 filename (with a file: prefix or no prefix)
- local iosp filename (with a file: prefix or no prefix)
buffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.iospMessage- special iosp tweaking (sent before open is called), may be null- Returns:
- NetcdfFile object, or null if can't find IOServiceProver
- Throws:
IOException- if error
-
open
public static NetcdfFile open(String location, String iospClassName, int bufferSize, CancelTask cancelTask, Object iospMessage) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException Open an existing file (read only), specifying which IOSP is to be used.- Parameters:
location- location of fileiospClassName- fully qualified class name of the IOSP class to handle this filebufferSize- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.iospMessage- special iosp tweaking (sent before open is called), may be null- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException- if read errorClassNotFoundException- cannot find iospClassName in the class pathInstantiationException- if class cannot be instantiatedIllegalAccessException- if class is not accessible
-
canOpen
Find out if the location can be opened, but dont actually open it. In order for a location to be openable by netCDF-java, we must have 1) a properRandomAccessFileimplementation, and 2) a properIOServiceProviderimplementation.- Parameters:
location- location of file- Returns:
- true if can be opened
- Throws:
IOException- on read error
-
canonicalizeUriString
Removes the"file:"or"file://"prefix from the location, if necessary. Also replaces back slashes with forward slashes.- Parameters:
location- a URI string.- Returns:
- a canonical URI string.
-
getRaf
Get the appropriate RandomAccessFile for accessing an object at the provided location- Parameters:
location- a URI string.buffer_size- size of the RandomAccessFileBuffer- Returns:
- RandomAccessFile for the object at location
- Throws:
IOException
-
openInMemory
Read a local CDM file into memory. All reads are then done from memory.- Parameters:
filename- location of CDM file, must be a local file.- Returns:
- a NetcdfFile, which is completely in memory
- Throws:
IOException- if error reading file
-
openInMemory
Read a remote CDM file into memory. All reads are then done from memory.- Parameters:
uri- location of CDM file, must be accessible through url.toURL().openStream().- Returns:
- a NetcdfFile, which is completely in memory
- Throws:
IOException- if error reading file
-
openInMemory
Open an in-memory netcdf file.- Parameters:
name- name of the dataset. Typically use the filename or URI.data- in-memory netcdf file- Returns:
- memory-resident NetcdfFile
- Throws:
IOException- if error
-
openInMemory
public static NetcdfFile openInMemory(String name, byte[] data, String iospClassName) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException Open an in-memory netcdf file, with a specific iosp.- Parameters:
name- name of the dataset. Typically use the filename or URI.data- in-memory netcdf fileiospClassName- fully qualified class name of the IOSP class to handle this file- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException- if read errorClassNotFoundException- cannat find iospClassName in the class pathInstantiationException- if class cannot be instantiatedIllegalAccessException- if class is not accessible
-
open
public static NetcdfFile open(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage) throws IOException Open a RandomAccessFile as a NetcdfFile, if possible.- Parameters:
raf- The open raf, is not cloised by this method.location- human readable locatoin of this dataset.cancelTask- used to monitor user cancellation; may be null.iospMessage- send this message to iosp; may be null.- Returns:
- NetcdfFile or throw an Exception.
- Throws:
IOException- if cannot open as a CDM NetCDF.
-
build
public static NetcdfFile build(IOServiceProvider spi, RandomAccessFile raf, String location, CancelTask cancelTask) throws IOException - Throws:
IOException
-
makeValidCdmObjectName
Create a valid CDM object name. Control chars (< 0x20) are not allowed. Trailing and leading blanks are not allowed and are stripped off. A space is converted into an underscore "_". A forward slash "/" is converted into an underscore "_".- Parameters:
shortName- from this name- Returns:
- valid CDM object name
-
makeValidCDLName
Escape special characters in a netcdf short name when it is intended for use in CDL.- Parameters:
vname- the name- Returns:
- escaped version of it
-
makeValidPathName
Escape special characters in a netcdf short name when it is intended for use in a fullname- Parameters:
vname- the name- Returns:
- escaped version of it
-
makeValidSectionSpecName
Escape special characters in a netcdf short name when it is intended for use in a sectionSpec- Parameters:
vname- the name- Returns:
- escaped version of it
-
makeFullName
Create a Groups's full name with appropriate backslash escaping. -
makeFullName
Create a Variable's full name with appropriate backslash escaping. Warning: do not use for a section spec.- Parameters:
v- the Variable- Returns:
- full name
-
makeFullNameSectionSpec
Create a Variable's full name with appropriate backslash escaping for use in a section spec.- Parameters:
v- the cdm node- Returns:
- full name
-