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


Java Snappy类代码示例

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


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

示例1: testCompressionSnappyRaw

import org.xerial.snappy.Snappy; //导入依赖的package包/类
/**
 * Test compression snappy raw.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void testCompressionSnappyRaw() throws IOException
{
	ByteBuffer src = ByteBuffer.allocateDirect(1024);
	ByteBuffer dst = ByteBuffer.allocateDirect(1024);
	String value = "0000000000000000000000000000000000000000000000000000000000000000000000000000000"+
       "0000000000000000000000000000000000000000000000000000000000000000000000000000000" +
       "0000000000000000000000000000000000000000000000000000000000000000000000000000000";
       src.put(value.getBytes());
       src.flip();
       int len = Snappy.compress(src, dst);
       LOG.info("Compressed size ="+len+" dst pos ="+dst.position()+" dst limit="+dst.limit());
       len = Snappy.uncompress(dst, src);
       LOG.info("Uncompressed size="+len);
       LOG.info("Original size="+value.length());
       
}
 
开发者ID:VladRodionov,项目名称:bigbase,代码行数:22,代码来源:CompressionTest.java

示例2: compressBufferForMessaging

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public static ByteBuffer compressBufferForMessaging(ByteBuffer buffer) throws IOException {
    assert(buffer.isDirect());
    int lim = buffer.limit();
    int pos = buffer.position();
    int rem = buffer.remaining();
    IOBuffers buffers = getBuffersForCompression(buffer.remaining(), true);
    ByteBuffer output = buffers.output;

    final int compressedSize = Snappy.compress(buffer, output);
    ByteBuffer result = ByteBuffer.wrap(new byte[compressedSize + 4]);
    result.putInt(compressedSize);
    result.put(output);
    result.flip();
    
    return result;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:17,代码来源:CompressionService.java

示例3: decompressBuffer

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public static byte[] decompressBuffer(final ByteBuffer compressed) throws IOException {
    assert(compressed.isDirect());
    IOBuffers buffers = m_buffers.get();
    ByteBuffer input = buffers.input;
    ByteBuffer output = buffers.output;

    final int uncompressedLength = Snappy.uncompressedLength(input);
    if (output.capacity() < uncompressedLength) {
        output = ByteBuffer.allocateDirect(Math.max(output.capacity() * 2, uncompressedLength));
        buffers = new IOBuffers(input, output);
        m_buffers.set(buffers);
    }
    output.clear();

    final int actualUncompressedLength = Snappy.uncompress(input, output);
    assert(uncompressedLength == actualUncompressedLength);

    byte result[] = new byte[actualUncompressedLength];
    output.get(result);
    return result;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:22,代码来源:CompressionService.java

示例4: compress

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public static byte[] compress(byte[] uncompressData) {
    try {
        switch (CMP) {
            case SNAPPY:
                return Snappy.compress(uncompressData);
            case GZIP:
                ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
                GZIPOutputStream gzout = new GZIPOutputStream(out);
                gzout.write(uncompressData, 0, uncompressData.length);
                gzout.close();
                return out.toByteArray();
            default:
                throw new RuntimeException("Should not happen!");
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:shunfei,项目名称:indexr,代码行数:19,代码来源:GenericCompression.java

示例5: compress

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public Frame compress(Frame frame) throws IOException
{
    byte[] input = CBUtil.readRawBytes(frame.body);
    ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.maxCompressedLength(input.length));

    try
    {
        int written = Snappy.compress(input, 0, input.length, output.array(), output.arrayOffset());
        output.writerIndex(written);
    }
    catch (final Throwable e)
    {
        output.release();
        throw e;
    }
    finally
    {
        //release the old frame
        frame.release();
    }

    return frame.with(output);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:24,代码来源:FrameCompressor.java

示例6: decompressBuffer

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public static byte[] decompressBuffer(final ByteBuffer compressed) throws IOException {
    assert(compressed.isDirect());
    IOBuffers buffers = m_buffers.get();
    BBContainer output = buffers.output;

    final int uncompressedLength = Snappy.uncompressedLength(compressed);
    final int outputCapacity = buffers.output.b().capacity();
    if (outputCapacity < uncompressedLength) {
        buffers.output.discard();
        output = DBBPool.allocateDirect(Math.max(outputCapacity * 2, uncompressedLength));
        buffers = new IOBuffers(buffers.input, output);
        m_buffers.set(buffers);
    }
    output.b().clear();

    final int actualUncompressedLength = Snappy.uncompress(compressed, output.b());
    assert(uncompressedLength == actualUncompressedLength);

    byte result[] = new byte[actualUncompressedLength];
    output.b().get(result);
    return result;
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:23,代码来源:CompressionService.java

示例7: insert

import org.xerial.snappy.Snappy; //导入依赖的package包/类
/**
 * Insert a tuple into the page, appending its serialized length to the file beforehand
 */
