public abstract class AbstractHttpFile extends Object implements HttpFile
HttpFile implementation.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpFile(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 |
|---|---|
HttpService |
asService()
|
protected Clock |
clock()
Returns the
Clock which provides the current date and time. |
protected MediaType |
contentType()
Returns the
MediaType of the file, which will be used for setting the "content-type"
header. |
protected abstract 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 String |
generateEntityTag(HttpFileAttributes attrs)
Generates an entity tag of the file with the given attributes using the
entityTagFunction
which was specified with the constructor. |
protected HttpHeaders |
headers()
Returns the immutable additional
HttpHeaders which will be set when building an
HttpResponse. |
protected boolean |
isDateEnabled()
Returns whether to add the
"date" header automatically. |
protected boolean |
isLastModifiedEnabled()
Returns whether to add the
"last-modified" header automatically. |
protected abstract String |
pathOrUri()
Returns the
String representation of the file path or URI, which is given to the
entityTagFunction specified with the constructor. |
HttpResponse |
read(Executor fileReadExecutor,
io.netty.buffer.ByteBufAllocator alloc)
Starts to stream this file into the returned
HttpResponse. |
ResponseHeaders |
readHeaders()
Reads the attributes of this file as
ResponseHeaders, which could be useful for building
a response for a HEAD request. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaggregate, aggregateWithPooledObjects, builder, builder, builder, builder, builder, nonExistent, of, of, of, of, of, ofCached, ofResource, ofResource, readAttributesprotected AbstractHttpFile(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 MediaType contentType()
MediaType of the file, which will be used for setting the "content-type"
header.MediaType of the file, or null if the "content-type" header will not
be set automatically.protected abstract String pathOrUri()
String representation of the file path or URI, which is given to the
entityTagFunction specified with the constructor.protected final boolean isDateEnabled()
"date" header automatically.protected final boolean isLastModifiedEnabled()
"last-modified" header automatically.protected final HttpHeaders headers()
HttpHeaders which will be set when building an
HttpResponse.protected final String generateEntityTag(HttpFileAttributes attrs)
entityTagFunction
which was specified with the constructor.null if entityTagFunction is null.public ResponseHeaders readHeaders() throws IOException
HttpFileResponseHeaders, which could be useful for building
a response for a HEAD request.readHeaders in interface HttpFilenull if the file does not exist.IOException - if failed to retrieve the attributes of this file.public final HttpResponse read(Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc)
HttpFileHttpResponse.protected abstract HttpResponse doRead(ResponseHeaders headers, long length, Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc) throws IOException
HttpResponse which streams the content of the file which follows the specified
ResponseHeaders.headers - 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 HttpService asService()
HttpFileCopyright © 2020 LeanCloud. All rights reserved.