
org.testifyproject.netty.handler.codec.compression.LzfDecoder Maven / Gradle / Ivy
/*
* Copyright 2014 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in org.testifyproject.testifyprojectpliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org.testifyproject/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.testifyproject.testifyproject.netty.handler.codec.org.testifyproject.testifyprojectpression;
import org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.BufferRecycler;
import org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.ChunkDecoder;
import org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.util.ChunkDecoderFactory;
import org.testifyproject.testifyproject.netty.buffer.ByteBuf;
import org.testifyproject.testifyproject.netty.channel.ChannelHandlerContext;
import org.testifyproject.testifyproject.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
import static org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.LZFChunk.BYTE_Z;
import static org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.LZFChunk.BYTE_V;
import static org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.LZFChunk.HEADER_LEN_NOT_COMPRESSED;
import static org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.LZFChunk.BLOCK_TYPE_NON_COMPRESSED;
import static org.testifyproject.testifyproject.ning.org.testifyproject.testifyprojectpress.lzf.LZFChunk.BLOCK_TYPE_COMPRESSED;
/**
* Uncompresses a {@link ByteBuf} encoded with the LZF format.
*
* See original LZF package
* and LZF format for full org.testifyproject.testifyprojectscription.
*/
public class LzfDecoder extends ByteToMessageDecoder {
/**
* Current state of org.testifyproject.testifyprojectcompression.
*/
private enum State {
INIT_BLOCK,
INIT_ORIGINAL_LENGTH,
DECOMPRESS_DATA,
CORRUPTED
}
private State currentState = State.INIT_BLOCK;
/**
* Magic number of LZF chunk.
*/
private static final short MAGIC_NUMBER = BYTE_Z << 8 | BYTE_V;
/**
* Underlying org.testifyproject.testifyprojectcoder in use.
*/
private ChunkDecoder org.testifyproject.testifyprojectcoder;
/**
* Object that handles org.testifyproject.testifyprojecttails of buffer recycling.
*/
private BufferRecycler recycler;
/**
* Length of current received chunk of data.
*/
private int chunkLength;
/**
* Original length of current received chunk of data.
* It is equal to {@link #chunkLength} for non org.testifyproject.testifyprojectpressed chunks.
*/
private int originalLength;
/**
* Indicates is this chunk org.testifyproject.testifyprojectpressed or not.
*/
private boolean isCompressed;
/**
* Creates a new LZF org.testifyproject.testifyprojectcoder with the most optimal available methods for underlying data access.
* It will "unsafe" instance if one can be used on current JVM.
* It should be safe to call this constructor as implementations are dynamically loaded; however, on some
* non-standard platforms it may be necessary to use {@link #LzfDecoder(boolean)} with {@code true} param.
*/
public LzfDecoder() {
this(false);
}
/**
* Creates a new LZF org.testifyproject.testifyprojectcoder with specified org.testifyproject.testifyprojectcoding instance.
*
* @param safeInstance
* If {@code true} org.testifyproject.testifyprojectcoder will use {@link ChunkDecoder} that only uses standard JDK access methods,
* and should work on all Java platforms and JVMs.
* Otherwise org.testifyproject.testifyprojectcoder will try to use highly optimized {@link ChunkDecoder} implementation that uses
* Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well).
*/
public LzfDecoder(boolean safeInstance) {
org.testifyproject.testifyprojectcoder = safeInstance ?
ChunkDecoderFactory.safeInstance()
: ChunkDecoderFactory.optimalInstance();
recycler = BufferRecycler.instance();
}
@Override
protected void org.testifyproject.testifyprojectcode(ChannelHandlerContext ctx, ByteBuf in, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy