|
YAACC - UPNP Client and Server
|
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...

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. | |
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.
| de.yaacc.share.RangeStreamer.RangeStreamer | ( | PositionalSource | source, |
| ByteRangeResolver.Result | result, | ||
| int | chunkBytes ) |
| result | a 200 or 206 result that was resolved against this source's size |
| IllegalArgumentException | for 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().

| 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.
len == 0, or -1 when the body is complete | IOException | if 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().


| long de.yaacc.share.RangeStreamer.remaining | ( | ) |
|
static |
Writes the whole body to the sink.
| IOException | from the sink (streaming stops at once) or if the source is closing, fails or ends early |
| IllegalArgumentException | as for the constructor, and for a null sink |