public void insert(MapTuple tuple){

  try {

    // Generate serial data and length
    byte[] serialData = Snappy.compress(Utils.serialize(tuple));
    byte[] serialLen = ByteBuffer.allocate(4).putInt(serialData.length).array();


    // Append compressed objects to the file
    FileOutputStream fos = new FileOutputStream(_tupleFileName, true);
    fos.write(serialLen);
    fos.write(serialData);
    fos.close();

  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
开发者ID:zillabyte,项目名称:motherbrain,代码行数:23,代码来源:TuplePage.java

示例8: snappyCompress

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public void snappyCompress() {
	byte[] raw = gen_.generate(4 * 1024);
	byte[] compressedOutput = new byte[Snappy
			.maxCompressedLength(raw.length)];

	long produced = 0;

	// attempt to compress the block
	while (bytes_ < 1024 * 1048576) { // Compress 1G
		try {
			int compressedSize = Snappy.compress(raw, 0, raw.length,
					compressedOutput, 0);
			bytes_ += raw.length;
			produced += compressedSize;
		} catch (IOException ignored) {
			throw Throwables.propagate(ignored);
		}

		finishedSingleOp();
	}

	message_ = String.format("(output: %.1f%%)", (produced * 100.0)
			/ bytes_);
}
 
开发者ID:ppdai,项目名称:sessdb,代码行数:25,代码来源:DbBenchmark.java

示例9: snappyUncompressArray

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public void snappyUncompressArray() {
	int inputSize = 4 * 1024;
	byte[] compressedOutput = new byte[Snappy
			.maxCompressedLength(inputSize)];
	byte raw[] = gen_.generate(inputSize);
	int compressedLength;
	try {
		compressedLength = Snappy.compress(raw, 0, raw.length,
				compressedOutput, 0);
	} catch (IOException e) {
		throw Throwables.propagate(e);
	}
	// attempt to uncompress the block
	while (bytes_ < 5L * 1024 * 1048576) { // Compress 1G
		try {
			Snappy.uncompress(compressedOutput, 0, compressedLength, raw, 0);
			bytes_ += inputSize;
		} catch (IOException ignored) {
			throw Throwables.propagate(ignored);
		}

		finishedSingleOp();
	}
}
 
开发者ID:ppdai,项目名称:sessdb,代码行数:25,代码来源:DbBenchmark.java

示例10: put

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public boolean put(byte[] key, byte[] value, long timeToLive, long createdTime, boolean isDelete) throws IOException {
	ensureNotClosed();
	Preconditions.checkArgument(key != null && key.length > 0, "Key is empty");
	Preconditions.checkArgument(value != null && value.length > 0, "value is empty");

	IMapEntry mapEntry = null;
	if (isDelete) {
		// make a tombstone
		mapEntry = this.appendTombstone(key);
	} else {
		mapEntry = this.compressionEnabled ?
				this.appendNewCompressed(key, Snappy.compress(value), timeToLive, createdTime) : this.appendNew(key, value, timeToLive, createdTime);
	}

	if (mapEntry == null) { // no space
		return false;
	}

	return true;
}
 
开发者ID:ppdai,项目名称:sessdb,代码行数:21,代码来源:HashMapTable.java

示例11: put

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public boolean put(byte[] key, byte[] value, long timeToLive, long createdTime, boolean isDelete) throws IOException {
	Preconditions.checkArgument(key != null && key.length > 0, "Key is empty");
	Preconditions.checkArgument(value != null && value.length > 0, "value is empty");

	IMapEntry mapEntry = null;
	if (isDelete) {
		// make a tombstone
		mapEntry = this.appendTombstone(key);
	} else {
		mapEntry = this.compressionEnabled ?
				this.appendNewCompressed(key, Snappy.compress(value), timeToLive, createdTime) : this.appendNew(key, value, timeToLive, createdTime);
	}

	if (mapEntry == null) { // no space
		return false;
	}

	return true;
}
 
开发者ID:ppdai,项目名称:levelcache,代码行数:20,代码来源:HashMapTable.java

示例12: writeCompressed

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public static int writeCompressed(DataOutput out, byte[] bytes, int length) throws IOException {
  if (length > COMPRESSION_THRESHOLD && ourCanUseSnappy) {
    SoftReference<byte[]> reference = spareBufferLocal.get();
    byte[] compressedOutputBuffer = reference != null ? reference.get():null;
    int maxCompressedSize = 32 + length + length / 6; // snappy.cc#MaxCompressedLength
    if (compressedOutputBuffer == null || compressedOutputBuffer.length < maxCompressedSize) {
      compressedOutputBuffer = new byte[maxCompressedSize];
      spareBufferLocal.set(new SoftReference<byte[]>(compressedOutputBuffer));
    }
    int compressedSize = Snappy.rawCompress(bytes, 0, length, compressedOutputBuffer, 0);
    DataInputOutputUtil.writeINT(out, -compressedSize);
    out.write(compressedOutputBuffer, 0, compressedSize);
    return compressedSize;
  } else {
    DataInputOutputUtil.writeINT(out, length);
    out.write(bytes, 0, length);
    return length;
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:CompressionUtil.java

示例13: writeListOfValues

import org.xerial.snappy.Snappy; //导入依赖的package包/类
private void writeListOfValues(List<Object> currentBatchValues) throws IOException {
    ByteArrayOutputStream bos;
    DataOutputStream dos;

    //write values
    bos = new ByteArrayOutputStream();
    dos = new DataOutputStream(bos);
    for (Object value : currentBatchValues) {
        byte[] objectAsBytes = SerializationUtils.objectToBytesCheckForNull(value, dataInterface.getObjectClass());
        if (SerializationUtils.getWidth(dataInterface.getObjectClass()) == -1) {
            dos.writeInt(objectAsBytes.length);
        }
        dos.write(objectAsBytes);
    }
    dos.close();
    byte[] origValues = bos.toByteArray();
    byte[] compressedValues = Snappy.compress(origValues);
    //            Log.i("Compressed values from " + origValues.length + " to " + compressedValues.length);
    connection.writeByteArray(compressedValues);
}
 
开发者ID:koendeschacht,项目名称:count-db,代码行数:21,代码来源:RemoteDataInterfaceServer.java

示例14: compress

import org.xerial.snappy.Snappy; //导入依赖的package包/类
@Override
public int compress(byte[] src, int srcPos, int length, byte[] dest,
	 int destPos) throws IOException {
	System.arraycopy(header, 0, dest, destPos, headerLength);

	// Compressed size cannot be greater than what we have available
	maxCompressedSize = dest.length - destPos - headerLength - 4;
	if (Snappy.maxCompressedLength(length) > maxCompressedSize) {
		return -1;
	}

	compressedLength = Snappy.compress(src, srcPos, length, dest, destPos
		 + headerLength + 4);
	writeInt(compressedLength, dest, destPos + headerLength);

	return headerLength + 4 + compressedLength;
}
 
开发者ID:blackberry,项目名称:Krackle,代码行数:18,代码来源:SnappyCompressor.java

示例15: objectToBytes

import org.xerial.snappy.Snappy; //导入依赖的package包/类
public byte[] objectToBytes(Object o) throws IOException {
    try {
        byte[] bytes = MarshallerUtil.obj2bytes(marshaller, o);

        if( DEBUG )
            log.debug( StackTraceUtil.getStackTrace(Thread.currentThread().getStackTrace()) );

        if( USE_SNAPPY_COMPRESSION ) {
            byte[] compressBuf = Snappy.compress(bytes);
            if( DEBUG ) {
                log.debug("KhanGridMarshaller/SIZE=" + bytes.length + "/COMPRESS=" + compressBuf.length);
            }
            return compressBuf;
        } else {
            if( DEBUG ) {
                log.debug("KhanGridMarshaller/SIZE=" + bytes.length );
            }
            return bytes;
        }
    } catch (Exception e) {
        throw new IOException("Exception");
    }
}
 
开发者ID:opennaru-dev,项目名称:khan-session,代码行数:24,代码来源:JBossMarshaller.java


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