@Override public int compress(ByteBuffer inDecompressed, ByteBuffer outCompressed) throws IOException { return Snappy.compress(inDecompressed, outCompressed); } }
public static byte[] compress(byte[] input) throws IOException { if(!useCompression) return input; return Snappy.compress(input); }
/** * Compress the input string using the given encoding * * @param s * @param encoding * @return the compressed data * @throws UnsupportedEncodingException * @throws IOException */ public static byte[] compress(String s, String encoding) throws UnsupportedEncodingException, IOException { byte[] data = s.getBytes(encoding); return compress(data); }
/** * Compress the input string using the given encoding * * @param s * @param encoding * @return the compressed data * @throws UnsupportedEncodingException * @throws IOException */ public static byte[] compress(String s, Charset encoding) throws IOException { byte[] data = s.getBytes(encoding); return compress(data); }
/** * Compress the input String * * @param s * @return the compressed data * @throws IOException */ public static byte[] compress(String s) throws IOException { try { return compress(s, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 encoder is not found"); } }
@Override public void writeValueToBuffer(DataOutput buffer) throws IOException { byte[] compressedBytes = Snappy.compress(m_value); buffer.writeShort(compressedBytes.length); buffer.write(compressedBytes); }
@Override ByteBuffer compress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())); int size = Snappy.compress(in.array(), in.position(), in.remaining(), out.array(), 0); out.limit(size); return out; }
@Override public ByteBuffer compress(ByteBuffer in) throws IOException { ByteBuffer out = ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4); int size = Snappy.compress(in.array(), in.position(), in.remaining(), out.array(), 0); crc32.reset(); crc32.update(in.array(), in.position(), in.remaining()); out.putInt(size, (int)crc32.getValue()); out.limit(size+4); return out; }
@Override public ByteBuffer compress(ByteBuffer in) throws IOException { int offset = computeOffset(in); ByteBuffer out = ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4); int size = Snappy.compress(in.array(), offset, in.remaining(), out.array(), 0); crc32.reset(); crc32.update(in.array(), offset, in.remaining()); out.putInt(size, (int)crc32.getValue()); out.limit(size+4); return out; }
Snappy.compress(directInputBuffer, outputBuffer);
/** * @param compactPage Compacted page. * @param compactSize Compacted page size. * @return Compressed page. */ private ByteBuffer compressPageSnappy(ByteBuffer compactPage, int compactSize) { ByteBuffer compressedPage = compressBuf.get(); copyPageHeader(compactPage, compressedPage, compactSize); try { int compressedSize = Snappy.compress(compactPage, compressedPage); assert compressedPage.limit() == PageIO.COMMON_HEADER_END + compressedSize; } catch (IOException e) { throw new IgniteException("Failed to compress page with Snappy.", e); } compactPage.position(0); compressedPage.position(0); return compressedPage; }
protected void compressInput() throws IOException { if (inputCursor <= 0) { return; // no need to dump } if (!headerWritten) { outputCursor = writeHeader(); headerWritten = true; } // Compress and dump the buffer content if (!hasSufficientOutputBufferFor(inputCursor)) { dumpOutput(); } writeBlockPreemble(); int compressedSize = Snappy.compress(inputBuffer, 0, inputCursor, outputBuffer, outputCursor + 4); // Write compressed data size writeInt(outputBuffer, outputCursor, compressedSize); outputCursor += 4 + compressedSize; inputCursor = 0; }
@Override public void compress(final List<ByteBuf> source, final BsonOutput target) { int uncompressedSize = getUncompressedSize(source); byte[] singleByteArraySource = new byte[uncompressedSize]; copy(source, singleByteArraySource); try { byte[] out = new byte[Snappy.maxCompressedLength(uncompressedSize)]; int compressedSize = Snappy.compress(singleByteArraySource, 0, singleByteArraySource.length, out, 0); target.writeBytes(out, 0, compressedSize); } catch (IOException e) { throw new MongoInternalException("Unexpected IOException", e); } }
public static byte[] compressWithSnappy(byte[] bytes) { try { return Snappy.compress(bytes); } catch (IOException e) { throw Throwables.throwUncheckedException(e); } }
private ByteBuf compressHeap(ByteBuf input) throws IOException { int maxCompressedLength = Snappy.maxCompressedLength(input.readableBytes()); int inOffset = input.arrayOffset() + input.readerIndex(); byte[] in = input.array(); int len = input.readableBytes(); // Increase reader index. input.readerIndex(input.writerIndex()); // Allocate a heap buffer from the ByteBufAllocator as we may use a PooledByteBufAllocator and // so // can eliminate the overhead of allocate a new byte[]. ByteBuf output = input.alloc().heapBuffer(maxCompressedLength); try { // Calculate the correct offset. int offset = output.arrayOffset() + output.writerIndex(); byte[] out = output.array(); int written = Snappy.compress(in, inOffset, len, out, offset); // Increase the writerIndex with the written bytes. output.writerIndex(output.writerIndex() + written); } catch (IOException e) { // release output buffer so we not leak and rethrow exception. output.release(); throw e; } return output; }
private ByteBuf compressDirect(ByteBuf input) throws IOException { int maxCompressedLength = Snappy.maxCompressedLength(input.readableBytes()); // 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(maxCompressedLength); try { ByteBuffer in = inputNioBuffer(input); // Increase reader index. input.readerIndex(input.writerIndex()); ByteBuffer out = outputNioBuffer(output); int written = Snappy.compress(in, out); // Set the writer index so the amount of written bytes is reflected output.writerIndex(output.writerIndex() + written); } catch (IOException e) { // release output buffer so we not leak and rethrow exception. output.release(); throw e; } return output; }
int compressedSize = Snappy.compress(baOut.getBuffer(), 0, baOut.size(), compressed, 0);
@Override public byte[] compressInt(int[] unCompInput) { try { return Snappy.compress(unCompInput); } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } }
public void compress(ByteBuffer input, ByteBuffer output) throws IOException { int dlimit = output.limit(); Snappy.compress(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()); }
public void compress(ByteBuffer input, ByteBuffer output) throws IOException { int dlimit = output.limit(); Snappy.compress(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()); }