public abstract class AbstractRetrievalPostProcessor extends Object implements RetrievalPostProcessor
Modifier and Type | Field and Description |
---|---|
protected AVList |
avList
Holds miscellaneous parameters examined by this and subclasses.
|
protected Retriever |
retriever
The retriever associated with the post-processor.
|
Constructor and Description |
---|
AbstractRetrievalPostProcessor()
Create a default post-processor.
|
AbstractRetrievalPostProcessor(AVList avList)
Create a post-processor and pass it attributes that can be examined during content handling.
|
Modifier and Type | Method and Description |
---|---|
protected ByteBuffer |
convertToDDS()
Converts an image to DDS.
|
protected abstract File |
doGetOutputFile()
Abstract method that subclasses must provide to identify the output file for the post-processor's retrieval
content.
|
protected Object |
getFileLock()
Returns an object that can be used to synchronize writing to the output file.
|
protected File |
getOutputFile()
Determines and returns the output file for the retrieved data.
|
Retriever |
getRetriever()
Returns the retriever associarted with this post-processor.
|
protected ByteBuffer |
handleApplicationContent()
Handles application content.
|
protected ByteBuffer |
handleContent()
Process the retrieved data.
|
protected void |
handleContentException(Exception e)
Reacts to exceptions occurring during content handling.
|
protected ByteBuffer |
handleHTMLContent()
Handles HTML content.
|
protected ByteBuffer |
handleImageContent()
Handles image content.
|
protected void |
handleInvalidResponseCode()
Handle the case of an invalid response code.
|
protected ByteBuffer |
handleSuccessfulRetrieval()
Process the retrieved data if it has been retrieved successfully.
|
protected ByteBuffer |
handleTextContent()
Handles Text content.
|
protected ByteBuffer |
handleUnknownContentType()
Handles content types that are not recognized by the content handler.
|
protected void |
handleUnsuccessfulRetrieval()
Called when the retrieval state is other than
Retriever.RETRIEVER_STATE_SUCCESSFUL . |
protected ByteBuffer |
handleWMSExceptionContent()
Handles WMS exceptions.
|
protected ByteBuffer |
handleXMLContent()
Handles XML content.
|
protected ByteBuffer |
handleZipContent()
Handles zipped content.
|
protected boolean |
isDeleteOnExit(File outFile)
Indicates whether the output file should have its delete-on-exit flag set so that it's deleted when the JVM
terminates.
|
protected boolean |
isPrimaryContentType(String typeOfContent,
String contentType) |
protected boolean |
isWMSException() |
protected void |
logTextBuffer(ByteBuffer buffer)
Log the content of a buffer as a String.
|
protected void |
markResourceAbsent()
Marks the retrieval target absent.
|
protected boolean |
overwriteExistingFile()
Indicates whether the retrieved data should be written to the output file if a file of the same name already
exists.
|
ByteBuffer |
run(Retriever retriever)
Runs the post-processor.
|
protected boolean |
saveBuffer()
Saves the retrieved and possibly transformed data.
|
protected boolean |
saveBuffer(ByteBuffer buffer)
Saves the retrieved and possibly transformed data.
|
protected ByteBuffer |
saveDDS()
Saves a DDS image file after first converting any other image format to DDS.
|
protected BufferedImage |
transformPixels()
Transform the retrieved data in some purpose-specific way.
|
protected boolean |
validateHTTPResponseCode()
Checks the retrieval's HTTP response code.
|
protected boolean |
validateJarResponseCode()
Checks the retrieval's HTTP response code.
|
protected boolean |
validateResponseCode()
Checks the retrieval response code.
|
protected AVList avList
protected Retriever retriever
run(Retriever)
is called.public AbstractRetrievalPostProcessor()
public AbstractRetrievalPostProcessor(AVList avList)
avList
- an attribute-value list with values that might be used during post-processing.protected ByteBuffer convertToDDS() throws IOException
transformPixels()
to perform
any defined image transform.IOException
- if an IO error occurs while converting the image.protected abstract File doGetOutputFile()
protected Object getFileLock()
protected File getOutputFile()
public Retriever getRetriever()
protected ByteBuffer handleApplicationContent() throws IOException
saveBuffer()
without.IOException
- if an IO error occurs while processing the data.protected ByteBuffer handleContent() throws IOException
handleZipContent()
for content types containing "zip", handleTextContent()
for content types starting
with "text", and handleImageContent()
for contents types starting with "image".IOException
- if an IO error occurs while processing the data.protected void handleContentException(Exception e)
e
- the exception to handle.protected ByteBuffer handleHTMLContent() throws IOException
logTextBuffer(java.nio.ByteBuffer)
and
returns.IOException
- if an IO error occurs while processing the data.protected ByteBuffer handleImageContent() throws IOException
saveBuffer()
,
first converting it to DDS if the suffix of the output file is .dds.
The default implementation of this method returns immediately if the output file cannot be determined or it
exists and overwriteExistingFile()
returns false.IOException
- if an IO error occurs while processing the data.protected void handleInvalidResponseCode()
markResourceAbsent()
and logs the contents of the retrieval buffer if it
contains content of type "text".protected ByteBuffer handleSuccessfulRetrieval()
protected ByteBuffer handleTextContent() throws IOException
handleXMLContent()
is called. If the content type
is text/html, handleHTMLContent()
is called. For all other sub-types the content is logged as a message
with level Level.SEVERE
.IOException
- if an IO error occurs while processing the data.protected ByteBuffer handleUnknownContentType()
protected void handleUnsuccessfulRetrieval()
Retriever.RETRIEVER_STATE_SUCCESSFUL
. Can be overridden by
subclasses to handle special error cases. The default implementation calls markResourceAbsent()
if the
retrieval state is Retriever.RETRIEVER_STATE_ERROR
.protected ByteBuffer handleWMSExceptionContent()
protected ByteBuffer handleXMLContent() throws IOException
logTextBuffer(java.nio.ByteBuffer)
and
returns.IOException
- if an IO error occurs while processing the data.protected ByteBuffer handleZipContent() throws IOException
IOException
- if an IO error occurs while processing the data.protected boolean isDeleteOnExit(File outFile)
outFile
- the output file.protected boolean isPrimaryContentType(String typeOfContent, String contentType)
protected boolean isWMSException()
protected void logTextBuffer(ByteBuffer buffer)
buffer
- the content to log. The content is assumed to be of type "text".protected void markResourceAbsent()
protected boolean overwriteExistingFile()
public ByteBuffer run(Retriever retriever)
run
in interface RetrievalPostProcessor
retriever
- the retriever to associate with the post-processor.IllegalArgumentException
- if the retriever is null.protected boolean saveBuffer() throws IOException
saveBuffer(java.nio.ByteBuffer)
with an argument
of null.IOException
- if an IO error occurs while attempting to save the buffer.protected boolean saveBuffer(ByteBuffer buffer) throws IOException
overwriteExistingFile()
returns true.buffer
- the buffer to save.IOException
- if an IO error occurred when attempting to save the buffer.protected ByteBuffer saveDDS() throws IOException
IOException
- if an IO error occurs while converting or saving the image.protected BufferedImage transformPixels()
ImageUtil.mapTransparencyColors(java.awt.image.BufferedImage,
int[])
if the attribute-value list specified at construction contains transparency colors (includes the AVKey.TRANSPARENCY_COLORS
key).protected boolean validateHTTPResponseCode()
HTTPRetriever
.HttpURLConnection.HTTP_OK
, otherwise false.protected boolean validateJarResponseCode()
HTTPRetriever
.HttpURLConnection.HTTP_OK
, otherwise false.protected boolean validateResponseCode()
HttpURLConnection.HTTP_OK
for
HTTP protocol), otherwise false.