当前位置: 首页>>代码示例>>Java>>正文


Java LZ4Exception类代码示例

本文整理汇总了Java中net.jpountz.lz4.LZ4Exception的典型用法代码示例。如果您正苦于以下问题:Java LZ4Exception类的具体用法?Java LZ4Exception怎么用?Java LZ4Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LZ4Exception类属于net.jpountz.lz4包,在下文中一共展示了LZ4Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public void compress(ByteBuffer input, ByteBuffer output) throws IOException
{
    int len = input.remaining();
    output.put((byte) len);
    output.put((byte) (len >>> 8));
    output.put((byte) (len >>> 16));
    output.put((byte) (len >>> 24));

    try
    {
        compressor.compress(input, output);
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:18,代码来源:LZ4Compressor.java

示例2: uncompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IOException
{
    final int decompressedLength =
            (input[inputOffset] & 0xFF)
            | ((input[inputOffset + 1] & 0xFF) << 8)
            | ((input[inputOffset + 2] & 0xFF) << 16)
            | ((input[inputOffset + 3] & 0xFF) << 24);

    final int compressedLength;
    try
    {
        compressedLength = decompressor.decompress(input, inputOffset + INTEGER_BYTES,
                                                   output, outputOffset, decompressedLength);
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }

    if (compressedLength != inputLength - INTEGER_BYTES)
    {
        throw new IOException("Compressed lengths mismatch");
    }

    return decompressedLength;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:27,代码来源:LZ4Compressor.java

示例3: decompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
@Override
public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkNotNull(decompressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    // Assume that we have a compression ratio of 1/3.
    int outLength = length * 3;
    while (true) {
        try {
            byte[] decompressed = safeDecompressor.decompress(data, offset, length, outLength);
            decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
            return decompressed;
        } catch (LZ4Exception e) {
            outLength *= 2;
        }
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:21,代码来源:LZ4CompressionCodec.java

示例4: compress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public int compress(byte[] input, int inputOffset, int inputLength, WrappedArray output, int outputOffset) throws IOException
{
    final byte[] dest = output.buffer;
    dest[outputOffset] = (byte) inputLength;
    dest[outputOffset + 1] = (byte) (inputLength >>> 8);
    dest[outputOffset + 2] = (byte) (inputLength >>> 16);
    dest[outputOffset + 3] = (byte) (inputLength >>> 24);
    final int maxCompressedLength = compressor.maxCompressedLength(inputLength);
    try
    {
        return INTEGER_BYTES + compressor.compress(input, inputOffset, inputLength,
                                                   dest, outputOffset + INTEGER_BYTES, maxCompressedLength);
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:LZ4Compressor.java

示例5: uncompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IOException
{
    final int decompressedLength =
            (input[inputOffset] & 0xFF)
            | ((input[inputOffset + 1] & 0xFF) << 8)
            | ((input[inputOffset + 2] & 0xFF) << 16)
            | ((input[inputOffset + 3] & 0xFF) << 24);
    final int compressedLength;
    try
    {
        compressedLength = decompressor.decompress(input, inputOffset + INTEGER_BYTES,
                                                   output, outputOffset, decompressedLength);
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }

    if (compressedLength != inputLength - INTEGER_BYTES)
    {
        throw new IOException("Compressed lengths mismatch");
    }

    return decompressedLength;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:26,代码来源:LZ4Compressor.java

示例6: compress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public Frame compress(Frame frame) throws IOException
{
    byte[] input = CBUtil.readRawBytes(frame.body);

    int maxCompressedLength = compressor.maxCompressedLength(input.length);
    byte[] output = new byte[INTEGER_BYTES + maxCompressedLength];

    output[0] = (byte) (input.length >>> 24);
    output[1] = (byte) (input.length >>> 16);
    output[2] = (byte) (input.length >>>  8);
    output[3] = (byte) (input.length);

    try
    {
        int written = compressor.compress(input, 0, input.length, output, INTEGER_BYTES, maxCompressedLength);
        return frame.with(ChannelBuffers.wrappedBuffer(output, 0, INTEGER_BYTES + written));
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:23,代码来源:FrameCompressor.java

示例7: decompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public Frame decompress(Frame frame) throws IOException
{
    byte[] input = CBUtil.readRawBytes(frame.body);

    int uncompressedLength = ((input[0] & 0xFF) << 24)
                           | ((input[1] & 0xFF) << 16)
                           | ((input[2] & 0xFF) <<  8)
                           | ((input[3] & 0xFF));

    byte[] output = new byte[uncompressedLength];

    try
    {
        int read = decompressor.decompress(input, INTEGER_BYTES, output, 0, uncompressedLength);
        if (read != input.length - INTEGER_BYTES)
            throw new IOException("Compressed lengths mismatch");

        return frame.with(ChannelBuffers.wrappedBuffer(output));
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:25,代码来源:FrameCompressor.java

示例8: compress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public Frame compress(Frame frame) throws IOException
{
    byte[] input = CBUtil.readRawBytes(frame.body);

    int maxCompressedLength = compressor.maxCompressedLength(input.length);
    byte[] output = new byte[INTEGER_BYTES + maxCompressedLength];

    output[0] = (byte) (input.length >>> 24);
    output[1] = (byte) (input.length >>> 16);
    output[2] = (byte) (input.length >>>  8);
    output[3] = (byte) (input.length);

    try
    {
        int written = compressor.compress(input, 0, input.length, output, INTEGER_BYTES, maxCompressedLength);
        return frame.with(Unpooled.wrappedBuffer(output, 0, INTEGER_BYTES + written));
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:23,代码来源:FrameCompressor.java

示例9: decompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public Frame decompress(Frame frame) throws IOException
{
    byte[] input = CBUtil.readRawBytes(frame.body);

    int uncompressedLength = ((input[0] & 0xFF) << 24)
                           | ((input[1] & 0xFF) << 16)
                           | ((input[2] & 0xFF) <<  8)
                           | ((input[3] & 0xFF));

    byte[] output = new byte[uncompressedLength];

    try
    {
        int read = decompressor.decompress(input, INTEGER_BYTES, output, 0, uncompressedLength);
        if (read != input.length - INTEGER_BYTES)
            throw new IOException("Compressed lengths mismatch");

        return frame.with(Unpooled.wrappedBuffer(output));
    }
    catch (LZ4Exception e)
    {
        throw new IOException(e);
    }
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:25,代码来源:FrameCompressor.java

示例10: readBody

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
private static ByteBuf readBody(LZ4FastDecompressor decompressor, StreamingXXHash32 checksum, Header header,
                                byte[] bytes, int off) throws ParseException {
	ByteBuf outputBuf = ByteBufPool.allocate(header.originalLen);
	outputBuf.writePosition(header.originalLen);
	switch (header.compressionMethod) {
		case COMPRESSION_METHOD_RAW:
			System.arraycopy(bytes, off, outputBuf.array(), 0, header.originalLen);
			break;
		case COMPRESSION_METHOD_LZ4:
			try {
				int compressedLen2 = decompressor.decompress(bytes, off, outputBuf.array(), 0, header.originalLen);
				if (header.compressedLen != compressedLen2) {
					throw new ParseException("Stream is corrupted");
				}
			} catch (LZ4Exception e) {
				throw new ParseException("Stream is corrupted", e);
			}
			break;
		default:
			throw new AssertionError();
	}
	checksum.reset();
	checksum.update(outputBuf.array(), 0, header.originalLen);
	if (checksum.getValue() != header.check) {
		throw new ParseException("Stream is corrupted");
	}
	return outputBuf;
}
 
开发者ID:softindex,项目名称:datakernel,代码行数:29,代码来源:StreamLZ4Decompressor.java

示例11: decompress

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
public static byte[] decompress(byte[] data) {
    long decompressedLength = unsigned(concatenateBytes(data[0], data[1], data[2], data[3]));
    if (decompressedLength > MAX_BUFFER_LENGTH) {
        throw new DecompressedDataTooLarge();
    }
    try {
        return decompressor.decompress(data, 4, (int)decompressedLength);
    } catch(LZ4Exception exception) {
        throw new InvalidLZ4Data(exception);
    }
}
 
开发者ID:dapperstout,项目名称:pulse-java,代码行数:12,代码来源:LZ4Compression.java

示例12: compress_and_decompressSafe_less_decompressLength

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
@Test
public void compress_and_decompressSafe_less_decompressLength() {
    byte[] compressed = Lz4CompressUtils.compress(ORIGINAL_DATA_BYTES);

    expectedException.expect(LZ4Exception.class);
    Lz4CompressUtils.decompressSafe(compressed, ORIGINAL_DATA_BYTES.length - 100);
}
 
开发者ID:kwon37xi,项目名称:hibernate4-memcached,代码行数:8,代码来源:Lz4CompressUtilsTest.java

示例13: decompressFast_less_exactDecompressedSize

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
@Test
public void decompressFast_less_exactDecompressedSize() {
    byte[] compressed = Lz4CompressUtils.compress(ORIGINAL_DATA_BYTES);

    expectedException.expect(LZ4Exception.class);
    Lz4CompressUtils.decompressFast(compressed, ORIGINAL_DATA_BYTES.length - 100);
}
 
开发者ID:kwon37xi,项目名称:hibernate4-memcached,代码行数:8,代码来源:Lz4CompressUtilsTest.java

示例14: decompressFast_over_exactDecompressedSize

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
@Test
public void decompressFast_over_exactDecompressedSize() {
    byte[] compressed = Lz4CompressUtils.compress(ORIGINAL_DATA_BYTES);

    expectedException.expect(LZ4Exception.class);
    Lz4CompressUtils.decompressFast(compressed, ORIGINAL_DATA_BYTES.length + 100);
}
 
开发者ID:kwon37xi,项目名称:hibernate4-memcached,代码行数:8,代码来源:Lz4CompressUtilsTest.java

示例15: readBlock

import net.jpountz.lz4.LZ4Exception; //导入依赖的package包/类
/**
 * Decompresses (if necessary) buffered data, optionally computes and validates a XXHash32 checksum, and writes the
 * result to a buffer.
 *
 * @throws IOException
 */
private void readBlock() throws IOException {
    if (in.remaining() < 4) {
        throw new IOException(PREMATURE_EOS);
    }

    int blockSize = in.getInt();
    boolean compressed = (blockSize & LZ4_FRAME_INCOMPRESSIBLE_MASK) == 0;
    blockSize &= ~LZ4_FRAME_INCOMPRESSIBLE_MASK;

    // Check for EndMark
    if (blockSize == 0) {
        finished = true;
        if (flg.isContentChecksumSet())
            in.getInt(); // TODO: verify this content checksum
        return;
    } else if (blockSize > maxBlockSize) {
        throw new IOException(String.format("Block size %s exceeded max: %s", blockSize, maxBlockSize));
    }

    if (in.remaining() < blockSize) {
        throw new IOException(PREMATURE_EOS);
    }

    if (compressed) {
        try {
            // workaround for https://github.com/lz4/lz4-java/pull/65
            final int bufferSize;
            if (in.hasArray()) {
                bufferSize = DECOMPRESSOR.decompress(
                    in.array(),
                    in.position() + in.arrayOffset(),
                    blockSize,
                    decompressionBuffer.array(),
                    0,
                    maxBlockSize
                );
            } else {
                // decompressionBuffer has zero arrayOffset, so we don't need to worry about
                // https://github.com/lz4/lz4-java/pull/65
                bufferSize = DECOMPRESSOR.decompress(in, in.position(), blockSize, decompressionBuffer, 0, maxBlockSize);
            }
            decompressionBuffer.position(0);
            decompressionBuffer.limit(bufferSize);
            decompressedBuffer = decompressionBuffer;
        } catch (LZ4Exception e) {
            throw new IOException(e);
        }
    } else {
        decompressedBuffer = in.slice();
        decompressedBuffer.limit(blockSize);
    }

    // verify checksum
    if (flg.isBlockChecksumSet()) {
        // workaround for https://github.com/lz4/lz4-java/pull/65
        int hash = in.hasArray() ?
                   CHECKSUM.hash(in.array(), in.arrayOffset() + in.position(), blockSize, 0) :
                   CHECKSUM.hash(in, in.position(), blockSize, 0);
        in.position(in.position() + blockSize);
        if (hash != in.getInt()) {
            throw new IOException(BLOCK_HASH_MISMATCH);
        }
    } else {
        in.position(in.position() + blockSize);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:73,代码来源:KafkaLZ4BlockInputStream.java


注:本文中的net.jpountz.lz4.LZ4Exception类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。