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 HttpURLConnectionHttpURLConnectionto allow the caller to access HTTP resposne headers.protected final ProxyProxy, or null none is explicitly given (Java runtime may still decide to use a proxy, though.)protected intNumber of bytes read so far.final intTotal bytes of the entity.final URLWhere 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 HttpURLConnectionconnect()Opens the URL and makes a connection.intread()intread(byte[] b, int off, int len) protected voidSubclass 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
HttpURLConnectionto 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:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-