Package gov.nasa.worldwind.retrieve
Class URLRetriever
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.retrieve.URLRetriever
-
- All Implemented Interfaces:
AVList,MessageListener,Retriever,WWObject,java.beans.PropertyChangeListener,java.util.concurrent.Callable<Retriever>,java.util.EventListener
- Direct Known Subclasses:
HTTPRetriever,JarRetriever
public abstract class URLRetriever extends WWObjectImpl implements Retriever
-
-
Field Summary
Fields Modifier and Type Field Description protected longbeginTimeprotected java.nio.ByteBufferbyteBufferprotected java.net.URLConnectionconnectionprotected intconnectTimeoutprotected intcontentLengthprotected java.util.concurrent.atomic.AtomicIntegercontentLengthReadprotected java.lang.StringcontentTypeprotected longendTimeprotected java.util.concurrent.atomic.AtomicLongexpirationstatic java.lang.StringEXTRACT_ZIP_ENTRYApplications never need to use this constant.protected RetrievalPostProcessorpostProcessorprotected intreadTimeoutprotected intstaleRequestLimitprotected java.lang.Stringstateprotected longsubmitTimeprotected java.net.URLurl-
Fields inherited from interface gov.nasa.worldwind.retrieve.Retriever
RETRIEVER_STATE_CONNECTING, RETRIEVER_STATE_ERROR, RETRIEVER_STATE_INTERRUPTED, RETRIEVER_STATE_NOT_STARTED, RETRIEVER_STATE_READING, RETRIEVER_STATE_STARTED, RETRIEVER_STATE_SUCCESSFUL
-
-
Constructor Summary
Constructors Constructor Description URLRetriever(java.net.URL url, RetrievalPostProcessor postProcessor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Retrievercall()protected voidconfigureSSLContext(javax.net.ssl.HttpsURLConnection connection)static URLRetrievercreateRetriever(java.net.URL url, RetrievalPostProcessor postProcessor)Create the appropriate retriever for a URL's protocol.protected java.nio.ByteBufferdoRead(java.net.URLConnection connection)protected voidend()booleanequals(java.lang.Object o)longgetBeginTime()java.nio.ByteBuffergetBuffer()protected java.net.URLConnectiongetConnection()intgetConnectTimeout()intgetContentLength()intgetContentLengthRead()java.lang.StringgetContentType()longgetEndTime()protected longgetExpiration(java.net.URLConnection connection)Indicates the expiration time specified by either the Expires header or the max-age directive of the Cache-Control header.longgetExpirationTime()Indicates the expiration time of the resource retrieved by this Retriever.java.lang.StringgetName()RetrievalPostProcessorgetPostProcessor()intgetReadTimeout()intgetStaleRequestLimit()java.lang.StringgetState()longgetSubmitTime()java.net.URLgetUrl()java.net.URLgetURL()inthashCode()protected booleaninterrupted()protected java.net.URLConnectionopenConnection()protected java.nio.ByteBufferread()protected java.nio.ByteBufferreadNonSpecificStream(java.io.InputStream inputStream, java.net.URLConnection connection)protected java.nio.ByteBufferreadNonSpecificStreamUnknownLength(java.io.InputStream inputStream)protected java.nio.ByteBufferreadZipStream(java.io.InputStream inputStream, java.net.URL url)voidsetBeginTime(long beginTime)voidsetConnectTimeout(int connectTimeout)protected voidsetContentLengthRead(int length)voidsetEndTime(long endTime)voidsetReadTimeout(int readTimeout)voidsetStaleRequestLimit(int staleRequestLimit)protected voidsetState(java.lang.String state)voidsetSubmitTime(long submitTime)java.lang.StringtoString()-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
-
-
-
-
Field Detail
-
EXTRACT_ZIP_ENTRY
public static final java.lang.String EXTRACT_ZIP_ENTRY
Applications never need to use this constant. It provides compatibility with very old WorldWind tile servers that deliver zipped content without identifying the content type as other than application/zip. In these cases, the object requesting the content must know the content type to expect, and also requires that the zip file be opened and only its first entry returned.- See Also:
- Constant Field Values
-
state
protected volatile java.lang.String state
-
contentLength
protected volatile int contentLength
-
contentLengthRead
protected java.util.concurrent.atomic.AtomicInteger contentLengthRead
-
contentType
protected volatile java.lang.String contentType
-
expiration
protected java.util.concurrent.atomic.AtomicLong expiration
-
byteBuffer
protected volatile java.nio.ByteBuffer byteBuffer
-
connection
protected volatile java.net.URLConnection connection
-
url
protected final java.net.URL url
-
postProcessor
protected final RetrievalPostProcessor postProcessor
-
connectTimeout
protected int connectTimeout
-
readTimeout
protected int readTimeout
-
staleRequestLimit
protected int staleRequestLimit
-
submitTime
protected long submitTime
-
beginTime
protected long beginTime
-
endTime
protected long endTime
-
-
Constructor Detail
-
URLRetriever
public URLRetriever(java.net.URL url, RetrievalPostProcessor postProcessor)- Parameters:
url- the URL of the resource to retrieve.postProcessor- the retrieval post-processor to invoke when the resource is retrieved. May be null.- Throws:
java.lang.IllegalArgumentException- ifurl.
-
-
Method Detail
-
createRetriever
public static URLRetriever createRetriever(java.net.URL url, RetrievalPostProcessor postProcessor)
Create the appropriate retriever for a URL's protocol.- Parameters:
url- the url that will be the source of the retrieval.postProcessor- the retriever's post-processor.- Returns:
- a retriever for the protocol specified in the url, or null if no retriever exists for the protocol.
- Throws:
java.lang.IllegalArgumentException- if the url is null.
-
getUrl
public final java.net.URL getUrl()
-
getContentLength
public final int getContentLength()
- Specified by:
getContentLengthin interfaceRetriever
-
setContentLengthRead
protected void setContentLengthRead(int length)
-
getContentLengthRead
public final int getContentLengthRead()
- Specified by:
getContentLengthReadin interfaceRetriever
-
getContentType
public final java.lang.String getContentType()
- Specified by:
getContentTypein interfaceRetriever
-
getExpirationTime
public long getExpirationTime()
Indicates the expiration time of the resource retrieved by this Retriever. Expiration time is determined by either the Expires header, or the max-age directive of the Cache-Control header. Cache-Control has priority if both headers are specified (see section 14.9.3 of the HTTP Specification).- Specified by:
getExpirationTimein interfaceRetriever- Returns:
- The expiration time of the resource, in milliseconds since the Epoch (January 1, 1970, 00:00:00 GMT). Zero indicates that there is no expiration time.
-
getBuffer
public final java.nio.ByteBuffer getBuffer()
-
getURL
public final java.net.URL getURL()
-
getConnection
protected final java.net.URLConnection getConnection()
-
getPostProcessor
public final RetrievalPostProcessor getPostProcessor()
-
getConnectTimeout
public final int getConnectTimeout()
- Specified by:
getConnectTimeoutin interfaceRetriever
-
getReadTimeout
public int getReadTimeout()
- Specified by:
getReadTimeoutin interfaceRetriever
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Specified by:
setReadTimeoutin interfaceRetriever
-
getStaleRequestLimit
public int getStaleRequestLimit()
- Specified by:
getStaleRequestLimitin interfaceRetriever
-
setStaleRequestLimit
public void setStaleRequestLimit(int staleRequestLimit)
- Specified by:
setStaleRequestLimitin interfaceRetriever
-
setConnectTimeout
public final void setConnectTimeout(int connectTimeout)
- Specified by:
setConnectTimeoutin interfaceRetriever
-
getSubmitTime
public long getSubmitTime()
- Specified by:
getSubmitTimein interfaceRetriever
-
setSubmitTime
public void setSubmitTime(long submitTime)
- Specified by:
setSubmitTimein interfaceRetriever
-
getBeginTime
public long getBeginTime()
- Specified by:
getBeginTimein interfaceRetriever
-
setBeginTime
public void setBeginTime(long beginTime)
- Specified by:
setBeginTimein interfaceRetriever
-
getEndTime
public long getEndTime()
- Specified by:
getEndTimein interfaceRetriever
-
setEndTime
public void setEndTime(long endTime)
- Specified by:
setEndTimein interfaceRetriever
-
call
public final Retriever call() throws java.lang.Exception
- Specified by:
callin interfacejava.util.concurrent.Callable<Retriever>- Throws:
java.lang.Exception
-
setState
protected void setState(java.lang.String state)
-
interrupted
protected boolean interrupted()
-
openConnection
protected java.net.URLConnection openConnection() throws java.io.IOException- Throws:
java.io.IOException
-
configureSSLContext
protected void configureSSLContext(javax.net.ssl.HttpsURLConnection connection)
-
end
protected void end() throws java.lang.Exception- Throws:
java.lang.Exception
-
read
protected java.nio.ByteBuffer read() throws java.lang.Exception- Throws:
java.lang.Exception
-
doRead
protected java.nio.ByteBuffer doRead(java.net.URLConnection connection) throws java.lang.Exception- Parameters:
connection- the connection to read from.- Returns:
- a buffer containing the content read from the connection
- Throws:
java.lang.Exception- ifconnectionis null or an exception occurs during reading.java.lang.IllegalArgumentException- ifconnectionis null
-
readNonSpecificStream
protected java.nio.ByteBuffer readNonSpecificStream(java.io.InputStream inputStream, java.net.URLConnection connection) throws java.io.IOException- Throws:
java.io.IOException
-
readNonSpecificStreamUnknownLength
protected java.nio.ByteBuffer readNonSpecificStreamUnknownLength(java.io.InputStream inputStream) throws java.io.IOException- Throws:
java.io.IOException
-
readZipStream
protected java.nio.ByteBuffer readZipStream(java.io.InputStream inputStream, java.net.URL url) throws java.io.IOException- Parameters:
inputStream- a stream to the zip connection.url- the URL of the zip resource.- Returns:
- a buffer containing the content read from the zip stream.
- Throws:
java.io.IOException- if the stream does not refer to a zip resource or an exception occurs during reading.java.lang.IllegalArgumentException- ifinputStreamis null
-
getExpiration
protected long getExpiration(java.net.URLConnection connection)
Indicates the expiration time specified by either the Expires header or the max-age directive of the Cache-Control header. If both are present, then Cache-Control is given priority (See section 14.9.3 of the HTTP Specification: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).If both the Expires and Date headers are present then the expiration time is calculated as current time + (expires - date). This helps guard against clock skew between the client and server.
- Parameters:
connection- Connection for which to get expiration time.- Returns:
- The expiration time, in milliseconds since the Epoch, specified by the HTTP headers, or zero if there is no expiration time.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-