YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.share.RangeStreamer Class Reference

Streams the body of a 200 or 206 answer from a PositionalSource: exactly the bytes the ByteRangeResolver.Result names (start() to endInclusive()), in chunks of at most the chunk size, so a large file is never held in memory. More...

Collaboration diagram for de.yaacc.share.RangeStreamer:
Collaboration graph

Public Member Functions

 RangeStreamer (PositionalSource source, ByteRangeResolver.Result result, int chunkBytes)
 
 RangeStreamer (PositionalSource source, ByteRangeResolver.Result result)
 
long remaining ()
 
int read (byte[] buf, int off, int len) throws IOException
 Reads the next chunk: at most len, at most the chunk size, at most what is left.
 

Static Public Member Functions

static void serve (PositionalSource source, ByteRangeResolver.Result result, ChunkSink sink) throws IOException
 Same with DEFAULT_CHUNK_BYTES.
 
static void serve (PositionalSource source, ByteRangeResolver.Result result, ChunkSink sink, int chunkBytes) throws IOException
 Writes the whole body to the sink.
 

Static Public Attributes

static final int DEFAULT_CHUNK_BYTES = 64 * 1024
 Default chunk size: 64 KiB.
 

Detailed Description

Streams the body of a 200 or 206 answer from a PositionalSource: exactly the bytes the ByteRangeResolver.Result names (start() to endInclusive()), in chunks of at most the chunk size, so a large file is never held in memory.

Plain Java.

Two ways to use it: read hands out one chunk at a time (what an asynchronous response producer needs, one call per "output is ready"), serve pumps the whole body into a ChunkSink (blocking). Both stop with an IOException as soon as the source is closing or ends before the promised length (the response header already announced the length, so a short body must abort the connection), and serve stops as soon as the sink fails. The status (200, 206 or 416) and its headers are the caller's business; a 416 has no body.

Constructor & Destructor Documentation

◆ RangeStreamer()

de.yaacc.share.RangeStreamer.RangeStreamer ( PositionalSource source,
ByteRangeResolver.Result result,
int chunkBytes )
Parameters
resulta 200 or 206 result that was resolved against this source's size
Exceptions
IllegalArgumentExceptionfor a null argument, a 416 or unknown-length result, a result that does not fit the source or a non-positive chunk size

Referenced by de.yaacc.share.RangeStreamer.serve().

Here is the caller graph for this function:

Member Function Documentation

◆ read()

int de.yaacc.share.RangeStreamer.read ( byte[] buf,
int off,
int len ) throws IOException

Reads the next chunk: at most len, at most the chunk size, at most what is left.

Returns
the number of bytes (> 0), 0 only for len == 0, or -1 when the body is complete
Exceptions
IOExceptionif the source is closing or closed, fails, or ends before the promised length

Referenced by de.yaacc.share.RangeStreamer.read(), and de.yaacc.share.RangeStreamer.serve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remaining()

long de.yaacc.share.RangeStreamer.remaining ( )
Returns
how many body bytes are still to be read

◆ serve()

static void de.yaacc.share.RangeStreamer.serve ( PositionalSource source,
ByteRangeResolver.Result result,
ChunkSink sink,
int chunkBytes ) throws IOException
static

Writes the whole body to the sink.

Exceptions
IOExceptionfrom the sink (streaming stops at once) or if the source is closing, fails or ends early
IllegalArgumentExceptionas for the constructor, and for a null sink
Here is the call graph for this function:

The documentation for this class was generated from the following file: