T - the type of the stream where the file content is read from, e.g. InputStream.public abstract class StreamingHttpFile<T extends Closeable> extends AbstractHttpFile
HttpFile that simplifies the streaming of potentially large content.| Modifier | Constructor and Description |
|---|---|
protected |
StreamingHttpFile(MediaType contentType,
Clock clock,
boolean dateEnabled,
boolean lastModifiedEnabled,
BiFunction<String,HttpFileAttributes,String> entityTagFunction,
HttpHeaders headers)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<AggregatedHttpFile> |
aggregate(Executor fileReadExecutor)
Converts this file into an
AggregatedHttpFile. |
CompletableFuture<AggregatedHttpFile> |
aggregateWithPooledObjects(Executor fileReadExecutor,
io.netty.buffer.ByteBufAllocator alloc)
Converts this file into an
AggregatedHttpFile. |
protected HttpResponse |
doRead(ResponseHeaders headers,
long length,
Executor fileReadExecutor,
io.netty.buffer.ByteBufAllocator alloc)
Returns a new
HttpResponse which streams the content of the file which follows the specified
ResponseHeaders. |
protected abstract T |
newStream()
Opens a new stream which reads from the file.
|
protected abstract int |
read(T src,
io.netty.buffer.ByteBuf dst)
Reads the content of
src into dst. |
asService, clock, contentType, generateEntityTag, headers, isDateEnabled, isLastModifiedEnabled, pathOrUri, read, readHeadersclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, builder, builder, builder, builder, nonExistent, of, of, of, of, of, ofCached, ofResource, ofResource, readAttributesprotected StreamingHttpFile(MediaType contentType, Clock clock, boolean dateEnabled, boolean lastModifiedEnabled, BiFunction<String,HttpFileAttributes,String> entityTagFunction, HttpHeaders headers)
contentType - the MediaType of the file which will be used as the "content-type"
header value. null to disable setting the "content-type" header.clock - the Clock which provides the current date and timedateEnabled - whether to set the "date" header automaticallylastModifiedEnabled - whether to add the "last-modified" header automaticallyentityTagFunction - the BiFunction that generates an entity tag from the file's attributes.
null to disable setting the "etag" header.headers - the additional headers to setprotected final HttpResponse doRead(ResponseHeaders headers, long length, Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc) throws IOException
AbstractHttpFileHttpResponse which streams the content of the file which follows the specified
ResponseHeaders.doRead in class AbstractHttpFileheaders - the ResponseHeaderslength - the content length. The returned HttpResponse must stream only as many bytes as
this value.fileReadExecutor - the Executor which should be used for performing a blocking file I/Oalloc - the ByteBufAllocator which should be used for allocating an input bufferHttpResponse, or null if the file does not exist.IOException - if failed to open the file. Note that an I/O error which occurred during content
streaming will be notified via the returned HttpResponse's error
notification mechanism.public final CompletableFuture<AggregatedHttpFile> aggregate(Executor fileReadExecutor)
HttpFileAggregatedHttpFile.fileReadExecutor - the Executor which will perform the read operations against the fileCompletableFuture which will complete when the aggregation process is finished, or
a CompletableFuture successfully completed with this, if this file is already
an AggregatedHttpFile.public final CompletableFuture<AggregatedHttpFile> aggregateWithPooledObjects(Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc)
HttpFileAggregatedHttpFile. AggregatedHttpFile.content() will
return a pooled object, and the caller must ensure to release it. If you don't know what this means,
use HttpFile.aggregate(Executor).fileReadExecutor - the Executor which will perform the read operations against the filealloc - the ByteBufAllocator which will allocate the content bufferCompletableFuture which will complete when the aggregation process is finished, or
a CompletableFuture successfully completed with this, if this file is already
an AggregatedHttpFile.protected abstract T newStream() throws IOException
null if the file does not exist.IOException - if failed to open a new streamprotected abstract int read(T src, io.netty.buffer.ByteBuf dst) throws IOException
src into dst.-1 if reached at the end of the fileIOException - if failed to read the contentCopyright © 2020 LeanCloud. All rights reserved.