/** * Construct LongsDiffReader * * @param compressedData Input byte array * @param useUnsafeReader use unsafe reader */ public LongsDiffReader(byte[] compressedData, boolean useUnsafeReader) { if (useUnsafeReader) { input = new UnsafeByteArrayInputStream(compressedData); } else { input = new ExtendedByteArrayDataInput(compressedData); } }
/** * Create an extended data input (can be subclassed) * * @param buf Buffer to use for the input * @return ExtendedDataInput object */ public ExtendedDataInput createExtendedDataInput(byte[] buf) { if (useUnsafeSerialization) { return new UnsafeByteArrayInputStream(buf); } else { return new ExtendedByteArrayDataInput(buf); } }
/** * Create an extended data input (can be subclassed) * * @param buf Buffer to use for the input * @param off Where to start reading in the buffer * @param length Maximum length of the buffer * @return ExtendedDataInput object */ public ExtendedDataInput createExtendedDataInput( byte[] buf, int off, int length) { if (useUnsafeSerialization) { return new UnsafeByteArrayInputStream(buf, off, length); } else { return new ExtendedByteArrayDataInput(buf, off, length); } }
public void readStash(ODAGStash stashToReadTo) { ExtendedByteArrayDataInput byteArrayInputCache = null; try { byteArrayInputCache = new ExtendedByteArrayDataInput(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); LOG.info(byteArrayInputCache.available()); stashToReadTo.readFields(byteArrayInputCache); } catch (IOException e) { LOG.info("stashToReadTo: " + stashToReadTo); LOG.info("input.available: " + byteArrayInputCache.available()); LOG.info("input.pos: " + byteArrayInputCache.getPos()); LOG.info("output.pos: " + byteArrayOutputCache.getPos()); throw new RuntimeException(e); } }
/** * Deserialize from given byte array into given writable, * using new instance of ExtendedByteArrayDataInput. * * @param data Byte array representing writable * @param to Object to fill * @param <T> Type of the object */ public static <T extends Writable> void fromByteArray(byte[] data, T to) { try { ExtendedByteArrayDataInput in = new ExtendedByteArrayDataInput(data, 0, data.length); to.readFields(in); if (in.available() != 0) { throw new RuntimeException( "Serialization encountered issues, " + in.available() + " bytes left to be read"); } } catch (IOException e) { throw new RuntimeException(e); } }
public void readEzip(ODAG ezip) { ExtendedByteArrayDataInput byteArrayInputCache = null; try { byteArrayInputCache = new ExtendedByteArrayDataInput(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); //LOG.info(byteArrayInputCache.available()); ezip.setPattern(pattern); ezip.readFields(byteArrayInputCache); } catch (IOException e) { LOG.info("pattern: " + pattern); LOG.info("partId: " + partId); LOG.info("ezip: " + ezip); LOG.info("input.available: " + byteArrayInputCache.available()); LOG.info("input.pos: " + byteArrayInputCache.getPos()); LOG.info("output.pos: " + byteArrayOutputCache.getPos()); throw new RuntimeException(e); } }
public ByteArrayObjectCacheIterator(ByteArrayObjectCache objectCache) { ExtendedByteArrayDataOutput byteArrayOutputCache = objectCache.byteArrayOutputCache; byteArrayInputCache = new ExtendedByteArrayDataInput(byteArrayOutputCache.getByteArray(), 0, byteArrayOutputCache.getPos()); configuration = Configuration.get(); }
/** * Read fields from byteArray to a Writeable object, skipping the size. * Serialization method is choosable * * @param byteArray Byte array to find the fields in. * @param writableObject Object to fill in the fields. * @param unsafe Use unsafe deserialization */ public static void readFieldsFromByteArrayWithSize( byte[] byteArray, Writable writableObject, boolean unsafe) { ExtendedDataInput extendedDataInput; if (unsafe) { extendedDataInput = new UnsafeByteArrayInputStream(byteArray); } else { extendedDataInput = new ExtendedByteArrayDataInput(byteArray); } try { extendedDataInput.readInt(); writableObject.readFields(extendedDataInput); } catch (IOException e) { throw new IllegalStateException( "readFieldsFromByteArrayWithSize: IOException", e); } }
extendedDataInput = new UnsafeByteArrayInputStream(byteArray); } else { extendedDataInput = new ExtendedByteArrayDataInput(byteArray);