private void initialize() { byteArrayOutputCache = new ExtendedByteArrayDataOutput(); }
@Override public void write(DataOutput dataOutput) throws IOException { dataOutput.writeInt(byteArrayOutputCache.getPos()); dataOutput.write(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); }
@Override public void skipBytes(int bytesToSkip) { ensureWritable(bytesToSkip); count += bytesToSkip; }
@Override public void readFields(DataInput dataInput) throws IOException { int size = dataInput.readInt(); byteArrayOutputCache.reset(); byteArrayOutputCache.skipBytes(size); dataInput.readFully(byteArrayOutputCache.getByteArray(), 0, size); }
/** * Serialize given writable object, and return it's size. * * @param w Writable object * @return it's size after serialization */ public static int size(Writable w) { try { ExtendedByteArrayDataOutput out = new ExtendedByteArrayDataOutput(); w.write(out); return out.getPos(); } catch (IOException e) { throw new RuntimeException(e); } }
private synchronized void decompress() { if (uncompressed) { return; } //LOG.info("Big no no"); //long start = System.currentTimeMillis(); LZ4FastDecompressor decompressor = lz4factory.fastDecompressor(); ByteBuffer dest = ByteBuffer.allocate(uncompressedSize); ByteBuffer src = ByteBuffer.wrap(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); decompressor.decompress(src, 0, dest, 0, uncompressedSize); byteArrayOutputCache = new ExtendedByteArrayDataOutput(dest.array(), uncompressedSize); uncompressed = true; }
@Override public boolean isEmpty() { return byteArrayOutputCache.getPos() == 0; }
/** * Serialize given writable to byte array, * using new instance of ExtendedByteArrayDataOutput. * * @param w Writable object * @return array of bytes * @param <T> Type of the object */ public static <T extends Writable> byte[] toByteArray(T w) { try { ExtendedByteArrayDataOutput out = new ExtendedByteArrayDataOutput(); w.write(out); return out.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
public void reset() { if (byteArrayOutputCache != null) { byteArrayOutputCache.reset(); } partId = -1; }
private void compress() { if (!uncompressed) { return; } uncompressedSize = byteArrayOutputCache.getPos(); LZ4Compressor lz4Compressor = lz4factory.fastCompressor(); int maxCompressedLength = lz4Compressor.maxCompressedLength(uncompressedSize); ByteBuffer compressed = ByteBuffer.wrap(new byte[maxCompressedLength]); int compressedLength = lz4Compressor.compress(ByteBuffer.wrap(byteArrayOutputCache.getByteArray()), 0, uncompressedSize, compressed, 0, maxCompressedLength); byteArrayOutputCache = new ExtendedByteArrayDataOutput(compressed.array(), compressedLength); uncompressed = false; }
public boolean isEmpty() { return byteArrayOutputCache.getPos() == 0; }
@Override public void readFields(DataInput dataInput) throws IOException { int size = dataInput.readInt(); byteArrayOutputCache.reset(); byteArrayOutputCache.skipBytes(size); dataInput.readFully(byteArrayOutputCache.getByteArray(), 0, size); }
public void reset() { byteArrayOutputCache.reset(); }
private void compress() { if (!uncompressed) { return; } uncompressedSize = byteArrayOutputCache.getPos(); LZ4Compressor lz4Compressor = lz4factory.fastCompressor(); int maxCompressedLength = lz4Compressor.maxCompressedLength(uncompressedSize); ByteBuffer compressed = ByteBuffer.wrap(new byte[maxCompressedLength]); int compressedLength = lz4Compressor.compress(ByteBuffer.wrap(byteArrayOutputCache.getByteArray()), 0, uncompressedSize, compressed, 0, maxCompressedLength); byteArrayOutputCache = new ExtendedByteArrayDataOutput(compressed.array(), compressedLength); uncompressed = false; }
public void write(DataOutput dataOutput) throws IOException { dataOutput.writeInt(byteArrayOutputCache.getPos()); dataOutput.write(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); }
private void initialize() { byteArrayOutputCache = new ExtendedByteArrayDataOutput(); }
public boolean isEmpty() { return byteArrayOutputCache.getPos() == 0; }
@Override public void readFields(DataInput dataInput) throws IOException { if (pattern == null) { pattern = Configuration.get().createPattern(); } pattern.readFields(dataInput); partId = dataInput.readInt(); int size = dataInput.readInt(); byteArrayOutputCache.reset(); byteArrayOutputCache.skipBytes(size); dataInput.readFully(byteArrayOutputCache.getByteArray(), 0, size); }
public void reset() { byteArrayOutputCache.reset(); }
private void decompressDataInput() { if (!Configuration.get().isUseCompressedCaches() || uncompressed) { return; } //LOG.info("Big no no"); LZ4FastDecompressor decompressor = lz4factory.fastDecompressor(); ByteBuffer dest = ByteBuffer.allocate(uncompressedSize); ByteBuffer src = ByteBuffer.wrap(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); decompressor.decompress(src, 0, dest, 0, uncompressedSize); byteArrayOutputCache = new ExtendedByteArrayDataOutput(dest.array(), uncompressedSize); uncompressed = true; }