Class ResponseBodyReader

java.lang.Object
java.io.Reader
java.io.FilterReader
com.langfuse.client.core.ResponseBodyReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class ResponseBodyReader extends FilterReader
A custom Reader that wraps the Reader from the OkHttp Response and ensures that the OkHttp Response object is properly closed when the reader is closed. This class extends FilterReader and takes an OkHttp Response object as a parameter. It retrieves the Reader from the Response and overrides the close method to close both the Reader and the Response object, ensuring proper resource management and preventing premature closure of the underlying HTTP connection.
  • Constructor Details

    • ResponseBodyReader

      public ResponseBodyReader(okhttp3.Response response) throws IOException
      Constructs a ResponseBodyReader that wraps the Reader from the given OkHttp Response object.
      Parameters:
      response - the OkHttp Response object from which the Reader is retrieved
      Throws:
      IOException - if an I/O error occurs while retrieving the Reader
  • Method Details

    • close

      public void close() throws IOException
      Closes the Reader and the associated OkHttp Response object. This ensures that the underlying HTTP connection is properly closed after the reader is no longer needed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterReader
      Throws:
      IOException - if an I/O error occurs