Package com.linecorp.armeria.server.file
Interface HttpFile
- All Known Implementing Classes:
AbstractHttpFile
,StreamingHttpFile
public interface HttpFile
A file-like HTTP resource which yields an
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();
- See Also:
HttpFileBuilder
-
Method Summary
Modifier and Type Method Description CompletableFuture<AggregatedHttpFile>
aggregate(Executor fileReadExecutor)
Converts this file into anAggregatedHttpFile
.CompletableFuture<AggregatedHttpFile>
aggregateWithPooledObjects(Executor fileReadExecutor, ByteBufAllocator alloc)
(Advanced users only) Converts this file into anAggregatedHttpFile
.HttpService
asService()
static HttpFileBuilder
builder(HttpData data)
static HttpFileBuilder
builder(HttpData data, long lastModifiedMillis)
Returns a newHttpFileBuilder
that builds anHttpFile
from the specifiedHttpData
andlastModifiedMillis
.static HttpFileBuilder
builder(File file)
static HttpFileBuilder
builder(ClassLoader classLoader, String path)
Returns a newHttpFileBuilder
that builds anHttpFile
from the classpath resource at the specifiedpath
using the specifiedClassLoader
.static HttpFileBuilder
builder(Path path)
static HttpFile
from(CompletionStage<? extends HttpFile> stage)
Returns anHttpFile
that becomes readable when the specifiedCompletionStage
is complete.static HttpFile
nonExistent()
Returns anHttpFile
which represents a non-existent file.static HttpFile
of(HttpData data)
static HttpFile
of(HttpData data, long lastModifiedMillis)
static HttpFile
of(File file)
static HttpFile
of(ClassLoader classLoader, String path)
Creates a newHttpFile
which streams the resource at the specifiedpath
, loaded by the specifiedClassLoader
.static HttpFile
of(Path path)
static HttpFile
ofCached(HttpFile file, int maxCachingLength)
CompletableFuture<HttpResponse>
read(Executor fileReadExecutor, ByteBufAllocator alloc)
Starts to stream this file into the returnedHttpResponse
.CompletableFuture<HttpFileAttributes>
readAttributes(Executor fileReadExecutor)
Retrieves the attributes of this file.CompletableFuture<ResponseHeaders>
readHeaders(Executor fileReadExecutor)
Reads the attributes of this file asResponseHeaders
, which could be useful for building a response for aHEAD
request.
-
Method Details
-
of
-
of
-
of
Creates a newHttpFile
which streams the resource at the specifiedpath
, loaded by the specifiedClassLoader
.- Parameters:
classLoader
- theClassLoader
which will load the resource at thepath
path
- the path to the resource
-
of
-
of
- Parameters:
data
- the data that provides the content of an HTTP responselastModifiedMillis
- when thedata
has been last modified, represented as the number of millisecond since the epoch
-
ofCached
-
nonExistent
Returns anHttpFile
which represents a non-existent file. -
from
Returns anHttpFile
that becomes readable when the specifiedCompletionStage
is complete. AllHttpFile
operations will wait until the specifiedCompletionStage
is completed. -
builder
-
builder
-
builder
Returns a newHttpFileBuilder
that builds anHttpFile
from the specifiedHttpData
. The last modified date of the file is set to 'now'. -
builder
Returns a newHttpFileBuilder
that builds anHttpFile
from the specifiedHttpData
andlastModifiedMillis
.- Parameters:
data
- the content of the filelastModifiedMillis
- the last modified time represented as the number of milliseconds since the epoch
-
builder
Returns a newHttpFileBuilder
that builds anHttpFile
from the classpath resource at the specifiedpath
using the specifiedClassLoader
. -
readAttributes
Retrieves the attributes of this file.- Parameters:
fileReadExecutor
- theExecutor
which will perform the read operations against the file- Returns:
- the
CompletableFuture
that will be completed with the attributes of this file. It will be completed withnull
if the file does not exist.
-
readHeaders
Reads the attributes of this file asResponseHeaders
, which could be useful for building a response for aHEAD
request.- Parameters:
fileReadExecutor
- theExecutor
which will perform the read operations against the file- Returns:
- the
CompletableFuture
that will be completed with the headers. It will be completed withnull
if the file does not exist.
-
read
Starts to stream this file into the returnedHttpResponse
.- Parameters:
fileReadExecutor
- theExecutor
which will perform the read operations against the filealloc
- theByteBufAllocator
which will allocate the buffers that hold the content of the file- Returns:
- the
CompletableFuture
that will be completed with the response. It will be completed withnull
if the file does not exist.
-
aggregate
Converts this file into anAggregatedHttpFile
.- Parameters:
fileReadExecutor
- theExecutor
which will perform the read operations against the file- Returns:
- a
CompletableFuture
which will complete when the aggregation process is finished, or aCompletableFuture
successfully completed withthis
, if this file is already anAggregatedHttpFile
.
-
aggregateWithPooledObjects
@UnstableApi CompletableFuture<AggregatedHttpFile> aggregateWithPooledObjects(Executor fileReadExecutor, ByteBufAllocator alloc)(Advanced users only) Converts this file into anAggregatedHttpFile
.AggregatedHttpFile.content()
will return a pooledHttpData
, and the caller must ensure to release it. If you don't know what this means, useaggregate(Executor)
.- Parameters:
fileReadExecutor
- theExecutor
which will perform the read operations against the filealloc
- theByteBufAllocator
which will allocate the content buffer- Returns:
- a
CompletableFuture
which will complete when the aggregation process is finished, or aCompletableFuture
successfully completed withthis
, if this file is already anAggregatedHttpFile
. - See Also:
PooledObjects
-
asService
HttpService asService()
-