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:
-
Method Summary
Modifier and TypeMethodDescriptionConverts this file into anAggregatedHttpFile
.aggregateWithPooledObjects
(Executor fileReadExecutor, ByteBufAllocator alloc) (Advanced users only) Converts this file into anAggregatedHttpFile
.static HttpFileBuilder
static HttpFileBuilder
Returns a newHttpFileBuilder
that builds anHttpFile
from the specifiedHttpData
andlastModifiedMillis
.static HttpFileBuilder
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
static HttpFileBuilder
static HttpFile
from
(CompletionStage<? extends HttpFile> stage) Returns anHttpFile
that becomes readable when the specifiedCompletionStage
is complete.static HttpFile
Returns anHttpFile
which represents a non-existent file.static HttpFile
static HttpFile
static HttpFile
static HttpFile
of
(ClassLoader classLoader, String path) Creates a newHttpFile
which streams the resource at the specifiedpath
, loaded by the specifiedClassLoader
.static HttpFile
static HttpFile
static HttpFile
ofRedirect
(String location) Returns anHttpFile
redirected to the specifiedlocation
.read
(Executor fileReadExecutor, ByteBufAllocator alloc) Starts to stream this file into the returnedHttpResponse
.readAttributes
(Executor fileReadExecutor) Retrieves the attributes of this file.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. -
ofRedirect
Returns anHttpFile
redirected to the specifiedlocation
. -
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 specifiedURL
.file:
,jrt:
and jar:file: protocol. -
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:
-
asService
HttpService asService()
-