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 AggregatedHttpFile |
nonExistent()
Returns an
AggregatedHttpFile which represents a non-existent file. |
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)
Creates a new
HttpFile which streams the resource at the specified path, loaded by
the specified ClassLoader. |
static HttpFile |
ofResource(String path)
Creates a new
HttpFile which streams the resource at the specified path. |
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 AggregatedHttpFile of(HttpData data)
AggregatedHttpFile which streams the specified HttpData. This method is
a shortcut of 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 epochstatic HttpFile ofResource(String path)
HttpFile which streams the resource at the specified path. This method is
a shortcut of HttpFile.of(HttpFile.class.getClassLoader(), path).static HttpFile ofResource(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 nonExistent()
AggregatedHttpFile which represents a non-existent file.@Nullable HttpFileAttributes readAttributes() throws IOException
null if the file does not exist.IOException - if failed to retrieve the attributes of this file.@Nullable 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.@Nullable 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.