org.jvnet.robust_http_client
public class RetryableHttpStream extends java.io.InputStream
InputStream
implementation around HttpURLConnection
that automatically reconnects
if the connection fails in the middle.Modifier and Type | Field and Description |
---|---|
java.net.HttpURLConnection |
connection
HttpURLConnection to allow the caller to access HTTP resposne headers. |
protected java.net.Proxy |
proxy
Proxy, or null none is explicitly given (Java runtime may still decide to use a proxy, though.)
|
protected int |
read
Number of bytes read so far.
|
int |
totalLength
Total bytes of the entity.
|
java.net.URL |
url
Where are we downloading from?
|
Constructor and Description |
---|
RetryableHttpStream(java.net.URL url)
Connects to the given HTTP/HTTPS URL, by using the proxy auto-configured by the Java runtime.
|
RetryableHttpStream(java.net.URL url,
java.net.Proxy proxy)
Connects to the given HTTP/HTTPS URL, by using the specified proxy.
|
Modifier and Type | Method and Description |
---|---|
protected java.net.HttpURLConnection |
connect()
Opens the URL and makes a connection.
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
protected void |
shallWeRetry()
Subclass can override this method to determine if we should continue to retry, or abort.
|
public final java.net.URL url
protected final java.net.Proxy proxy
public final int totalLength
protected int read
public final java.net.HttpURLConnection connection
HttpURLConnection
to allow the caller to access HTTP resposne headers.
Do not use URLConnection.getInputStream()
, however.public RetryableHttpStream(java.net.URL url) throws java.io.IOException
java.io.IOException
public RetryableHttpStream(java.net.URL url, java.net.Proxy proxy) throws java.io.IOException
proxy
- To force a direct connection, pass in Proxy.NO_PROXY
.java.io.IOException
protected java.net.HttpURLConnection connect() throws java.io.IOException
java.io.IOException
protected void shallWeRetry() throws java.io.IOException
If this method returns normally, we'll retry. By default, this method retries 5 times then quits.
java.io.IOException
- to abort the processing.public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
Copyright © 2014. All Rights Reserved.