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 booleantrueif theWritableGridCoverageResource.CommonOption.REPLACEoption has been specified.private final GridCoverageResourceThe resource where to write.private booleantrueif theWritableGridCoverageResource.CommonOption.UPDATEoption has been specified. -
Constructor Summary
ConstructorsConstructorDescriptionWritableResourceSupport(GridCoverageResource resource, WritableGridCoverageResource.Option[] options) Creates a new helper class for the given options. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringReturns the message for an exception saying that we cannot write the resource.final ChannelDataOutputchannel(ChannelDataInput input) Returns the writable channel positioned at the beginning of the stream.final AffineTransformgetAffineTransform2D(GridExtent extent, org.opengis.referencing.operation.MathTransform gridToCRS) Returns the "grid to CRS" transform as a two-dimensional affine transform.final LocaleReturns the locale used by the resource for error messages, ornullif unknown.private static booleanisEmpty(ChannelDataInput input) Returnstrueif the given channel is empty.final booleanreplace(ChannelDataInput input) Returnstrueif the caller should add or replace the resource orfalseif it needs to update an existing resource.final StringrotationNotSupported(String format) Returns the message for an exception saying that rotations are not supported.final GridCoverageupdate(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 replacetrueif theWritableGridCoverageResource.CommonOption.REPLACEoption has been specified. At most one ofreplaceandupdatecan betrue. -
update
private boolean updatetrueif theWritableGridCoverageResource.CommonOption.UPDATEoption has been specified. At most one ofreplaceandupdatecan 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, ornullif 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
Returnstrueif the caller should add or replace the resource orfalseif 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
trueif theREPLACEoption was specified, or returnsfalseif theUPDATEoption was specified, or thrown aResourceAlreadyExistsExceptionotherwise.
- Parameters:
input- the channel to test for emptiness, ornullif 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
Returnstrueif the given channel is empty. In case of doubt, this method conservatively returnsfalse.- Parameters:
input- the channel to test for emptiness, ornullif unknown.- Returns:
trueif the channel is empty, orfalseif 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.
-