uk.ac.starlink.hapi

## Class ChunkStreamer

- java.lang.Object
- - uk.ac.starlink.hapi.ChunkStreamer

-     public class ChunkStreamer
      extends java.lang.Object

  Handles reading HAPI data streams in chunks to cope with data requests that encounter service errors with the status 1408 "Bad Status - too much time or data requested".
  Since:
    26 Jan 2024

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ChunkStreamer(HapiService service, int chunkLimit, IOConsumer<java.lang.String> limitCallback)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getChunkLimit()` Returns the largest number of chunks that this streamer is prepared to request for a given download.
    `java.io.InputStream` | `openMultiChunkStream(java.net.URL requestUrl)` Returns an input stream corresponding to the supplied HAPI data request URL, but which may be assembled from the concatenation of multiple actual requests to the service.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ChunkStreamer

          public ChunkStreamer(HapiService service,
                               int chunkLimit,
                               IOConsumer<java.lang.String> limitCallback)

      Constructor.

      A limit must be supplied for the maximum number of chunks that will be retrieved for a given request. If this limit is exceeded, the supplied callback object, if any, will be called and the stream will terminate. If the callback throws an IOException, it will be encountered by the code reading the stream.

      Parameters:
        `service` - service to which requests will be made
        `chunkLimit` - maximum number of chunks that a data stream will include
        `limitCallback` - called with a failure message if chunk limit is exceeded; may be null

  - ### Method Detail

    - #### getChunkLimit

          public int getChunkLimit()

      Returns the largest number of chunks that this streamer is prepared to request for a given download.
      Returns:
        chunk limit

    - #### openMultiChunkStream

          public java.io.InputStream openMultiChunkStream(java.net.URL requestUrl)
                                                   throws java.io.IOException

      Returns an input stream corresponding to the supplied HAPI data request URL, but which may be assembled from the concatenation of multiple actual requests to the service.
      Parameters:
        `requestUrl` - data request URL
      Returns:
        input stream containing all data in requested range, subject to chunk limit
      Throws:
        `java.io.IOException`