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 long
beginTime
protected java.nio.ByteBuffer
byteBuffer
protected java.net.URLConnection
connection
protected int
connectTimeout
protected int
contentLength
protected java.util.concurrent.atomic.AtomicInteger
contentLengthRead
protected java.lang.String
contentType
protected long
endTime
protected java.util.concurrent.atomic.AtomicLong
expiration
static java.lang.String
EXTRACT_ZIP_ENTRY
Applications never need to use this constant.protected RetrievalPostProcessor
postProcessor
protected int
readTimeout
protected int
staleRequestLimit
protected java.lang.String
state
protected long
submitTime
protected java.net.URL
url
-
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 Retriever
call()
protected void
configureSSLContext(javax.net.ssl.HttpsURLConnection connection)
static URLRetriever
createRetriever(java.net.URL url, RetrievalPostProcessor postProcessor)
Create the appropriate retriever for a URL's protocol.protected java.nio.ByteBuffer
doRead(java.net.URLConnection connection)
protected void
end()
boolean
equals(java.lang.Object o)
long
getBeginTime()
java.nio.ByteBuffer
getBuffer()
protected java.net.URLConnection
getConnection()
int
getConnectTimeout()
int
getContentLength()
int
getContentLengthRead()
java.lang.String
getContentType()
long
getEndTime()
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.long
getExpirationTime()
Indicates the expiration time of the resource retrieved by this Retriever.java.lang.String
getName()
RetrievalPostProcessor
getPostProcessor()
int
getReadTimeout()
int
getStaleRequestLimit()
java.lang.String
getState()
long
getSubmitTime()
java.net.URL
getUrl()
java.net.URL
getURL()
int
hashCode()
protected boolean
interrupted()
protected java.net.URLConnection
openConnection()
protected java.nio.ByteBuffer
read()
protected java.nio.ByteBuffer
readNonSpecificStream(java.io.InputStream inputStream, java.net.URLConnection connection)
protected java.nio.ByteBuffer
readNonSpecificStreamUnknownLength(java.io.InputStream inputStream)
protected java.nio.ByteBuffer
readZipStream(java.io.InputStream inputStream, java.net.URL url)
void
setBeginTime(long beginTime)
void
setConnectTimeout(int connectTimeout)
protected void
setContentLengthRead(int length)
void
setEndTime(long endTime)
void
setReadTimeout(int readTimeout)
void
setStaleRequestLimit(int staleRequestLimit)
protected void
setState(java.lang.String state)
void
setSubmitTime(long submitTime)
java.lang.String
toString()
-
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:
getContentLength
in interfaceRetriever
-
setContentLengthRead
protected void setContentLengthRead(int length)
-
getContentLengthRead
public final int getContentLengthRead()
- Specified by:
getContentLengthRead
in interfaceRetriever
-
getContentType
public final java.lang.String getContentType()
- Specified by:
getContentType
in 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:
getExpirationTime
in 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:
getConnectTimeout
in interfaceRetriever
-
getReadTimeout
public int getReadTimeout()
- Specified by:
getReadTimeout
in interfaceRetriever
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Specified by:
setReadTimeout
in interfaceRetriever
-
getStaleRequestLimit
public int getStaleRequestLimit()
- Specified by:
getStaleRequestLimit
in interfaceRetriever
-
setStaleRequestLimit
public void setStaleRequestLimit(int staleRequestLimit)
- Specified by:
setStaleRequestLimit
in interfaceRetriever
-
setConnectTimeout
public final void setConnectTimeout(int connectTimeout)
- Specified by:
setConnectTimeout
in interfaceRetriever
-
getSubmitTime
public long getSubmitTime()
- Specified by:
getSubmitTime
in interfaceRetriever
-
setSubmitTime
public void setSubmitTime(long submitTime)
- Specified by:
setSubmitTime
in interfaceRetriever
-
getBeginTime
public long getBeginTime()
- Specified by:
getBeginTime
in interfaceRetriever
-
setBeginTime
public void setBeginTime(long beginTime)
- Specified by:
setBeginTime
in interfaceRetriever
-
getEndTime
public long getEndTime()
- Specified by:
getEndTime
in interfaceRetriever
-
setEndTime
public void setEndTime(long endTime)
- Specified by:
setEndTime
in interfaceRetriever
-
call
public final Retriever call() throws java.lang.Exception
- Specified by:
call
in 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
- ifconnection
is null or an exception occurs during reading.java.lang.IllegalArgumentException
- ifconnection
is 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
- ifinputStream
is 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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-