Enum Class WSHelper.Type

java.lang.Object
java.lang.Enum<WSHelper.Type>
com.iizix.jetty.WSHelper.Type
All Implemented Interfaces:
Serializable, Comparable<WSHelper.Type>, Constable
Enclosing class:
WSHelper

public static enum WSHelper.Type extends Enum<WSHelper.Type>
The compression types enum.

Overview of each type's file extension, minimum compress size and the candidate source file extensions that are precompressed:

 Type       Extension  Minimum size (bytes)
 ---------  ---------  --------------------
 GZIP       .gz        128
 BROTLI     .br        48
 ZSTANDARD  .zst       48
 

All three types currently share the same candidate source extensions (stored per type in fileExtensionCandidates): .js .mjs .css .htm .html .svg .json .webmanifest .xml .txt .map .wasm .ttf .otf .eot .ico

  • Enum Constant Details

    • GZIP

      public static final WSHelper.Type GZIP
      GZIP compression type. Its minimumSize is 128: gzip carries ~18 bytes of header/trailer plus block overhead, so it uses a higher floor than brotli/zstandard; 128 is a conservative, web-common value below which compression is not worthwhile. GZIP compression is set to 9 = Best.
    • BROTLI

      public static final WSHelper.Type BROTLI
      Brotli compression type. Its minimumSize is 48: brotli's small per-stream overhead and built-in dictionary make it worthwhile on smaller payloads; 48 matches Jetty's brotli module default. Brotli compression is set to 11 = Best.
    • ZSTANDARD

      public static final WSHelper.Type ZSTANDARD
      Zstandard compression type. Its minimumSize is 48: zstandard's small frame overhead makes it worthwhile on smaller payloads, like brotli; 48 matches Jetty's zstandard module default. Zstandard compression is set to what Jetty can handle as its best, i.e. 19 (and the levels 20-22, so-called "ultra" are not exposed by the Jetty wrapper and cannot be used).
  • Field Details

    • extension

      public final String extension
      The extension (including the '.').
    • compressionLevel

      public final int compressionLevel
      The compression level to use for this type, always set to best level of compression for each compression type.
    • minimumSize

      public final int minimumSize
      The minimum size, in bytes, below which a response body of this compression type is passed through uncompressed regardless of Accept-Encoding. Wired to setMinCompressSize(int) on the Jetty Compression instance in WSHelper.createCompressionsHandler(Handler). Declared public final so it can be read directly without a getter; set before the web server starts.
    • fileExtensionCandidates

      public final List<String> fileExtensionCandidates
      The candidate source file extensions for this compression type (lower-case, each including the leading '.'). These are the file types the precompression build script (compress-candidate-files.js) compresses to a 'extension' sibling; already-compressed types (images, media, archives, and the web fonts '.woff'/'.woff2') are deliberately excluded. Informational on the Java side -- the actual filtering happens in the build script, which mirrors this list by convention.
  • Method Details

    • values

      public static WSHelper.Type[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static WSHelper.Type valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • isAvailable

      public boolean isAvailable() throws Throwable
      Checks if this Jetty instance supports the compression type and is available for use.
      Returns:
      The availability flag.
      Throws:
      Throwable - In case the instance is not supported.
    • isAvailableSilent

      public boolean isAvailableSilent()
      Checks if this Jetty instance supports the compression type and is available for use. The check is done silently so no exception is thrown, but false is returned.
      Returns:
      The availability flag.
    • appendToPath

      public URI appendToPath(URI uri) throws URISyntaxException
      Appends the suffix of this compression type to a URI.
      Parameters:
      uri - The URI to append suffix to path.
      Throws:
      URISyntaxException - If there is an error when creating the new URI (should not occur) if suffix is just a normal file extension.
    • from

      public static WSHelper.Type from(String ext)
      Gets the extension type from the string (with or without '.' prefix), case insensitive.
      Parameters:
      ext - The file extension.
      Returns:
      The type, or null if none is found.