Package com.linecorp.armeria.server.file
Class FileService
java.lang.Object
com.linecorp.armeria.server.AbstractHttpService
com.linecorp.armeria.server.file.FileService
- All Implemented Interfaces:
Unwrappable
,HttpService
,Service<HttpRequest,HttpResponse>
public final class FileService extends AbstractHttpService
An
HttpService
that serves static files from a file system.- See Also:
FileServiceBuilder
-
Method Summary
Modifier and Type Method Description static FileServiceBuilder
builder(HttpVfs vfs)
Returns a newFileServiceBuilder
with the specifiedHttpVfs
.static FileServiceBuilder
builder(File rootDir)
Returns a newFileServiceBuilder
with the specifiedrootDir
in an O/S file system.static FileServiceBuilder
builder(ClassLoader classLoader, String rootDir)
Returns a newFileServiceBuilder
with the specifiedrootDir
in the current class path.static FileServiceBuilder
builder(Path rootDir)
Returns a newFileServiceBuilder
with the specifiedrootDir
in an O/S file system.FileServiceConfig
config()
Returns the configuration.protected HttpResponse
doGet(ServiceRequestContext ctx, HttpRequest req)
Handles aGET
request.static FileService
of(HttpVfs vfs)
Returns a newFileService
for the specifiedHttpVfs
.static FileService
of(File rootDir)
Returns a newFileService
for the specifiedrootDir
in an O/S file system.static FileService
of(ClassLoader classLoader, String rootDir)
Returns a newFileService
for the specifiedrootDir
in the current class path.static FileService
of(Path rootDir)
Returns a newFileService
for the specifiedrootDir
in an O/S file system.HttpService
orElse(HttpService nextService)
Creates a newHttpService
that tries thisFileService
first and then the specifiedHttpService
when thisFileService
does not have a requested resource.void
serviceAdded(ServiceConfig cfg)
Invoked when this service has been added to aServer
with the specified configuration.boolean
shouldCachePath(String path, String query, Route route)
Returns whether the givenpath
andquery
should be cached if the service's result is successful.Methods inherited from class com.linecorp.armeria.server.AbstractHttpService
doDelete, doHead, doOptions, doPatch, doPost, doPut, doTrace, serve
-
Method Details
-
of
Returns a newFileService
for the specifiedrootDir
in an O/S file system. -
of
Returns a newFileService
for the specifiedrootDir
in an O/S file system. -
of
Returns a newFileService
for the specifiedrootDir
in the current class path. -
of
Returns a newFileService
for the specifiedHttpVfs
. -
builder
Returns a newFileServiceBuilder
with the specifiedrootDir
in an O/S file system. -
builder
Returns a newFileServiceBuilder
with the specifiedrootDir
in an O/S file system. -
builder
Returns a newFileServiceBuilder
with the specifiedrootDir
in the current class path. -
builder
Returns a newFileServiceBuilder
with the specifiedHttpVfs
. -
serviceAdded
Description copied from interface:Service
Invoked when this service has been added to aServer
with the specified configuration. Please note that this method can be invoked more than once if this service has been added more than once.- Throws:
Exception
-
shouldCachePath
Description copied from interface:Service
Returns whether the givenpath
andquery
should be cached if the service's result is successful. By default, exact path mappings with no input query are cached. -
config
Returns the configuration. -
doGet
Description copied from class:AbstractHttpService
Handles aGET
request. This method sends a405 Method Not Allowed
response by default.- Overrides:
doGet
in classAbstractHttpService
- Throws:
Exception
-
orElse
Creates a newHttpService
that tries thisFileService
first and then the specifiedHttpService
when thisFileService
does not have a requested resource.- Parameters:
nextService
- theHttpService
to try secondly
-