public class GvrsFile extends Object implements Closeable, AutoCloseable
A Caution Regarding Thread Safety
GvrsFile and its related classes are not thread safe. While a file may be opened on a read-only basis using multiple instances of GvrsFile, the individual objects implement state-variables and data caches that are not protected for concurrent access. Application requiring multi-threaded access to a single GvrsFile object must manage concurrency issues themselves.
Constructor and Description |
---|
GvrsFile(File file,
GvrsFileSpecification specification)
Creates a new raster file using the specified file and specifications.
|
GvrsFile(File file,
String access)
Open an existing raster file for read or write access.
|
GvrsFile(GvrsFileSpecification specification)
Constructs a raster store backed by a temporary file that will
be deleted when the close() method is called or the program terminates
successfully.
|
GvrsFile(int nRowsInRaster,
int nColumnsInRaster,
GvrsElementType elementType)
Constructs a raster store backed by a temporary file that will
be deleted when the close() method is called or the program terminates
successfully.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the file and releases all associated resources.
|
void |
deleteMetadata(String name,
int recordID)
Delete a metadata element from the file.
|
void |
flush()
Write any in-memory data to the file.
|
ICompressionDecoder |
getCompressionDecoder(String name)
Gets an instance of the compression decoder that matches the
specified CODEC name, if any.
|
ICompressionEncoder |
getCompressionEncoder(String name)
Gets an instance of the compression encoder that matches the
specified CODEC name, if any.
|
long |
getCreationTimeMillis()
Gets the time that the GVRS file was created..
|
GvrsElement |
getElement(int index)
Gets the GVRS element by index (order created).
|
GvrsElement |
getElement(String name)
Gets the GVRS element (if any) that matches the specified
name.
|
List<GvrsElement> |
getElements()
Gets a list of all the elements that were specified for
the GVRS file when it was created.
|
File |
getFile()
Gets a file reference to the file in which the data
for this raster is stored.
|
long |
getModificationTimeMillis()
Gets the time that the content of the GVRS file was last modified.
|
GvrsFileSpecification |
getSpecification()
Gets a safe copy of the gvrs raster specification associated with this
file.
|
UUID |
getUUID()
Gets the UUID assigned to this specification (and any GVRS files derived
from it).
|
boolean |
isClosed()
Indicates whether the raster is closed.
|
boolean |
isOpenedForWriting()
Indicates whether the file is opened for writing.
|
double[] |
mapCartesianToGrid(double x,
double y)
Deprecated.
|
double[] |
mapGeographicToGrid(double latitude,
double longitude)
Deprecated.
|
GridPoint |
mapGeographicToGridPoint(double latitude,
double longitude)
Map geographic coordinates to grid coordinates storing the row and column
in an array in that order.
|
GridPoint |
mapGeographicToGridPoint(IGeoPoint geoPoint)
Map geographic coordinates to grid coordinates storing the row and column
in an instance of the GridPoint class.
|
double[] |
mapGridToCartesian(double row,
double column)
Deprecated.
|
double[] |
mapGridToGeographic(double row,
double column)
Deprecated.
|
GeoPoint |
mapGridToGeoPoint(double row,
double column)
Map grid coordinates to geographic coordinates storing the resulting
latitude and longitude in an instance of GvrsGeoPoint.
|
ModelPoint |
mapGridToModelPoint(double row,
double column)
Map grid coordinates to model coordinates storing the resulting x and y
values in a GvrsModelPoint instance.
|
GridPoint |
mapModelToGridPoint(double x,
double y)
Map model coordinates to grid coordinates storing the computed row and
column in an instance of GvrsGridPoint.
|
GridPoint |
mapModelToGridPoint(IModelPoint modelPoint)
Maps a model point to a grid point.
|
List<GvrsMetadata> |
readMetadata()
Reads the complete set of metadata records stored in the file.
|
List<GvrsMetadata> |
readMetadata(GvrsMnc gmConstant)
Reads a set of metadata objects that match the name of the specified
enumeration.If no such metadata objects exist,
the resulting list will be empty.
|
List<GvrsMetadata> |
readMetadata(String name)
Reads a set of metadata objects that match the specified name
from the GVRS file.
|
GvrsMetadata |
readMetadata(String name,
int recordID)
Reads the unique metadata object identified by name and record ID from
the GVRS file.
|
void |
setMultiThreadingEnabled(boolean multiThreadingEnabled)
Sets multi-threading enabled.
|
void |
setTileCacheSize(GvrsCacheSize cacheSize)
Sets the tile cache size to one of the standard sizes defined by the
specified enumeration.
|
void |
setTileCacheSize(int tileCacheSize)
Sets the tile cache size.
|
void |
summarize(PrintStream ps,
boolean analyze)
Scans the file and writes a summary of its content to the specified
PrintStream.
|
boolean |
wasFileDeletedOnClose()
Indicates if the backing file associated with this instance
was successfully deleted on close.
|
void |
writeMetadata(GvrsMetadata metadata)
Store a GvrsMetadata instance providing metadata in the file.
|
void |
writeMetadata(GvrsMnc gmConstant,
String content)
A convenience method for storing a GVRS metadata object with string
content.
|
void |
writeMetadata(String name,
String content)
A convenience method for storing a GVRS metadata object with string
content.
|
public GvrsFile(GvrsFileSpecification specification) throws IOException
specification
- a valid specificationIOException
- when an unhandled I/O exception occurs.public GvrsFile(int nRowsInRaster, int nColumnsInRaster, GvrsElementType elementType) throws IOException
nRowsInRaster
- an integer value greater than zeronColumnsInRaster
- an integer value greater than zeroelementType
- a valid instanceIOException
- when an unhandled I/O exception occurs.public GvrsFile(File file, GvrsFileSpecification specification) throws IOException
When a new instance of GvrsFile is constructed, the specification object will be copied. Therefore, any subsequent changes to the specification object supplied by the application will not affect the internal elements in the GvrsFile element.
file
- a valid file reference giving the path to a new output file
in a location with write access.specification
- a valid GVRS raster specificationIOException
- in the event of an unrecoverable I/O error.public GvrsFile(File file, String access) throws IOException
Only one application may write to a file at once. If the existing file was previously opened for writing and not properly closed, it may not be accessible.
file
- a valid fileaccess
- a valid access control following the general contract of
the
Java RandomAccessFile class (valid values, "r", "rw", etc.)IOException
- in the event of an unrecoverable I/O errorpublic File getFile()
public boolean isClosed()
public void flush() throws IOException
Note that the close() method calls flush() before closing a file.
IOException
- in the event of an I/O error.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- in the event of an I/O error.public boolean wasFileDeletedOnClose()
public boolean isOpenedForWriting()
public void summarize(PrintStream ps, boolean analyze)
The analyze option will allow an application to print a report of statistics related to data compression. This process requires accessing the content of tiles and may be somewhat time consuming.
ps
- a valid print-streamanalyze
- performs an analysis of compressed datapublic void setTileCacheSize(int tileCacheSize) throws IOException
tileCacheSize
- a positive integer greater than zero.IOException
- in the event of a non-recoverable I/O exception.public void setTileCacheSize(GvrsCacheSize cacheSize) throws IOException
If the sizes specified using the enumeration are inadequate for the needs of an application, an application can set the specific number of tiles in the cache by using the alternate version of this method.
cacheSize
- a valid instanceIOException
- in the event of a non-recoverable I/P exception.public GvrsFileSpecification getSpecification()
public ModelPoint mapGridToModelPoint(double row, double column)
The transformation performed by this method is based on the parameters established through a call to the setCartesianCoordinates{} method.
row
- a row (may be a non-integral value)column
- a column (may be a non-integral value)public GridPoint mapModelToGridPoint(double x, double y)
The transformation performed by this method is based on the parameters established through a call to the setCartesianCoordinates() method.
x
- a valid floating-point coordinatey
- a valid floating-point coordinatepublic GridPoint mapModelToGridPoint(IModelPoint modelPoint)
modelPoint
- a valid instancepublic GridPoint mapGeographicToGridPoint(double latitude, double longitude)
The transformation performed by this method is based on the parameters established through a call to the setGeographicCoordinates{} method. Longitudes may be adjusted according to the bounds established by the specification and in recognition of the cyclic nature of longitude coordinates (i.e. 450 degrees is equivalent to 90 degrees, etc.).
latitude
- a valid floating-point coordinatelongitude
- a valid floating-point coordinatepublic GridPoint mapGeographicToGridPoint(IGeoPoint geoPoint)
The transformation performed by this method is based on the parameters established through a call to the setGeographicCoordinates{} method. Longitudes may be adjusted according to the bounds established by the specification and in recognition of the cyclic nature of longitude coordinates (i.e. 450 degrees is equivalent to 90 degrees, etc.).
geoPoint
- a valid instance.public GeoPoint mapGridToGeoPoint(double row, double column)
The transformation performed by this method is based on the parameters established through a call to the setCartesianCoordinates{} method.
row
- the row coordinate (may be non-integral)column
- the column coordinate (may be non-integral)public final List<GvrsMetadata> readMetadata() throws IOException
IOException
- in the event of unrecoverable I/O exceptionpublic final GvrsMetadata readMetadata(String name, int recordID) throws IOException
name
- a valid string giving a GVRS identifierrecordID
- the record ID for the specified metadataIOException
- in the event of an unrecoverable I/O exceptionpublic List<GvrsMetadata> readMetadata(String name) throws IOException
name
- a valid string giving a GVRS identifierIOException
- in the event of an unrecoverable I/O exception.public List<GvrsMetadata> readMetadata(GvrsMnc gmConstant) throws IOException
gmConstant
- a valid, non-null enumeration instanceIOException
- in the event of an unrecoverable I/O exception.public final void writeMetadata(GvrsMetadata metadata) throws IOException
metadata
- a valid instanceIOException
- in the event of a unhandled I/O exception.public void writeMetadata(String name, String content) throws IOException
name
- a valid string conforming to the GVRS identifier syntax.content
- the string to be stored.IOException
- in the event of an unrecoverable I/O exceptionpublic void writeMetadata(GvrsMnc gmConstant, String content) throws IOException
gmConstant
- valid instance.content
- the string to be stored.IOException
- in the event of an unrecoverable I/O exceptionpublic void deleteMetadata(String name, int recordID) throws IOException
name
- The name of the metadata to be deleted.recordID
- The record ID of the metadata to be deleted.IOException
- in the event of an unrecoverable I/O exception.public GvrsElement getElement(String name)
name
- The name of the desired element.public GvrsElement getElement(int index)
index
- A value of zero or greaterpublic List<GvrsElement> getElements()
public UUID getUUID()
The UUID is established by the GvrsFile constructor when a GVRS file is first created. One set, it is never modified.
Internally, the UUID is an arbitrary set of 16 bytes. Non-Java language implementations in languages/environments that do not have built-in support for UUIDs are free to implement this feature as they see fit.
public long getModificationTimeMillis()
public long getCreationTimeMillis()
@Deprecated public double[] mapCartesianToGrid(double x, double y)
This method is deprecated. Please use mapModelToGridPoint() instead.
x
- a valid floating-point coordinatey
- a valid floating-point coordinate@Deprecated public double[] mapGridToCartesian(double row, double column)
This method is deprecated. Please use mapGridToModelPoint() instead.
row
- a row (may be a non-integral value)column
- a column (may be a non-integral value)@Deprecated public double[] mapGeographicToGrid(double latitude, double longitude)
This method is deprecated. Please use mapGeographicToGridPoint() instead.
latitude
- a valid floating-point coordinatelongitude
- a valid floating-point coordinate@Deprecated public double[] mapGridToGeographic(double row, double column)
This method is deprecated. Please use mapModelToGridPoint() instead.
row
- the row coordinate (may be non-integral)column
- the column coordinate (may be non-integral)public ICompressionEncoder getCompressionEncoder(String name)
The purpose of this method is to provide encoder instances to application code to support operations such as statistics and analysis reporting, and post-compression logging. It may be particularly useful to developers implementing their own compression classes.
name
- a valid, non-empty string.public ICompressionDecoder getCompressionDecoder(String name)
The purpose of this method is to provide decoder instances to application code to support operations such as statistics and analysis reporting, and post-compression logging. It may be particularly useful to developers implementing their own compression classes.
name
- a valid, non-empty string.public void setMultiThreadingEnabled(boolean multiThreadingEnabled)
Future development for the GVRS API may expand the use of multi-threaded processing.
Multi-threading can expedite processing, but is sometimes inconvenient when developing, profiling, or debugging an application. Multi-threaded applications may also consume more resources than single threaded processes. Therefore, the default setting for this class is to treat multi-threading as disabled.
multiThreadingEnabled
- true if multiple threads are enabled;
otherwise, false (default false).Copyright © 2022. All rights reserved.