Class MultipartInputStream

All Implemented Interfaces:
AutoCloseable, PollableInputStream, Proxy, AutoCloseable

@Generated("org.javagi.JavaGI") public final class MultipartInputStream extends FilterInputStream implements PollableInputStream

Handles streams of multipart messages.

This adds support for the multipart responses. For handling the multiple parts the user needs to wrap the InputStream obtained by sending the request with a MultipartInputStream and use nextPart(Cancellable) before reading. Responses which are not wrapped will be treated like non-multipart responses.

Note that although MultipartInputStream is a InputStream, you should not read directly from it, and the results are undefined if you do.

  • Constructor Details

    • MultipartInputStream

      public MultipartInputStream(MemorySegment address)
      Create a MultipartInputStream instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • MultipartInputStream

      public MultipartInputStream(Message msg, InputStream baseStream)

      Creates a new MultipartInputStream that wraps the InputStream obtained by sending the Message.

      Reads should not be done directly through this object, use the input streams returned by nextPart(Cancellable) or its async counterpart instead.

      Parameters:
      msg - the SoupMessage the response is related to.
      baseStream - the GInputStream returned by sending the request.
    • MultipartInputStream

      public MultipartInputStream()
      Create a new MultipartInputStream.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the MultipartInputStream class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected MultipartInputStream asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class FilterInputStream
      Returns:
      the instance as if it were its parent type
    • getHeaders

      public @Nullable MessageHeaders getHeaders()

      Obtains the headers for the part currently being processed.

      Note that the MessageHeaders that are returned are owned by the MultipartInputStream and will be replaced when a call is made to nextPart(Cancellable) or its async counterpart, so if keeping the headers is required, a copy must be made.

      Note that if a part had no headers at all an empty MessageHeaders will be returned.

      Returns:
      a SoupMessageHeaders containing the headers for the part currently being processed or null if the headers failed to parse.
    • nextPart

      public @Nullable InputStream nextPart(@Nullable Cancellable cancellable) throws GErrorException

      Obtains an input stream for the next part.

      When dealing with a multipart response the input stream needs to be wrapped in a MultipartInputStream and this function or its async counterpart need to be called to obtain the first part for reading.

      After calling this function, getHeaders() can be used to obtain the headers for the first part. A read of 0 bytes indicates the end of the part; a new call to this function should be done at that point, to obtain the next part.

      error will only be set if an error happens during a read, null is a valid return value otherwise.

      Parameters:
      cancellable - a GCancellable
      Returns:
      a new GInputStream, or null if there are no more parts
      Throws:
      GErrorException - see GError
    • nextPartAsync

      public void nextPartAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Obtains a InputStream for the next request.

      See nextPart(Cancellable) for details on the workflow.

      Parameters:
      ioPriority - the I/O priority for the request.
      cancellable - a GCancellable.
      callback - callback to call when request is satisfied.
    • nextPartFinish

      public @Nullable InputStream nextPartFinish(AsyncResult result) throws GErrorException
      Finishes an asynchronous request for the next part.
      Parameters:
      result - a GAsyncResult.
      Returns:
      a newly created InputStream for reading the next part or null if there are no more parts.
      Throws:
      GErrorException - see GError
    • builder

      public static MultipartInputStream.Builder<? extends MultipartInputStream.Builder> builder()
      A MultipartInputStream.Builder object constructs a MultipartInputStream with the specified properties. Use the various set...() methods to set properties, and finish construction with MultipartInputStream.Builder.build().
      Returns:
      the builder object