public interface HttpFile
HttpResponse.
HttpFile faviconFile = HttpFile.of(new File("/var/www/favicon.ico"));
ServerBuilder builder = Server.builder();
builder.service("/favicon.ico", faviconFile.asService());
Server server = builder.build();
HttpFileBuilder| 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. |
HttpService |
asService()
|
static HttpFileBuilder |
builder(ClassLoader classLoader,
String path)
Returns a new
HttpFileBuilder that builds an HttpFile from the classpath resource
at the specified path using the specified ClassLoader. |
static HttpFileBuilder |
builder(File file)
|
static HttpFileBuilder |
builder(HttpData data)
|
static HttpFileBuilder |
builder(HttpData data,
long lastModifiedMillis)
Returns a new
HttpFileBuilder that builds an AggregatedHttpFile from the specified
HttpData and lastModifiedMillis. |
static HttpFileBuilder |
builder(Path path)
|
static AggregatedHttpFile |
nonExistent()
Returns an
AggregatedHttpFile which represents a non-existent file. |
static HttpFile |
of(ClassLoader classLoader,
String path)
Creates a new
HttpFile which streams the resource at the specified path, loaded by
the specified ClassLoader. |
static HttpFile |
of(File file)
|
static AggregatedHttpFile |
of(HttpData data)
Creates a new
AggregatedHttpFile which streams the specified HttpData. |
static AggregatedHttpFile |
of(HttpData data,
long lastModifiedMillis)
Creates a new
AggregatedHttpFile which streams the specified HttpData with the specified
lastModifiedMillis. |
static HttpFile |
of(Path path)
|
static HttpFile |
ofCached(HttpFile file,
int maxCachingLength)
|
static HttpFile |
ofResource(ClassLoader classLoader,
String path)
Deprecated.
|
static HttpFile |
ofResource(String path)
Deprecated.
|
HttpResponse |
read(Executor fileReadExecutor,
io.netty.buffer.ByteBufAllocator alloc)
Starts to stream this file into the returned
HttpResponse. |
HttpFileAttributes |
readAttributes()
Retrieves the attributes of this file.
|
ResponseHeaders |
readHeaders()
Reads the attributes of this file as
ResponseHeaders, which could be useful for building
a response for a HEAD request. |
static HttpFile of(ClassLoader classLoader, String path)
HttpFile which streams the resource at the specified path, loaded by
the specified ClassLoader.classLoader - the ClassLoader which will load the resource at the pathpath - the path to the resourcestatic AggregatedHttpFile of(HttpData data)
AggregatedHttpFile which streams the specified HttpData. This method is
a shortcut for HttpFile.of(data, System.currentTimeMillis().static AggregatedHttpFile of(HttpData data, long lastModifiedMillis)
AggregatedHttpFile which streams the specified HttpData with the specified
lastModifiedMillis.data - the data that provides the content of an HTTP responselastModifiedMillis - when the data has been last modified, represented as the number of
millisecond since the epoch@Deprecated static HttpFile ofResource(String path)
of(ClassLoader, String).HttpFile which streams the resource at the specified path. This method is
a shortcut for HttpFile.of(HttpFile.class.getClassLoader(), path).@Deprecated static HttpFile ofResource(ClassLoader classLoader, String path)
of(ClassLoader, String).HttpFile which streams the resource at the specified path, loaded by
the specified ClassLoader.classLoader - the ClassLoader which will load the resource at the pathpath - the path to the resourcestatic AggregatedHttpFile nonExistent()
AggregatedHttpFile which represents a non-existent file.static HttpFileBuilder builder(File file)
static HttpFileBuilder builder(Path path)
static HttpFileBuilder builder(HttpData data)
HttpFileBuilder that builds an AggregatedHttpFile from the specified
HttpData. The last modified date of the file is set to 'now'. Note that the
HttpFileBuilder.build() method of the returned builder will always return
an AggregatedHttpFile, which guarantees a safe downcast:
AggregatedHttpFile f = (AggregatedHttpFile) HttpFile.builder(HttpData.ofUtf8("foo")).build();
static HttpFileBuilder builder(HttpData data, long lastModifiedMillis)
HttpFileBuilder that builds an AggregatedHttpFile from the specified
HttpData and lastModifiedMillis. Note that the HttpFileBuilder.build() method
of the returned builder will always return an AggregatedHttpFile, which guarantees a safe
downcast:
AggregatedHttpFile f = (AggregatedHttpFile) HttpFile.builder(HttpData.ofUtf8("foo"), 1546923055020)
.build();
data - the content of the filelastModifiedMillis - the last modified time represented as the number of milliseconds
since the epochstatic HttpFileBuilder builder(ClassLoader classLoader, String path)
HttpFileBuilder that builds an HttpFile from the classpath resource
at the specified path using the specified ClassLoader.HttpFileAttributes readAttributes() throws IOException
null if the file does not exist.IOException - if failed to retrieve the attributes of this file.ResponseHeaders readHeaders() throws IOException
ResponseHeaders, which could be useful for building
a response for a HEAD request.null if the file does not exist.IOException - if failed to retrieve the attributes of this file.HttpResponse read(Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc)
HttpResponse.fileReadExecutor - the Executor which will perform the read operations against the filealloc - the ByteBufAllocator which will allocate the buffers that hold the content of
the filenull if the file does not exist.CompletableFuture<AggregatedHttpFile> aggregate(Executor fileReadExecutor)
AggregatedHttpFile.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.CompletableFuture<AggregatedHttpFile> aggregateWithPooledObjects(Executor fileReadExecutor, io.netty.buffer.ByteBufAllocator alloc)
AggregatedHttpFile. AggregatedHttpFile.content() will
return a pooled object, and the caller must ensure to release it. If you don't know what this means,
use 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.HttpService asService()
Copyright © 2020 LeanCloud. All rights reserved.