Class FileServiceBuilder

java.lang.Object
com.linecorp.armeria.server.file.FileServiceBuilder

public final class FileServiceBuilder extends Object
Builds a new FileService and its FileServiceConfig. Use the factory methods in FileService if you do not override the default settings.
  • Method Details

    • clock

      public FileServiceBuilder clock(Clock clock)
      Sets the Clock that provides the current date and time.
    • maxCacheEntries

      public FileServiceBuilder maxCacheEntries(int maxCacheEntries)
      Sets the maximum allowed number of cached file entries. If not set, up to 1024 entries are cached by default.
    • entryCacheSpec

      public FileServiceBuilder entryCacheSpec(String entryCacheSpec)
      Sets the Caffeine specification string of the cache that stores the content of the HttpFiles read by the FileService. If not set, Flags.fileServiceCacheSpec() is used by default.
    • serveCompressedFiles

      public FileServiceBuilder serveCompressedFiles(boolean serveCompressedFiles)
      Sets whether pre-compressed files should be served. FileService supports serving files compressed with gzip, with the extension ".gz", and brotli, with the extension ".br". The extension should be appended to the original file. For example, to serve index.js either raw, gzip-compressed, or brotli-compressed, there should be three files, index.js, index.js.gz, and index.js.br. By default, this feature is disabled.

      Some tools for precompressing resources during a build process include gulp-zopfli and gulp-brotli, which by default create files with the correct extension.

    • autoDecompress

      public FileServiceBuilder autoDecompress(boolean autoDecompress)
      Sets whether pre-compressed files could be served after being decompressed, when a client does not accept a compressed file. The compressed file will be automatically decompressed depending on the extension of the compressed file. For example, files compressed with gzip should have the extension ".gz" and compressed with brotli should have the extension ".br".

      Note that this option is valid only when serveCompressedFiles(boolean) is enabled.

      See Also:
    • maxCacheEntrySizeBytes

      public FileServiceBuilder maxCacheEntrySizeBytes(int maxCacheEntrySizeBytes)
      Sets the maximum allowed size of a cached file entry. The file bigger than this value will not be cached. If not set, 65536 is used by default.
    • autoIndex

      public FileServiceBuilder autoIndex(boolean autoIndex)
      Sets whether FileService auto-generates a directory listing for a directory without an index.html file. By default, this feature is disabled. Consider the security implications of when enabling this feature.
    • addHeader

      public FileServiceBuilder addHeader(CharSequence name, Object value)
      Adds the specified HTTP header.
    • addHeaders

      public FileServiceBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
      Adds the specified HTTP headers.
    • setHeader

      public FileServiceBuilder setHeader(CharSequence name, Object value)
      Sets the specified HTTP header.
    • setHeaders

      public FileServiceBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
      Sets the specified HTTP headers.
    • cacheControl

      public FileServiceBuilder cacheControl(CacheControl cacheControl)
      Sets the "cache-control" header. This method is a shortcut for:
      
       builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
       
    • cacheControl

      public FileServiceBuilder cacheControl(CharSequence cacheControl)
      Sets the "cache-control" header. This method is a shortcut for:
      
       builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
       
    • mediaTypeResolver

      public FileServiceBuilder mediaTypeResolver(MediaTypeResolver mediaTypeResolver)
      Sets the MediaTypeResolver that determines a file's MediaType using its path. If not set, MediaTypeResolver.ofDefault() is used by default.
    • build

      public FileService build()
      Returns a newly-created FileService based on the properties of this builder.
    • toString

      public String toString()
      Overrides:
      toString in class Object