Class JdkZlibDecompressor

java.lang.Object
io.netty.handler.codec.compression.InputBufferingDecompressor
io.netty.handler.codec.compression.JdkZlibDecompressor
All Implemented Interfaces:
Decompressor, AutoCloseable

@UnstableApi public final class JdkZlibDecompressor extends InputBufferingDecompressor
Decompress a ByteBuf using the inflate algorithm.
  • Field Details

    • FHCRC

      private static final int FHCRC
      See Also:
    • FEXTRA

      private static final int FEXTRA
      See Also:
    • FNAME

      private static final int FNAME
      See Also:
    • FCOMMENT

      private static final int FCOMMENT
      See Also:
    • FRESERVED

      private static final int FRESERVED
      See Also:
    • MIN_OUTPUT_BUFFER_SIZE

      private static final int MIN_OUTPUT_BUFFER_SIZE
      Smallest output buffer we hand to Inflater.inflate(byte[], int, int). The number of remaining input bytes is only a hint for how much output to expect: the inflater may still hold decoded data that did not fit into the previous output buffer, and by then it may have consumed all input bytes already (Inflater.getRemaining() == 0). Inflating into a zero-sized buffer can never make progress.
      See Also:
    • inflater

      private Inflater inflater
    • maxAllocation

      private final int maxAllocation
    • dictionary

      private final byte[] dictionary
    • crc

      private final ByteBufChecksum crc
    • decompressConcatenated

      private final boolean decompressConcatenated
    • gzipState

      private JdkZlibDecompressor.GzipState gzipState
    • flags

      private int flags
    • xlen

      private int xlen
    • decideZlibOrNone

      private boolean decideZlibOrNone
    • finished

      private boolean finished
    • gzipMemberFinished

      private boolean gzipMemberFinished
    • inputBufferInInflater

      private boolean inputBufferInInflater
      If this is true, part of the input buffer is still in use by the inflater, so we shouldn't touch that buffer too much (e.g. compact it).
    • inflaterHasPendingOutput

      private boolean inflaterHasPendingOutput
      If this is true, the last Inflater.inflate(byte[], int, int) filled the output buffer completely, so the inflater may still hold decoded data even if Inflater.needsInput() reports that all input was consumed.
  • Constructor Details

  • Method Details

    • status

      Description copied from interface: Decompressor
      Get the current status. Like the other operations on this class, calling this method is not permitted if the decompressor has failed or was closed.
      Returns:
      The current status
      Throws:
      DecompressionException
    • endOfInput

      public void endOfInput() throws DecompressionException
      Description copied from interface: Decompressor
      Notify the decompressor that the end of input has been reached. Some implementations may flush remaining data or throw an exception if the input is truncated, but most implementations do nothing. Only permitted for Decompressor.Status.NEED_INPUT.
      Throws:
      DecompressionException
    • processInput

      void processInput(ByteBuf buf) throws DecompressionException
      Description copied from class: InputBufferingDecompressor
      Process some input. The input buffer ownership does not transfer to this method: If there's still data unread after this method finishes, it will be buffered.
      Specified by:
      processInput in class InputBufferingDecompressor
      Parameters:
      buf - The input buffer
      Throws:
      DecompressionException
    • consumeInput

      private void consumeInput(ByteBuf buf)
    • processOutput

      ByteBuf processOutput(ByteBuf buf) throws DecompressionException
      Description copied from class: InputBufferingDecompressor
      Produce some output. The input buffer parameter may be read from to consume some more data, but note that this method must return a buffer even if the input is too short.
      Specified by:
      processOutput in class InputBufferingDecompressor
      Parameters:
      buf - The input buffer
      Throws:
      DecompressionException
    • handleGzipFooter

      private boolean handleGzipFooter(ByteBuf in)
    • readGZIPHeader

      private boolean readGZIPHeader(ByteBuf in)
    • skipIfNeeded

      private boolean skipIfNeeded(ByteBuf in, int flagMask)
      Skip bytes in the input if needed until we find the end marker 0x00.
      Parameters:
      in - the input
      flagMask - the mask that should be present in the flags when we need to skip bytes.
      Returns:
      true if the operation is complete and we can move to the next state, false if we need the retry again once we have more readable bytes.
    • readGZIPFooter

      private boolean readGZIPFooter(ByteBuf in)
      Read the GZIP footer.
      Parameters:
      in - the input.
      Returns:
      true if the footer could be read, false if the read could not be performed as the input ByteBuf doesn't have enough readable bytes (8 bytes).
    • verifyCrc

      private boolean verifyCrc(ByteBuf in)
      Verifies CRC.
      Parameters:
      in - the input.
      Returns:
      true if verification could be performed, false if verification could not be performed as the input ByteBuf doesn't have enough readable bytes (4 bytes).
    • verifyCrc16

      private boolean verifyCrc16(ByteBuf in)
    • looksLikeZlib

      private static boolean looksLikeZlib(short cmf_flg)
    • close

      public void close()
      Description copied from interface: Decompressor
      Close this decompressor, cleaning up any associated resources. This method is idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Decompressor
      Overrides:
      close in class InputBufferingDecompressor
    • builder

      @UnstableApi public static JdkZlibDecompressor.Builder builder()