本文整理汇总了Java中org.iq80.snappy.Snappy.uncompress方法的典型用法代码示例。如果您正苦于以下问题:Java Snappy.uncompress方法的具体用法?Java Snappy.uncompress怎么用?Java Snappy.uncompress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.iq80.snappy.Snappy
的用法示例。
在下文中一共展示了Snappy.uncompress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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 );
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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;
}
示例6: 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);
}
}
示例7: getMaybeUncompressedBytes
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
private byte[] getMaybeUncompressedBytes(@Nullable byte[] bytes) throws SingularityTranscoderException {
if (bytes == null || bytes.length == 0) {
return bytes;
}
try {
return compressLargeDataObjects ? Snappy.uncompress(bytes, 0, bytes.length) : bytes;
} catch (CorruptionException ce) {
throw new SingularityTranscoderException(ce);
}
}
示例8: uncompressCharSequence
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
@NotNull
public static CharSequence uncompressCharSequence(@NotNull Object string, @NotNull Charset charset) {
if (string instanceof CharSequence) return (CharSequence)string;
byte[] b = (byte[])string;
try {
int uncompressedLength = Snappy.getUncompressedLength(b, 0);
byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength);
int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0);
return new String(bytes, 0, bytesLength, charset);
}
catch (CorruptionException ex) {
throw new RuntimeException(ex);
}
}
示例9: uncompressStringRawBytes
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
@NotNull
public static CharSequence uncompressStringRawBytes(@NotNull Object compressed) {
if (compressed instanceof CharSequence) return (CharSequence)compressed;
byte[] b = (byte[])compressed;
try {
int uncompressedLength = Snappy.getUncompressedLength(b, 0);
byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength);
int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0);
ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes, 0, bytesLength);
@NotNull DataInput in = new DataInputStream(byteStream);
int len = DataInputOutputUtil.readINT(in);
char[] chars = new char[len];
for (int i=0; i<len; i++) {
int c = DataInputOutputUtil.readINT(in);
chars[i] = (char)c;
}
return StringFactory.createShared(chars);
}
catch (CorruptionException ex) {
throw new RuntimeException(ex);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: decompressSnappy
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
private int decompressSnappy(Slice in)
throws IOException
{
byte[] inArray = (byte[]) in.getBase();
int inOffset = (int) (in.getAddress() - ARRAY_BYTE_BASE_OFFSET);
int inLength = in.length();
int uncompressedLength = Snappy.getUncompressedLength(inArray, inOffset);
checkArgument(uncompressedLength <= maxBufferSize, "Snappy requires buffer (%s) larger than max size (%s)", uncompressedLength, maxBufferSize);
allocateOrGrowBuffer(uncompressedLength, false);
return Snappy.uncompress(inArray, inOffset, inLength, buffer, 0);
}
示例11: decompress
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
@Override
public ByteBuffer decompress(ByteBuffer in) throws IOException {
ByteBuffer out = ByteBuffer.allocate
(Snappy.getUncompressedLength(in.array(),in.position()));
int size = Snappy.uncompress(in.array(),in.position(),in.remaining()-4,
out.array(), 0);
out.limit(size);
crc32.reset();
crc32.update(out.array(), 0, size);
if (in.getInt(in.limit()-4) != (int)crc32.getValue())
throw new IOException("Checksum failure");
return out;
}
示例12: inflate
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
@Override
public byte[] inflate(InputStream data) throws CompressionException
{
try
{
byte[] temp = IOUtils.toByteArray(data);
return Snappy.uncompress(temp, 0, temp.length);
}
catch (IOException e)
{
throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
}
}
示例13: decompress
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
/**
* Decompress the given array of bytes.
*
* @return null if the bytes cannot be decompressed
*/
protected byte[] decompress(byte[] in) {
byte[] decompressed = null;
if (in != null) {
try {
decompressed = Snappy.uncompress(in, 0, in.length);
} catch (Exception e) {
getLogger().warn("Failed to decompress data", e);
return null;
}
}
return decompressed;
}
示例14: decode
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
public Object decode(CachedData d) {
byte[] data = d.getData();
if ((d.getFlags() & COMPRESSED) != 0) {
try {
return Snappy.uncompress(data,0,data.length);
} catch (Exception e) {
getLogger().warn("Unable to Uncompress");
data = null;
}
}
return data;
}
示例15: decompress
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
@Override
public void decompress(ByteBuffer in, ByteBuffer out) throws IOException {
int inOffset = in.position();
int uncompressLen =
Snappy.uncompress(in.array(), in.arrayOffset() + inOffset,
in.limit() - inOffset, out.array(), out.arrayOffset() + out.position());
out.position(uncompressLen + out.position());
out.flip();
}