Class Compression

All Implemented Interfaces:
Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
Direct Known Subclasses:
BrotliCompression, GzipCompression, ZstandardCompression

public abstract class Compression extends ContainerLifeCycle
  • Constructor Details

    • Compression

      public Compression(String encoding)
  • Method Details

    • acquireByteBuffer

      public abstract RetainableByteBuffer.Mutable acquireByteBuffer(int length)
      Acquire a RetainableByteBuffer that is managed by this Compression implementation which is suitable for compressed output from an EncoderSink or compressed input from a DecoderSource.

      It is recommended to use this method so that any compression specific details can be managed by this Compression implementation (such as ByteOrder or buffer pooling)

      Parameters:
      length - the requested size of the buffer
      Returns:
      the ByteBuffer suitable for this compression implementation.
    • etag

      public String etag(String etag)
      Get an etag with suffix that represents this compression implementation.
      Parameters:
      etag - an etag
      Returns:
      the etag with compression suffix
    • getBufferSize

      public int getBufferSize()
    • setBufferSize

      public void setBufferSize(int size)
    • getByteBufferPool

      public ByteBufferPool getByteBufferPool()
    • setByteBufferPool

      public void setByteBufferPool(ByteBufferPool byteBufferPool)
    • getContainer

      public Container getContainer()
      Get the container being used for common components.
      Returns:
      the container for common components
    • setContainer

      public void setContainer(Container container)
      Set the container that this compression implementation should use.

      The container is often a source for common components (beans) that can be shared across different implementations.

      Parameters:
      container - the container (often the Server itself).
    • getContentEncodingField

      public abstract HttpField getContentEncodingField()
      The HttpField for Content-Encoding suitable for this Compression implementation.
      Returns:
      the HttpField for Content-Encoding.
    • getDefaultDecoderConfig

      public abstract DecoderConfig getDefaultDecoderConfig()
    • setDefaultDecoderConfig

      public abstract void setDefaultDecoderConfig(DecoderConfig decoderConfig)
    • getDefaultEncoderConfig

      public abstract EncoderConfig getDefaultEncoderConfig()
    • setDefaultEncoderConfig

      public abstract void setDefaultEncoderConfig(EncoderConfig encoderConfig)
    • getEncodingName

      public String getEncodingName()
      The name of the encoding if seen in the HTTP protocol in fields like Content-Encoding or Accept-Encoding. This name is also reused for the ETag representations of the compressed content.
      Returns:
      the name of the Content-Encoding for this compression implementation.
    • getEtagSuffix

      public String getEtagSuffix()
      Get the ETag suffix.
      Returns:
      the etag suffix for this compression.
    • getFileExtensionNames

      public abstract List<String> getFileExtensionNames()
      The filename extensions for this compression implementation.

      Not an exhaustive list, just the most commonly seen extensions.

      Returns:
      the list of common extension names (all lowercase) for this compression implementation. ordered by most common to least common.
    • getMinCompressSize

      public int getMinCompressSize()
    • setMinCompressSize

      public void setMinCompressSize(int minCompressSize)
    • getName

      public abstract String getName()
      Returns:
      the name of the compression implementation.
    • getXContentEncodingField

      public abstract HttpField getXContentEncodingField()
      The HttpField for X-Content-Encoding suitable for this Compression implementation.
      Returns:
      the HttpField for X-Content-Encoding.
    • newDecoderInputStream

      public InputStream newDecoderInputStream(InputStream in) throws IOException
      Create a new InputStream to decode (decompress) with this compression implementation.
      Parameters:
      in - the input stream to write the decoded (decompressed) bytes to
      Returns:
      the InputStream implementation for this compression.
      Throws:
      IOException - if unable to create InputStream
    • newDecoderInputStream

      public abstract InputStream newDecoderInputStream(InputStream in, DecoderConfig config) throws IOException
      Create a new InputStream to decode (decompress) with this compression implementation.
      Parameters:
      in - the input stream to write the decoded (decompressed) bytes to
      config - the DecoderConfig for this input stream.
      Returns:
      the InputStream implementation for this compression.
      Throws:
      IOException - if unable to create InputStream
    • newDecoderSource

      public DecoderSource newDecoderSource(Content.Source source)
      Create a new DecoderSource for this compression implementation
      Parameters:
      source - the source to write the decoded bytes to
      Returns:
      a new DecoderSource
    • newDecoderSource

      public abstract DecoderSource newDecoderSource(Content.Source source, DecoderConfig config)
      Create a new DecoderSource for this compression implementation
      Parameters:
      source - the source to write the decoded bytes to
      config - the DecoderConfig for this source.
      Returns:
      a new DecoderSource
    • newEncoderOutputStream

      public OutputStream newEncoderOutputStream(OutputStream out) throws IOException
      Create a new OutputStream to encode (compress) with this compression implementation.
      Parameters:
      out - the output stream to write the encoded (compressed) bytes to
      Returns:
      the OutputStream implementation for this compression.
      Throws:
      IOException - if unable to create OutputStream
    • newEncoderOutputStream

      public abstract OutputStream newEncoderOutputStream(OutputStream out, EncoderConfig config) throws IOException
      Create a new OutputStream to encode (compress) with this compression implementation.
      Parameters:
      out - the output stream to write the encoded (compressed) bytes to
      config - the EncoderConfig for this output stream.
      Returns:
      the OutputStream implementation for this compression.
      Throws:
      IOException - if unable to create OutputStream
    • newEncoderSink

      public EncoderSink newEncoderSink(Content.Sink sink)
      Create a new EncoderSink for this compression implementation
      Parameters:
      sink - the sink to write the encoded bytes to
      Returns:
      a new EncoderSink
    • newEncoderSink

      public abstract EncoderSink newEncoderSink(Content.Sink sink, EncoderConfig config)
      Create a new EncoderSink for this compression implementation
      Parameters:
      sink - the sink to write the encoded bytes to
      config - the EncoderConfig for this sink.
      Returns:
      a new EncoderSink
    • stripSuffixes

      public String stripSuffixes(String etagsList)
      Strip compression suffixes off etags
      Parameters:
      etagsList - the list of etags to strip
      Returns:
      the tags stripped of compression suffixes.
    • doStart

      protected void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class ContainerLifeCycle
      Throws:
      Exception - If there was a problem starting. Will cause a transition to FAILED state