Class RemoteBase.HttpClientClosingInputStream
java.lang.Object
java.io.InputStream
org.opencastproject.serviceregistry.api.RemoteBase.HttpClientClosingInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
RemoteBase
A stream wrapper that closes the http response when the stream is closed. If a remote service proxy returns an
inputstream, this implementation should be used to ensure that the http connection is closed properly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InputStreamThe input stream delivering the actual dataprotected org.apache.http.HttpResponseThe http response to close when the stream is closed -
Constructor Summary
ConstructorsConstructorDescriptionHttpClientClosingInputStream(org.apache.http.HttpResponse resp) Constructs an HttpClientClosingInputStream from a source stream and an http response. -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
delegateStream
The input stream delivering the actual data -
httpResponse
protected org.apache.http.HttpResponse httpResponseThe http response to close when the stream is closed
-
-
Constructor Details
-
HttpClientClosingInputStream
public HttpClientClosingInputStream(org.apache.http.HttpResponse resp) throws IllegalStateException, IOException Constructs an HttpClientClosingInputStream from a source stream and an http response.- Throws:
IOExceptionIllegalStateException
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException- See Also:
-
available
- Overrides:
availablein classInputStream- Throws:
IOException- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- See Also:
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream- Parameters:
readlimit-- See Also:
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream- Returns:
- whether this stream supports marking
- See Also:
-
read
- Overrides:
readin classInputStream- Parameters:
b- the buffer into which the data is read.off- the start offset in arraybat which the data is written.len- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of the stream has been reached. - Throws:
IOException- If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.NullPointerException- Ifbisnull.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanb.length - off- See Also:
-
read
- Overrides:
readin classInputStream- Parameters:
b- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1is there is no more data because the end of the stream has been reached. - Throws:
IOException- If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.NullPointerException- ifbisnull.- See Also:
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException- See Also:
-
skip
- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if the stream does not support seek, or if some other I/O error occurs.- See Also:
-
toString
-