Class JdkZlibDecompressor
- java.lang.Object
-
- io.netty.handler.codec.compression.InputBufferingDecompressor
-
- io.netty.handler.codec.compression.JdkZlibDecompressor
-
- All Implemented Interfaces:
Decompressor,java.lang.AutoCloseable
@UnstableApi public final class JdkZlibDecompressor extends InputBufferingDecompressor
Decompress aByteBufusing the inflate algorithm.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJdkZlibDecompressor.Builderprivate static classJdkZlibDecompressor.GzipState-
Nested classes/interfaces inherited from interface io.netty.handler.codec.compression.Decompressor
Decompressor.AbstractDecompressorBuilder, Decompressor.Status
-
-
Field Summary
Fields Modifier and Type Field Description private ByteBufChecksumcrcprivate booleandecideZlibOrNoneprivate booleandecompressConcatenatedprivate byte[]dictionaryprivate static intFCOMMENTprivate static intFEXTRAprivate static intFHCRCprivate booleanfinishedprivate intflagsprivate static intFNAMEprivate static intFRESERVEDprivate booleangzipMemberFinishedprivate JdkZlibDecompressor.GzipStategzipStateprivate java.util.zip.Inflaterinflaterprivate booleaninflaterHasPendingOutputIf this is true, the lastInflater.inflate(byte[], int, int)filled the output buffer completely, so the inflater may still hold decoded data even ifInflater.needsInput()reports that all input was consumed.private booleaninputBufferInInflaterIf this is true, part of the input buffer is still in use by theinflater, so we shouldn't touch that buffer too much (e.g.private intmaxAllocationprivate static intMIN_OUTPUT_BUFFER_SIZESmallest output buffer we hand toInflater.inflate(byte[], int, int).private intxlen-
Fields inherited from class io.netty.handler.codec.compression.InputBufferingDecompressor
allocator
-
-
Constructor Summary
Constructors Constructor Description JdkZlibDecompressor(JdkZlibDecompressor.Builder builder, ByteBufAllocator allocator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JdkZlibDecompressor.Builderbuilder()voidclose()Close this decompressor, cleaning up any associated resources.private voidconsumeInput(ByteBuf buf)voidendOfInput()Notify the decompressor that the end of input has been reached.private booleanhandleGzipFooter(ByteBuf in)private static booleanlooksLikeZlib(short cmf_flg)(package private) voidprocessInput(ByteBuf buf)Process some input.(package private) ByteBufprocessOutput(ByteBuf buf)Produce some output.private booleanreadGZIPFooter(ByteBuf in)Read the GZIP footer.private booleanreadGZIPHeader(ByteBuf in)private booleanskipIfNeeded(ByteBuf in, int flagMask)Skip bytes in the input if needed until we find the end marker0x00.Decompressor.Statusstatus()Get the current status.private booleanverifyCrc(ByteBuf in)Verifies CRC.private booleanverifyCrc16(ByteBuf in)-
Methods inherited from class io.netty.handler.codec.compression.InputBufferingDecompressor
addInput, available, takeOutput
-
-
-
-
Field Detail
-
FHCRC
private static final int FHCRC
- See Also:
- Constant Field Values
-
FEXTRA
private static final int FEXTRA
- See Also:
- Constant Field Values
-
FNAME
private static final int FNAME
- See Also:
- Constant Field Values
-
FCOMMENT
private static final int FCOMMENT
- See Also:
- Constant Field Values
-
FRESERVED
private static final int FRESERVED
- See Also:
- Constant Field Values
-
MIN_OUTPUT_BUFFER_SIZE
private static final int MIN_OUTPUT_BUFFER_SIZE
Smallest output buffer we hand toInflater.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:
- Constant Field Values
-
inflater
private java.util.zip.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 theinflater, so we shouldn't touch that buffer too much (e.g. compact it).
-
inflaterHasPendingOutput
private boolean inflaterHasPendingOutput
If this is true, the lastInflater.inflate(byte[], int, int)filled the output buffer completely, so the inflater may still hold decoded data even ifInflater.needsInput()reports that all input was consumed.
-
-
Constructor Detail
-
JdkZlibDecompressor
JdkZlibDecompressor(JdkZlibDecompressor.Builder builder, ByteBufAllocator allocator)
-
-
Method Detail
-
status
public Decompressor.Status status() throws DecompressionException
Description copied from interface:DecompressorGet 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 DecompressionExceptionDescription copied from interface:DecompressorNotify 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 forDecompressor.Status.NEED_INPUT.- Throws:
DecompressionException
-
processInput
void processInput(ByteBuf buf) throws DecompressionException
Description copied from class:InputBufferingDecompressorProcess 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:
processInputin classInputBufferingDecompressor- Parameters:
buf- The input buffer- Throws:
DecompressionException
-
consumeInput
private void consumeInput(ByteBuf buf)
-
processOutput
ByteBuf processOutput(ByteBuf buf) throws DecompressionException
Description copied from class:InputBufferingDecompressorProduce 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:
processOutputin classInputBufferingDecompressor- 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 marker0x00.- Parameters:
in- the inputflagMask- the mask that should be present in theflagswhen we need to skip bytes.- Returns:
trueif the operation is complete and we can move to the next state,falseif 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:
trueif the footer could be read,falseif the read could not be performed as the inputByteBufdoesn't have enough readable bytes (8 bytes).
-
verifyCrc
private boolean verifyCrc(ByteBuf in)
Verifies CRC.- Parameters:
in- the input.- Returns:
trueif verification could be performed,falseif verification could not be performed as the inputByteBufdoesn'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:DecompressorClose this decompressor, cleaning up any associated resources. This method is idempotent.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceDecompressor- Overrides:
closein classInputBufferingDecompressor
-
builder
@UnstableApi public static JdkZlibDecompressor.Builder builder()
-
-