/** * 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); } }
@Override public V getValue() { if (cachedValue != null) { return cachedValue; // Return always same instance } DataInput dis = new UnsafeByteArrayInputStream(valueBytes); cachedValue = getConf().createVertexValue(); try { cachedValue.readFields(dis); } catch (IOException ioe) { throw new RuntimeException("Could not deserialize vertex value", ioe); } // Forget the serialized data, because we have cached the object valueBytes = null; return cachedValue; }
/** * 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 extendedDataInput; if (unsafe) { extendedDataInput = new UnsafeByteArrayInputStream(byteArray); } else { extendedDataInput = new ExtendedByteArrayDataInput(byteArray);
new UnsafeByteArrayInputStream(out.getByteArray(), 0, out.getPos()); to.readFields(in);