Package org.apache.sis.internal.storage
Class WritableResourceSupport
java.lang.Object
org.apache.sis.internal.storage.WritableResourceSupport
- All Implemented Interfaces:
Localized
Helper classes for the management of
WritableGridCoverageResource.CommonOption
.- Since:
- 1.2
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
true
if theinvalid reference
WritableGridCoverageResource.CommonOption.REPLACE
private final GridCoverageResource
The resource where to write.private boolean
true
if theinvalid reference
WritableGridCoverageResource.CommonOption.UPDATE
-
Constructor Summary
ConstructorsConstructorDescriptionWritableResourceSupport
(GridCoverageResource resource, WritableGridCoverageResource.Option[] options) Creates a new helper class for the given options. -
Method Summary
Modifier and TypeMethodDescriptionfinal String
Returns the message for an exception saying that we cannot write the resource.final ChannelDataOutput
channel
(ChannelDataInput input) Returns the writable channel positioned at the beginning of the stream.final AffineTransform
getAffineTransform2D
(GridExtent extent, org.opengis.referencing.operation.MathTransform gridToCRS) Returns the "grid to CRS" transform as a two-dimensional affine transform.final Locale
Returns the locale used by the resource for error messages, ornull
if unknown.private static boolean
isEmpty
(ChannelDataInput input) Returnstrue
if the given channel is empty.final boolean
replace
(ChannelDataInput input) Returnstrue
if the caller should add or replace the resource orfalse
if it needs to update an existing resource.final String
rotationNotSupported
(String format) Returns the message for an exception saying that rotations are not supported.final GridCoverage
update
(GridCoverage coverage) Reads the current coverage in the resource and updates its content with cell values from the given coverage.
-
Field Details
-
resource
The resource where to write. -
replace
private boolean replacetrue
if theinvalid reference
WritableGridCoverageResource.CommonOption.REPLACE
replace
andupdate
can betrue
. -
update
private boolean updatetrue
if theinvalid reference
WritableGridCoverageResource.CommonOption.UPDATE
replace
andupdate
can betrue
.
-
-
Constructor Details
-
WritableResourceSupport
public WritableResourceSupport(GridCoverageResource resource, WritableGridCoverageResource.Option[] options) Creates a new helper class for the given options.- Parameters:
resource
- the resource where to write.options
- configuration of the write operation.
-
-
Method Details
-
getLocale
Returns the locale used by the resource for error messages, ornull
if unknown. -
channel
public final ChannelDataOutput channel(ChannelDataInput input) throws IOException, DataStoreException Returns the writable channel positioned at the beginning of the stream. The returned channel should not be closed because it is the same channel than the one used byinput
. Caller should invokeChannelDataOutput.flush()
after usage.- Parameters:
input
- the input from which to get the writable channel.- Returns:
- the writable channel.
- Throws:
IOException
- if the stream position cannot be reset.DataStoreException
- if the channel is read-only.
-
replace
Returnstrue
if the caller should add or replace the resource orfalse
if it needs to update an existing resource. Current heuristic:- If the given channel is empty, then this method always returns
true
. - Otherwise this method returns
true
if theREPLACE
option was specified, or returnsfalse
if theUPDATE
option was specified, or thrown aResourceAlreadyExistsException
otherwise.
- Parameters:
input
- the channel to test for emptiness, ornull
if unknown.- Returns:
- whether the caller should replace (
true
) or update (false
) the resource. - Throws:
IOException
- if an error occurred while checking the channel length.ResourceAlreadyExistsException
- if the resource exists and the writer should neither updating or replacing it.DataStoreException
- if another kind of error occurred with the resource.
- If the given channel is empty, then this method always returns
-
isEmpty
Returnstrue
if the given channel is empty. In case of doubt, this method conservatively returnsfalse
.- Parameters:
input
- the channel to test for emptiness, ornull
if unknown.- Returns:
true
if the channel is empty, orfalse
if not or if unknown.- Throws:
IOException
-
update
Reads the current coverage in the resource and updates its content with cell values from the given coverage. This method can be used as a simple implementation ofWritableGridCoverageResource.CommonOption.UPDATE
. This method returns the updated coverage; it is caller responsibility to write it.This method can be used when updating the coverage requires to read it fully, then write if fully. Advanced writers should try to update only the modified parts (typically some tiles) instead.
- Parameters:
coverage
- the coverage to use for updating the currently existing coverage.- Returns:
- the updated coverage that the caller should write.
- Throws:
DataStoreException
- if an error occurred while reading or updating the coverage.
-
getAffineTransform2D
public final AffineTransform getAffineTransform2D(GridExtent extent, org.opengis.referencing.operation.MathTransform gridToCRS) throws DataStoreException Returns the "grid to CRS" transform as a two-dimensional affine transform. This is a convenience method for writers that support only this kind of transform.- Parameters:
extent
- the extent of the grid coverage to write.gridToCRS
- the "grid to CRS" transform of the coverage to write.- Returns:
- the given "grid to CRS" as a two-dimensional affine transform.
- Throws:
DataStoreException
- if the affine transform cannot be extracted from the given "grid to CRS" transform.
-
canNotWrite
Returns the message for an exception saying that we cannot write the resource.- Returns:
- a localized "Cannot write resource" message.
- Throws:
DataStoreException
- if an error occurred while preparing the error message.
-
rotationNotSupported
Returns the message for an exception saying that rotations are not supported.- Parameters:
format
- name of the format that does not support rotations.- Returns:
- a localized "rotation not supported" message.
-