/** * High-level API for uncompressing the input byte array. * * @param input * @return the uncompressed byte array * @throws IOException */ public static byte[] uncompress(byte[] input) throws IOException { byte[] result = new byte[Snappy.uncompressedLength(input)]; Snappy.uncompress(input, 0, input.length, result, 0); return result; }
@Override public int decompress(ByteBuffer compressedInput, ByteBuffer decompressedOutput) throws IOException { return Snappy.uncompress(compressedInput, decompressedOutput); } }
/** * Uncompress the input[offset, offset+length) as a String of the given * encoding * * @param input * @param offset * @param length * @param encoding * @return the uncompressed data * @throws IOException */ public static String uncompressString(byte[] input, int offset, int length, Charset encoding) throws IOException, UnsupportedEncodingException { byte[] uncompressed = new byte[uncompressedLength(input, offset, length)]; uncompress(input, offset, length, uncompressed, 0); return new String(uncompressed, encoding); }
public static byte[] decompress(byte[] input) throws IOException { if(!useCompression) return input; return Snappy.uncompress(input); }
/** * Uncompress the input[offset, offset+length) as a String of the given * encoding * * @param input * @param offset * @param length * @param encoding * @return the uncompressed data * @throws IOException */ public static String uncompressString(byte[] input, int offset, int length, String encoding) throws IOException, UnsupportedEncodingException { byte[] uncompressed = new byte[uncompressedLength(input, offset, length)]; uncompress(input, offset, length, uncompressed, 0); return new String(uncompressed, encoding); }
/** * Uncompress the input as a String of the given encoding * * @param input * @param encoding * @return the uncompressed data * @throws IOException * @throws UnsupportedEncodingException */ public static String uncompressString(byte[] input, String encoding) throws IOException, UnsupportedEncodingException { byte[] uncompressed = uncompress(input); return new String(uncompressed, encoding); }
protected void readFully(byte[] fragment, int fragmentLength) throws IOException { if (fragmentLength == 0) { finishedReading = true; return; } // read the entire input data to the buffer compressed = new byte[Math.max(8 * 1024, fragmentLength)]; // 8K System.arraycopy(fragment, 0, compressed, 0, fragmentLength); int cursor = fragmentLength; for (int readBytes = 0; (readBytes = in.read(compressed, cursor, compressed.length - cursor)) != -1; ) { cursor += readBytes; if (cursor >= compressed.length) { byte[] newBuf = new byte[(compressed.length * 2)]; System.arraycopy(compressed, 0, newBuf, 0, compressed.length); compressed = newBuf; } } finishedReading = true; // Uncompress int uncompressedLength = Snappy.uncompressedLength(compressed, 0, cursor); uncompressed = new byte[uncompressedLength]; Snappy.uncompress(compressed, 0, cursor, uncompressed, 0); this.uncompressedCursor = 0; this.uncompressedLimit = uncompressedLength; }
/** * Uncompress the input as a String of the given encoding * * @param input * @param encoding * @return the uncompressed data * @throws IOException */ public static String uncompressString(byte[] input, Charset encoding) throws IOException, UnsupportedEncodingException { byte[] uncompressed = uncompress(input); return new String(uncompressed, encoding); } }
@Override ByteBuffer decompress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate (Snappy.uncompressedLength(in.array(),in.position(),in.remaining())); int size = Snappy.uncompress(in.array(),in.position(),in.remaining(), out.array(), 0); out.limit(size); return out; }
Snappy.uncompress(page, dst);
@Override public ByteBuffer decompress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate (Snappy.uncompressedLength(in.array(),in.position(),in.remaining()-4)); 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; }
public static byte[] decompressWithSnappy(byte[] bytes) { try { if (!Snappy.isValidCompressedBuffer(bytes)) { throw new IllegalArgumentException("Cannot decompress these bytes using Snappy"); } return Snappy.uncompress(bytes); } catch (IOException e) { throw Throwables.throwUncheckedException(e); } } }
@Override public ByteBuffer decompress(ByteBuffer in) throws IOException { int offset = computeOffset(in); ByteBuffer out = ByteBuffer.allocate (Snappy.uncompressedLength(in.array(), offset, in.remaining()-4)); int size = Snappy.uncompress(in.array(), offset, 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; }
public void uncompress(ByteBuffer input, ByteBuffer output) throws IOException { int dlimit = output.limit(); Snappy.uncompress(input, output); // Snappy doesn't match the ICompressor contract w/regards to state it leaves dest ByteBuffer's counters in output.position(output.limit()); output.limit(dlimit); input.position(input.limit()); }
@Override public DataPoint getDataPoint(long timestamp, KDataInput buffer) throws IOException { int buffSz = buffer.readUnsignedShort(); byte[] byteBuffer = new byte[buffSz]; buffer.readFully(byteBuffer, 0, buffSz); String result; if (Snappy.isValidCompressedBuffer(byteBuffer, 0, buffSz)) { byte[] uncompressedArray = new byte[Snappy.uncompressedLength(byteBuffer, 0, buffSz)]; int incompressedLength = Snappy.uncompress(byteBuffer, 0, buffSz, uncompressedArray, 0); result = new String(uncompressedArray, 0, incompressedLength, UTF8); } else { result = new String(byteBuffer, UTF8); } SnappyStringDataPoint ret = new SnappyStringDataPoint(timestamp, result); return ret; }
this.valid = Snappy.uncompress(input, uncompressedDirect);
uncompressed = new byte[uncompressedLength]; int actualUncompressedLength = Snappy.uncompress(compressed, 0, chunkSize, uncompressed, 0); if (uncompressedLength != actualUncompressedLength) { throw new SnappyIOException(SnappyErrorCode.INVALID_CHUNK_SIZE, String.format("expected %,d bytes, but decompressed chunk has %,d bytes", uncompressedLength, actualUncompressedLength));
@Override public Closeable newCache(ImmutableBytesWritable cachePtr, MemoryChunk chunk) throws SQLException { try { int size = Snappy.uncompressedLength(cachePtr.get()); byte[] uncompressed = new byte[size]; Snappy.uncompress(cachePtr.get(), 0, cachePtr.getLength(), uncompressed, 0); return new HashCacheImpl(uncompressed, chunk); } catch (IOException e) { throw ServerUtil.parseServerException(e); } }
int written = Snappy.uncompress(in, inOffset, len, out, offset);
private ByteBuf decompressDirect(ByteBuf input) throws IOException { ByteBuffer in = inputNioBuffer(input); // Increase reader index. input.readerIndex(input.writerIndex()); if (!Snappy.isValidCompressedBuffer(in)) throw new DriverInternalError("Provided frame does not appear to be Snappy compressed"); // If the input is direct we will allocate a direct output buffer as well as this will allow us // to use // Snappy.compress(ByteBuffer, ByteBuffer) and so eliminate memory copies. ByteBuf output = input.alloc().directBuffer(Snappy.uncompressedLength(in)); try { ByteBuffer out = outputNioBuffer(output); int size = Snappy.uncompress(in, out); // Set the writer index so the amount of written bytes is reflected output.writerIndex(output.writerIndex() + size); } catch (IOException e) { // release output buffer so we not leak and rethrow exception. output.release(); throw e; } return output; }