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


Java Snappy类代码示例

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


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

示例1: compressSnappy

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public static byte[] compressSnappy(final BlockValue bv, final FTableDescriptor td) {
  byte[] bytes = null;
  final int totalSize = bv.getValueSize() + (bv.size() * 4);
  try (HeapDataOutputStream hdos = new HeapDataOutputStream(totalSize, null, true)) {
    for (final byte[] rec : bv.getRecords()) {
      hdos.writeInt(rec.length);
      hdos.write(rec);
    }
    // bytes = Snappy.compress(hdos.toByteArray());
    bytes = hdos.toByteArray();
    byte[] compressedOut = new byte[Snappy.maxCompressedLength(bytes.length)];
    int compressedSize = Snappy.compress(bytes, 0, bytes.length, compressedOut, 0);
    bytes = Arrays.copyOf(compressedOut, compressedSize);
  } catch (IOException e) {
    logger.error("Error converting to Snappy format.", e);
  }
  return bytes;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:OrcUtils.java

示例2: writeCompressedWithoutOriginalBufferLength

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public static int writeCompressedWithoutOriginalBufferLength(@NotNull DataOutput out, @NotNull byte[] bytes, int length) throws IOException {
  long started = DUMP_COMPRESSION_STATS ? System.nanoTime() : 0;

  final byte[] compressedOutputBuffer = spareBufferLocal.getBuffer(Snappy.maxCompressedLength(length));
  int compressedSize = Snappy.compress(bytes, 0, length, compressedOutputBuffer, 0);

  final long time = (DUMP_COMPRESSION_STATS ? System.nanoTime() : 0) - started;
  mySizeAfterCompression.addAndGet(compressedSize);
  mySizeBeforeCompression.addAndGet(length);
  int requests = myCompressionRequests.incrementAndGet();
  long l = myCompressionTime.addAndGet(time);

  if (DUMP_COMPRESSION_STATS && requests % 1000  == 0) {
    System.out.println("Compressed " + requests + " times, size:" + mySizeBeforeCompression + "->" + mySizeAfterCompression + " for " + (l  / 1000000) + "ms");
  }

  DataInputOutputUtil.writeINT(out, compressedSize);
  out.write(compressedOutputBuffer, 0, compressedSize);

  return compressedSize;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CompressionUtil.java

示例3: readCompressedWithoutOriginalBufferLength

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@NotNull
public static byte[] readCompressedWithoutOriginalBufferLength(@NotNull DataInput in) throws IOException {
  int size = DataInputOutputUtil.readINT(in);

  byte[] bytes = spareBufferLocal.getBuffer(size);
  in.readFully(bytes, 0, size);

  int decompressedRequests = myDecompressionRequests.incrementAndGet();
  long started = DUMP_COMPRESSION_STATS ? System.nanoTime() : 0;

  byte[] decompressedResult = Snappy.uncompress(bytes, 0, size);

  long doneTime = (DUMP_COMPRESSION_STATS ? System.nanoTime() : 0) - started;
  long decompressedSize = myDecompressedSize.addAndGet(size);
  long decompressedTime = myDecompressionTime.addAndGet(doneTime);
  if (DUMP_COMPRESSION_STATS && decompressedRequests % 1000 == 0) {
    System.out.println("Decompressed " + decompressedRequests + " times, size: " + decompressedSize  + " for " + (decompressedTime / 1000000) + "ms");
  }

  return decompressedResult;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CompressionUtil.java

示例4: compressCharSequence

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@NotNull
public static Object compressCharSequence(@NotNull CharSequence string, @NotNull Charset charset) {
  if (string.length() < STRING_COMPRESSION_THRESHOLD) {
    if (string instanceof CharBuffer && ((CharBuffer)string).capacity() > STRING_COMPRESSION_THRESHOLD) {
      string = string.toString();   // shrink to size
    }
    return string;
  }
  try {
    return Snappy.compress(string.toString().getBytes(charset));
  }
  catch (CorruptionException ex) {
    ex.printStackTrace();
    return string;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CompressionUtil.java

示例5: decompressBytes

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public static byte[] decompressBytes(byte[] bytesArray) throws ClientException  { 
	
	byte[] checkSumBuf = new byte[8];
	checkSumBuf[0] = bytesArray[bytesArray.length-8];
	checkSumBuf[1] = bytesArray[bytesArray.length-7];
	checkSumBuf[2] = bytesArray[bytesArray.length-6];
	checkSumBuf[3] = bytesArray[bytesArray.length-5];
	checkSumBuf[4] = bytesArray[bytesArray.length-4];
	checkSumBuf[5] = bytesArray[bytesArray.length-3];
	checkSumBuf[6] = bytesArray[bytesArray.length-2];
	checkSumBuf[7] = bytesArray[bytesArray.length-1];
	
	
	ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
    buffer.put(checkSumBuf);
    buffer.flip();//need flip 
    long checkSum = buffer.getLong();
    
    Adler32 adler32 = new Adler32();
	adler32.update(bytesArray, 0, bytesArray.length-8);
	if(checkSum !=adler32.getValue())
		throw new ClientException("Data corruption detected - checksum failure. Please, try again.");
    
	return Snappy.uncompress(bytesArray, 0, bytesArray.length -8 );
}
 
开发者ID:PortfolioEffect,项目名称:PE-HFT-Java,代码行数:26,代码来源:ArrayUtil.java

示例6: shouldCompressSmallContent

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@Test
public void shouldCompressSmallContent() {
    String text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo " +
        "ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient " +
        "montes, nascetur ridiculus mus.";

    channel.pipeline().addFirst(new SnappyFeatureHandler());

    ByteBuf content = Unpooled.copiedBuffer(text, CharsetUtil.UTF_8);

    UpsertRequest request = new UpsertRequest("key", content.copy(), "bucket");
    request.partition((short) 512);
    channel.writeOutbound(request);
    FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound();
    assertNotNull(outbound);

    assertEquals(KeyValueHandler.DATATYPE_SNAPPY, outbound.getDataType());

    byte[] compressed = new byte[outbound.content().readableBytes()];
    outbound.content().getBytes(0, compressed);
    byte[] uncompressed = Snappy.uncompress(compressed, 0, compressed.length);
    assertArrayEquals(text.getBytes(CharsetUtil.UTF_8), uncompressed);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:24,代码来源:KeyValueHandlerTest.java

示例7: shouldDecompressSmallContent

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@Test
public void shouldDecompressSmallContent() {
    String text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo " +
        "ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient " +
        "montes, nascetur ridiculus mus.";

    channel.pipeline().addFirst(new SnappyFeatureHandler());

    ByteBuf content = Unpooled.wrappedBuffer(Snappy.compress(text.getBytes(CharsetUtil.UTF_8)));
    FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(KEY, Unpooled.EMPTY_BUFFER,
        content.copy());
    response.setDataType(KeyValueHandler.DATATYPE_SNAPPY);

    GetRequest requestMock = mock(GetRequest.class);
    requestQueue.add(requestMock);
    channel.writeInbound(response);

    GetResponse event = (GetResponse) eventSink.responseEvents().get(0).getMessage();
    assertEquals(text, event.content().toString(CHARSET));
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:21,代码来源:KeyValueHandlerTest.java

示例8: set

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public boolean set(final String key, final String value) throws InterruptedException, ExecutionException, UnsupportedEncodingException,
		MasterMayBeLostException {
	byte[] b = value.getBytes("utf-8");
	b = Snappy.compress(b);// ѹ��
	Add add = Add.newBuilder().setKey(key).setValue(ByteString.copyFrom(b)).build();
	Future<byte[]> future = operator.add(add.toByteArray(), CommandType.USER_WRITE);
	try {
		byte[] response = future.get(5, TimeUnit.SECONDS);
		if (response[0] == 1) {
			return true;
		} else {
			return false;
		}
	} catch (TimeoutException e) {
		throw new MasterMayBeLostException();
	}
}
 
开发者ID:qinannmj,项目名称:FireFly,代码行数:18,代码来源:ConfigClient.java

示例9: compress

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public int compress(byte[] value, int offset) {
	int size;
	if (end > start) {
		value[offset] = 0;
		size = Snappy.compress(buffer, start, end - start, value,
				offset + 1);
	} else {
		value[offset] = 1;
		size = Snappy.compress(buffer, start, buffer.length - start, value,
				offset + 5);
		Utils.encodeInt(value, offset + 1, size);
		size += 4 + Snappy.compress(buffer, 0, end, value, offset + 5
				+ size);
	}
	return size + 1;
}
 
开发者ID:jrbn,项目名称:ajira,代码行数:17,代码来源:ByteArray.java

示例10: decompress

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public void decompress(byte[] value, int offset, int len) {
	if (value[offset] == 0) {
		grow(Snappy.getUncompressedLength(value, offset + 1));
		end = Snappy.uncompress(value, offset + 1, len - 1, buffer, 0);
	} else {
		int s = Utils.decodeInt(value, offset + 1);
		// Calculate uncompress size
		offset += 5;
		len -= 5;
		int un_s = Snappy.getUncompressedLength(value, offset);
		un_s += Snappy.getUncompressedLength(value, offset + s);
		grow(un_s);

		end = Snappy.uncompress(value, offset, s, buffer, 0);
		end += Snappy.uncompress(value, offset + s, len - s, buffer, end);
	}
}
 
开发者ID:jrbn,项目名称:ajira,代码行数:18,代码来源:ByteArray.java

示例11: writeCompressedWithoutOriginalBufferLength

import org.iq80.snappy.Snappy; //导入依赖的package包/类
public static int writeCompressedWithoutOriginalBufferLength(@Nonnull DataOutput out, @Nonnull byte[] bytes, int length) throws IOException {
  long started = System.nanoTime();

  final byte[] compressedOutputBuffer = spareBufferLocal.getBuffer(Snappy.maxCompressedLength(length));
  int compressedSize = Snappy.compress(bytes, 0, length, compressedOutputBuffer, 0);

  final long time = System.nanoTime() - started;
  mySizeAfterCompression.addAndGet(compressedSize);
  mySizeBeforeCompression.addAndGet(length);
  int requests = myCompressionRequests.incrementAndGet();
  long l = myCompressionTime.addAndGet(time);

  if (DUMP_COMPRESSION_STATS && requests % 1000  == 0) {
    System.out.println("Compressed " + requests + " times, size:" + mySizeBeforeCompression + "->" + mySizeAfterCompression + " for " + (l  / 1000000) + "ms");
  }

  DataInputOutputUtil.writeINT(out, compressedSize);
  out.write(compressedOutputBuffer, 0, compressedSize);

  return compressedSize;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:CompressionUtil.java

示例12: readCompressedWithoutOriginalBufferLength

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@Nonnull
public static byte[] readCompressedWithoutOriginalBufferLength(@Nonnull DataInput in) throws IOException {
  int size = DataInputOutputUtil.readINT(in);

  byte[] bytes = spareBufferLocal.getBuffer(size);
  in.readFully(bytes, 0, size);

  int decompressedRequests = myDecompressionRequests.incrementAndGet();
  long started = System.nanoTime();

  byte[] decompressedResult = Snappy.uncompress(bytes, 0, size);

  long doneTime = System.nanoTime() - started;
  long decompressedSize = myDecompressedSize.addAndGet(size);
  long decompressedTime = myDecompressionTime.addAndGet(doneTime);
  if (DUMP_COMPRESSION_STATS && decompressedRequests % 1000 == 0) {
    System.out.println("Decompressed " + decompressedRequests + " times, size: " + decompressedSize  + " for " + (decompressedTime / 1000000) + "ms");
  }

  return decompressedResult;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:CompressionUtil.java

示例13: compressCharSequence

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@Nonnull
public static Object compressCharSequence(@Nonnull CharSequence string, @Nonnull Charset charset) {
  if (string.length() < STRING_COMPRESSION_THRESHOLD) {
    if (string instanceof CharBuffer && ((CharBuffer)string).capacity() > STRING_COMPRESSION_THRESHOLD) {
      string = string.toString();   // shrink to size
    }
    return string;
  }
  try {
    return Snappy.compress(string.toString().getBytes(charset));
  }
  catch (CorruptionException ex) {
    ex.printStackTrace();
    return string;
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:CompressionUtil.java

示例14: decompress

import org.iq80.snappy.Snappy; //导入依赖的package包/类
@Override
public byte[] decompress(byte[] input) {
  try {
    return Snappy.uncompress(input, 0, input.length);
  } catch (CorruptionException e) {
    throw new CompressionException(e);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:9,代码来源:SnappyCompressor.java

示例15: getMaybeCompressedBytes

import org.iq80.snappy.Snappy; //导入依赖的package包/类
private byte[] getMaybeCompressedBytes(@Nullable byte[] bytes) throws SingularityTranscoderException {

    if (bytes == null || bytes.length == 0) {
      return bytes;
    }

    return compressLargeDataObjects ? Snappy.compress(bytes) : bytes;
  }
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:9,代码来源:CompressingTranscoder.java


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