public class RetryableHttpStream extends InputStream
InputStream
implementation around HttpURLConnection
that automatically reconnects
if the connection fails in the middle.Modifier and Type | Field and Description |
---|---|
HttpURLConnection |
connection
HttpURLConnection to allow the caller to access HTTP resposne headers. |
protected 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.
|
URL |
url
Where are we downloading from?
|
Constructor and Description |
---|
RetryableHttpStream(URL url)
Connects to the given HTTP/HTTPS URL, by using the proxy auto-configured by the Java runtime.
|
RetryableHttpStream(URL url,
Proxy proxy)
Connects to the given HTTP/HTTPS URL, by using the specified proxy.
|
Modifier and Type | Method and Description |
---|---|
protected 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.
|
available, close, mark, markSupported, read, reset, skip
public final URL url
protected final Proxy proxy
public final int totalLength
protected int read
public final HttpURLConnection connection
HttpURLConnection
to allow the caller to access HTTP resposne headers.
Do not use URLConnection.getInputStream()
, however.public RetryableHttpStream(URL url) throws IOException
IOException
public RetryableHttpStream(URL url, Proxy proxy) throws IOException
proxy
- To force a direct connection, pass in Proxy.NO_PROXY
.IOException
protected HttpURLConnection connect() throws IOException
IOException
protected void shallWeRetry() throws IOException
If this method returns normally, we'll retry. By default, this method retries 5 times then quits.
IOException
- to abort the processing.public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
Copyright © 2019. All rights reserved.