Package com.flagright.api.core
Class ResponseBodyInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.flagright.api.core.ResponseBodyInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ResponseBodyInputStream extends java.io.FilterInputStreamA custom InputStream that wraps the InputStream from the OkHttp Response and ensures that the OkHttp Response object is properly closed when the stream is closed. This class extends FilterInputStream and takes an OkHttp Response object as a parameter. It retrieves the InputStream from the Response and overrides the close method to close both the InputStream and the Response object, ensuring proper resource management and preventing premature closure of the underlying HTTP connection.
-
-
Constructor Summary
Constructors Constructor Description ResponseBodyInputStream(okhttp3.Response response)Constructs a ResponseBodyInputStream that wraps the InputStream from the given OkHttp Response object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the InputStream and the associated OkHttp Response object.-
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, read, read, reset, skip
-
-
-
-
Constructor Detail
-
ResponseBodyInputStream
public ResponseBodyInputStream(okhttp3.Response response) throws java.io.IOExceptionConstructs a ResponseBodyInputStream that wraps the InputStream from the given OkHttp Response object.- Parameters:
response- the OkHttp Response object from which the InputStream is retrieved- Throws:
java.io.IOException- if an I/O error occurs while retrieving the InputStream
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionCloses the InputStream and the associated OkHttp Response object. This ensures that the underlying HTTP connection is properly closed after the stream is no longer needed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException- if an I/O error occurs
-
-