Class InputStreamRequestBody

java.lang.Object
okhttp3.RequestBody
com.langfuse.client.core.InputStreamRequestBody

public class InputStreamRequestBody extends okhttp3.RequestBody
A custom implementation of OkHttp's RequestBody that wraps an InputStream. This class allows streaming of data from an InputStream directly to an HTTP request body, which is useful for file uploads or sending large amounts of data without loading it all into memory.
  • Nested Class Summary

    Nested classes/interfaces inherited from class okhttp3.RequestBody

    okhttp3.RequestBody.Companion
  • Field Summary

    Fields inherited from class okhttp3.RequestBody

    Companion
  • Constructor Summary

    Constructors
    Constructor
    Description
    InputStreamRequestBody(okhttp3.MediaType contentType, InputStream inputStream)
    Constructs an InputStreamRequestBody with the specified content type and input stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the content length of this request body, if known.
    okhttp3.MediaType
    Returns the content type of this request body.
    void
    writeTo(okio.BufferedSink sink)
    Writes the content of the InputStream to the given BufferedSink.

    Methods inherited from class okhttp3.RequestBody

    create, create, create, create, create, create, create, create, create, create, create, create, create, isDuplex, isOneShot

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InputStreamRequestBody

      public InputStreamRequestBody(@Nullable okhttp3.MediaType contentType, InputStream inputStream)
      Constructs an InputStreamRequestBody with the specified content type and input stream.
      Parameters:
      contentType - the MediaType of the content, or null if not known
      inputStream - the InputStream containing the data to be sent
      Throws:
      NullPointerException - if inputStream is null
  • Method Details

    • contentType

      @Nullable public okhttp3.MediaType contentType()
      Returns the content type of this request body.
      Specified by:
      contentType in class okhttp3.RequestBody
      Returns:
      the MediaType of the content, or null if not specified
    • contentLength

      public long contentLength() throws IOException
      Returns the content length of this request body, if known. This method attempts to determine the length using the InputStream's available() method, which may not always accurately reflect the total length of the stream.
      Overrides:
      contentLength in class okhttp3.RequestBody
      Returns:
      the content length, or -1 if the length is unknown
      Throws:
      IOException - if an I/O error occurs
    • writeTo

      public void writeTo(okio.BufferedSink sink) throws IOException
      Writes the content of the InputStream to the given BufferedSink. This method is responsible for transferring the data from the InputStream to the network request.
      Specified by:
      writeTo in class okhttp3.RequestBody
      Parameters:
      sink - the BufferedSink to write the content to
      Throws:
      IOException - if an I/O error occurs during writing