public abstract class AbstractRetrievalPostProcessor extends java.lang.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 java.nio.ByteBuffer |
convertToDDS()
Converts an image to DDS.
|
protected abstract java.io.File |
doGetOutputFile()
Abstract method that subclasses must provide to identify the output file for the post-processor's retrieval
content.
|
protected java.lang.Object |
getFileLock()
Returns an object that can be used to synchronize writing to the output file.
|
protected java.io.File |
getOutputFile()
Determines and returns the output file for the retrieved data.
|
Retriever |
getRetriever()
Returns the retriever associarted with this post-processor.
|
protected java.nio.ByteBuffer |
handleApplicationContent()
Handles application content.
|
protected java.nio.ByteBuffer |
handleContent()
Process the retrieved data.
|
protected void |
handleContentException(java.lang.Exception e)
Reacts to exceptions occurring during content handling.
|
protected java.nio.ByteBuffer |
handleHTMLContent()
Handles HTML content.
|
protected java.nio.ByteBuffer |
handleImageContent()
Handles image content.
|
protected void |
handleInvalidResponseCode()
Handle the case of an invalid response code.
|
protected java.nio.ByteBuffer |
handleSuccessfulRetrieval()
Process the retrieved data if it has been retrieved successfully.
|
protected java.nio.ByteBuffer |
handleTextContent()
Handles Text content.
|
protected java.nio.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 java.nio.ByteBuffer |
handleWMSExceptionContent()
Handles WMS exceptions.
|
protected java.nio.ByteBuffer |
handleXMLContent()
Handles XML content.
|
protected java.nio.ByteBuffer |
handleZipContent()
Handles zipped content.
|
protected boolean |
isDeleteOnExit(java.io.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(java.lang.String typeOfContent,
java.lang.String contentType) |
protected boolean |
isWMSException() |
protected void |
logTextBuffer(java.nio.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.
|
java.nio.ByteBuffer |
run(Retriever retriever)
Runs the post-processor.
|
protected boolean |
saveBuffer()
Saves the retrieved and possibly transformed data.
|
protected boolean |
saveBuffer(java.nio.ByteBuffer buffer)
Saves the retrieved and possibly transformed data.
|
protected java.nio.ByteBuffer |
saveDDS()
Saves a DDS image file after first converting any other image format to DDS.
|
protected java.awt.image.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 java.nio.ByteBuffer convertToDDS() throws java.io.IOException
transformPixels()
to perform
any defined image transform.java.io.IOException
- if an IO error occurs while converting the image.protected abstract java.io.File doGetOutputFile()
protected java.lang.Object getFileLock()
protected java.io.File getOutputFile()
public Retriever getRetriever()
protected java.nio.ByteBuffer handleApplicationContent() throws java.io.IOException
saveBuffer()
without.java.io.IOException
- if an IO error occurs while processing the data.protected java.nio.ByteBuffer handleContent() throws java.io.IOException
handleZipContent()
for content types containing "zip", handleTextContent()
for content types starting
with "text", and handleImageContent()
for contents types starting with "image".java.io.IOException
- if an IO error occurs while processing the data.protected void handleContentException(java.lang.Exception e)
e
- the exception to handle.protected java.nio.ByteBuffer handleHTMLContent() throws java.io.IOException
logTextBuffer(java.nio.ByteBuffer)
and
returns.java.io.IOException
- if an IO error occurs while processing the data.protected java.nio.ByteBuffer handleImageContent() throws java.io.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.java.io.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 java.nio.ByteBuffer handleSuccessfulRetrieval()
protected java.nio.ByteBuffer handleTextContent() throws java.io.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
.java.io.IOException
- if an IO error occurs while processing the data.protected java.nio.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 java.nio.ByteBuffer handleWMSExceptionContent()
protected java.nio.ByteBuffer handleXMLContent() throws java.io.IOException
logTextBuffer(java.nio.ByteBuffer)
and
returns.java.io.IOException
- if an IO error occurs while processing the data.protected java.nio.ByteBuffer handleZipContent() throws java.io.IOException
java.io.IOException
- if an IO error occurs while processing the data.protected boolean isDeleteOnExit(java.io.File outFile)
outFile
- the output file.protected boolean isPrimaryContentType(java.lang.String typeOfContent, java.lang.String contentType)
protected boolean isWMSException()
protected void logTextBuffer(java.nio.ByteBuffer buffer)
buffer
- the content to log. The content is assumed to be of type "text".protected void markResourceAbsent()
protected boolean overwriteExistingFile()
public java.nio.ByteBuffer run(Retriever retriever)
run
in interface RetrievalPostProcessor
retriever
- the retriever to associate with the post-processor.java.lang.IllegalArgumentException
- if the retriever is null.protected boolean saveBuffer() throws java.io.IOException
saveBuffer(java.nio.ByteBuffer)
with an argument
of null.java.io.IOException
- if an IO error occurs while attempting to save the buffer.protected boolean saveBuffer(java.nio.ByteBuffer buffer) throws java.io.IOException
overwriteExistingFile()
returns true.buffer
- the buffer to save.java.io.IOException
- if an IO error occurred when attempting to save the buffer.protected java.nio.ByteBuffer saveDDS() throws java.io.IOException
java.io.IOException
- if an IO error occurs while converting or saving the image.protected java.awt.image.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.