/** * Create an extended data output (can be subclassed) * * @return ExtendedDataOutput object */ public ExtendedDataOutput createExtendedDataOutput() { if (useUnsafeSerialization) { return new UnsafeByteArrayOutputStream(); } else { return new ExtendedByteArrayDataOutput(); } }
/** * Create an extended data output (can be subclassed) * * @param expectedSize Expected size * @return ExtendedDataOutput object */ public ExtendedDataOutput createExtendedDataOutput(int expectedSize) { if (useUnsafeSerialization) { return new UnsafeByteArrayOutputStream(expectedSize); } else { return new ExtendedByteArrayDataOutput(expectedSize); } }
/** * Construct LongsDiffWriter * @param useUnsafeWriter use unsafe writer */ public LongsDiffWriter(boolean useUnsafeWriter) { if (useUnsafeWriter) { out = new UnsafeByteArrayOutputStream(); } else { out = new ExtendedByteArrayDataOutput(); } }
/** * Create an extended data output (can be subclassed) * * @param buf Buffer to use for the output (reuse perhaps) * @param pos How much of the buffer is already used * @return ExtendedDataOutput object */ public ExtendedDataOutput createExtendedDataOutput(byte[] buf, int pos) { if (useUnsafeSerialization) { return new UnsafeByteArrayOutputStream(buf, pos); } else { return new ExtendedByteArrayDataOutput(buf, pos); } }
private <W extends Writable> W copyWritable(W writable) { if (reusedOut == null) { reusedOut = new UnsafeByteArrayOutputStream(); } if (reusedIn == null) { reusedIn = new UnsafeReusableByteArrayInput(); } return WritableUtils.createCopy(reusedOut, reusedIn, writable, null); }
/** * Serialize given writable to byte array, * using new instance of UnsafeByteArrayOutputStream. * * @param w Writable object * @return array of bytes * @param <T> Type of the object */ public static <T extends Writable> byte[] toByteArrayUnsafe(T w) { try { UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(); w.write(out); return out.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Constructor * * Creates new instances of all reducers from * {@link WorkerAggregatorHandler} */ public ThreadLocalWorkerGlobalCommUsage() { threadReducerMap = Maps.newHashMapWithExpectedSize( WorkerAggregatorHandler.this.reducerMap.size()); UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(); UnsafeReusableByteArrayInput in = new UnsafeReusableByteArrayInput(); for (Entry<String, Reducer<Object, Writable>> entry : reducerMap.entrySet()) { ReduceOperation<Object, Writable> globalReduceOp = entry.getValue().getReduceOp(); ReduceOperation<Object, Writable> threadLocalCopy = WritableUtils.createCopy(out, in, globalReduceOp, conf); threadReducerMap.put(entry.getKey(), new Reducer<>(threadLocalCopy)); } }
/** * Serializes the value to bytes, stored in field valueBytes * @param value new vertex value */ private void setSerializedValue(V value) { UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(); try { value.write(bos); bos.close(); } catch (IOException ioe) { throw new RuntimeException("Could not serialize vertex value", ioe); } this.valueBytes = bos.toByteArray(); cachedValue = null; }
UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(); from.write(out); if (checkOverRead) {
/** * Write object to a byte array with the first 4 bytes as the size of the * entire buffer (including the size). * * @param writableObject Object to write from. * @param buffer Use this buffer instead * @param unsafe Use unsafe serialization? * @return Byte array with serialized object. */ public static byte[] writeToByteArrayWithSize(Writable writableObject, byte[] buffer, boolean unsafe) { ExtendedDataOutput extendedDataOutput; if (unsafe) { extendedDataOutput = new UnsafeByteArrayOutputStream(buffer); } else { extendedDataOutput = new ExtendedByteArrayDataOutput(buffer); } try { extendedDataOutput.writeInt(-1); writableObject.write(extendedDataOutput); extendedDataOutput.writeInt(0, extendedDataOutput.getPos()); } catch (IOException e) { throw new IllegalStateException("writeToByteArrayWithSize: " + "IOException", e); } return extendedDataOutput.getByteArray(); }
@Override public void doRequest(ServerData serverData) { UnsafeByteArrayOutputStream reusedOut = new UnsafeByteArrayOutputStream(); UnsafeReusableByteArrayInput reusedIn = new UnsafeReusableByteArrayInput();
ExtendedDataOutput extendedDataOutput; if (unsafe) { extendedDataOutput = new UnsafeByteArrayOutputStream(buffer); } else { extendedDataOutput = new ExtendedByteArrayDataOutput(buffer);