NASA World Wind

gov.nasa.worldwind.retrieve
Class URLRetriever

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.retrieve.URLRetriever
All Implemented Interfaces:
AVList, MessageListener, Retriever, WWObject, PropertyChangeListener, Callable<Retriever>, EventListener
Direct Known Subclasses:
HTTPRetriever, JarRetriever

public abstract class URLRetriever
extends WWObjectImpl
implements Retriever


Field Summary
protected  long beginTime
           
protected  ByteBuffer byteBuffer
           
protected  URLConnection connection
           
protected  int connectTimeout
           
protected  int contentLength
           
protected  AtomicInteger contentLengthRead
           
protected  String contentType
           
protected  long endTime
           
protected  AtomicLong expiration
           
static String EXTRACT_ZIP_ENTRY
          Applications never need to use this constant.
protected  RetrievalPostProcessor postProcessor
           
protected  int readTimeout
           
protected  int staleRequestLimit
           
protected  String state
           
protected  long submitTime
           
protected  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
URLRetriever(URL url, RetrievalPostProcessor postProcessor)
           
 
Method Summary
 Retriever call()
           
protected  void configureSSLContext(HttpsURLConnection connection)
           
static URLRetriever createRetriever(URL url, RetrievalPostProcessor postProcessor)
          Create the appropriate retriever for a URL's protocol.
protected  ByteBuffer doRead(URLConnection connection)
           
protected  void end()
           
 boolean equals(Object o)
           
 long getBeginTime()
           
 ByteBuffer getBuffer()
           
protected  URLConnection getConnection()
           
 int getConnectTimeout()
           
 int getContentLength()
           
 int getContentLengthRead()
           
 String getContentType()
           
 long getEndTime()
           
protected  long getExpiration(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.
 String getName()
           
 RetrievalPostProcessor getPostProcessor()
           
 int getReadTimeout()
           
 int getStaleRequestLimit()
           
 String getState()
           
 long getSubmitTime()
           
 URL getUrl()
           
 URL getURL()
           
 int hashCode()
           
protected  boolean interrupted()
           
protected  URLConnection openConnection()
           
protected  ByteBuffer read()
           
protected  ByteBuffer readNonSpecificStream(InputStream inputStream, URLConnection connection)
           
protected  ByteBuffer readNonSpecificStreamUnknownLength(InputStream inputStream)
           
protected  ByteBuffer readZipStream(InputStream inputStream, 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(String state)
           
 void setSubmitTime(long submitTime)
           
 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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
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 java.beans.PropertyChangeListener
propertyChange
 
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
 

Field Detail

beginTime

protected long beginTime

byteBuffer

protected volatile ByteBuffer byteBuffer

connection

protected volatile URLConnection connection

connectTimeout

protected int connectTimeout

contentLength

protected volatile int contentLength

contentLengthRead

protected AtomicInteger contentLengthRead

contentType

protected volatile String contentType

endTime

protected long endTime

expiration

protected AtomicLong expiration

EXTRACT_ZIP_ENTRY

public static final String EXTRACT_ZIP_ENTRY
Applications never need to use this constant. It provides compatibility with very old World Wind 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

postProcessor

protected final RetrievalPostProcessor postProcessor

readTimeout

protected int readTimeout

staleRequestLimit

protected int staleRequestLimit

state

protected volatile String state

submitTime

protected long submitTime

url

protected final URL url
Constructor Detail

URLRetriever

public URLRetriever(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:
IllegalArgumentException - if url.
Method Detail

call

public final Retriever call()
                     throws Exception
Specified by:
call in interface Callable<Retriever>
Throws:
Exception

configureSSLContext

protected void configureSSLContext(HttpsURLConnection connection)

createRetriever

public static URLRetriever createRetriever(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:
IllegalArgumentException - if the url is null.

doRead

protected ByteBuffer doRead(URLConnection connection)
                     throws Exception
Parameters:
connection - the connection to read from.
Returns:
a buffer containing the content read from the connection
Throws:
Exception - if connection is null or an exception occurs during reading.
IllegalArgumentException - if connection is null

end

protected void end()
            throws Exception
Throws:
Exception

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getBeginTime

public long getBeginTime()
Specified by:
getBeginTime in interface Retriever

getBuffer

public final ByteBuffer getBuffer()
Specified by:
getBuffer in interface Retriever

getConnection

protected final URLConnection getConnection()

getConnectTimeout

public final int getConnectTimeout()
Specified by:
getConnectTimeout in interface Retriever

getContentLength

public final int getContentLength()
Specified by:
getContentLength in interface Retriever

getContentLengthRead

public final int getContentLengthRead()
Specified by:
getContentLengthRead in interface Retriever

getContentType

public final String getContentType()
Specified by:
getContentType in interface Retriever

getEndTime

public long getEndTime()
Specified by:
getEndTime in interface Retriever

getExpiration

protected long getExpiration(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.

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 interface Retriever
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.

getName

public final String getName()
Specified by:
getName in interface Retriever

getPostProcessor

public final RetrievalPostProcessor getPostProcessor()

getReadTimeout

public int getReadTimeout()
Specified by:
getReadTimeout in interface Retriever

getStaleRequestLimit

public int getStaleRequestLimit()
Specified by:
getStaleRequestLimit in interface Retriever

getState

public final String getState()
Specified by:
getState in interface Retriever

getSubmitTime

public long getSubmitTime()
Specified by:
getSubmitTime in interface Retriever

getUrl

public final URL getUrl()

getURL

public final URL getURL()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

interrupted

protected boolean interrupted()

openConnection

protected URLConnection openConnection()
                                throws IOException
Throws:
IOException

read

protected ByteBuffer read()
                   throws Exception
Throws:
Exception

readNonSpecificStream

protected ByteBuffer readNonSpecificStream(InputStream inputStream,
                                           URLConnection connection)
                                    throws IOException
Throws:
IOException

readNonSpecificStreamUnknownLength

protected ByteBuffer readNonSpecificStreamUnknownLength(InputStream inputStream)
                                                 throws IOException
Throws:
IOException

readZipStream

protected ByteBuffer readZipStream(InputStream inputStream,
                                   URL url)
                            throws 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:
IOException - if the stream does not refer to a zip resource or an exception occurs during reading.
IllegalArgumentException - if inputStream is null

setBeginTime

public void setBeginTime(long beginTime)
Specified by:
setBeginTime in interface Retriever

setConnectTimeout

public final void setConnectTimeout(int connectTimeout)
Specified by:
setConnectTimeout in interface Retriever

setContentLengthRead

protected void setContentLengthRead(int length)

setEndTime

public void setEndTime(long endTime)
Specified by:
setEndTime in interface Retriever

setReadTimeout

public void setReadTimeout(int readTimeout)
Specified by:
setReadTimeout in interface Retriever

setStaleRequestLimit

public void setStaleRequestLimit(int staleRequestLimit)
Specified by:
setStaleRequestLimit in interface Retriever

setState

protected void setState(String state)

setSubmitTime

public void setSubmitTime(long submitTime)
Specified by:
setSubmitTime in interface Retriever

toString

public String toString()
Overrides:
toString in class Object

NASA World Wind