Package org.jvnet.robust_http_client
Class RetryableHttpStream
java.lang.Object
java.io.InputStream
org.jvnet.robust_http_client.RetryableHttpStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
InputStream
implementation around HttpURLConnection
that automatically reconnects
if the connection fails in the middle.- Author:
- Kohsuke Kawaguchi
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal HttpURLConnection
HttpURLConnection
to allow the caller to access HTTP resposne headers.protected final Proxy
Proxy, or null none is explicitly given (Java runtime may still decide to use a proxy, though.)protected int
Number of bytes read so far.final int
Total bytes of the entity.final URL
Where are we downloading from? -
Constructor Summary
ConstructorsConstructorDescriptionRetryableHttpStream
(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected HttpURLConnection
connect()
Opens the URL and makes a connection.int
read()
int
read
(byte[] b, int off, int len) protected void
Subclass can override this method to determine if we should continue to retry, or abort.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
url
Where are we downloading from? -
proxy
Proxy, or null none is explicitly given (Java runtime may still decide to use a proxy, though.) -
totalLength
public final int totalLengthTotal bytes of the entity. -
read
protected int readNumber of bytes read so far. -
connection
HttpURLConnection
to allow the caller to access HTTP resposne headers. Do not useURLConnection.getInputStream()
, however.
-
-
Constructor Details
-
RetryableHttpStream
Connects to the given HTTP/HTTPS URL, by using the proxy auto-configured by the Java runtime.- Throws:
IOException
-
RetryableHttpStream
Connects to the given HTTP/HTTPS URL, by using the specified proxy.- Parameters:
proxy
- To force a direct connection, pass inProxy.NO_PROXY
.- Throws:
IOException
-
-
Method Details
-
connect
Opens the URL and makes a connection.- Throws:
IOException
-
shallWeRetry
Subclass can override this method to determine if we should continue to retry, or abort.If this method returns normally, we'll retry. By default, this method retries 5 times then quits.
- Throws:
IOException
- to abort the processing.
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-