@Override protected T deserialize(T reuse, DataInputView dataInput) throws IOException { reuse.read(dataInput); return reuse; } }
/** * Clones the given writable using the {@link IOReadableWritable serialization}. * * @param original Object to clone * @param <T> Type of the object to clone * @return Cloned object * @throws IOException Thrown is the serialization fails. */ public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException { if (original == null) { return null; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(baos)) { original.write(out); } final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); try (DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais)) { @SuppressWarnings("unchecked") T copy = (T) instantiate(original.getClass()); copy.read(in); return copy; } }
@Override protected T deserialize(T reuse, DataInputView dataInput) throws IOException { reuse.read(dataInput); return reuse; } }
@Override protected T deserialize(T reuse, DataInputView dataInput) throws IOException { reuse.read(dataInput); return reuse; } }
/** * Clones the given writable using the {@link IOReadableWritable serialization}. * * @param original Object to clone * @param <T> Type of the object to clone * @return Cloned object * @throws IOException Thrown is the serialization fails. */ public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException { if (original == null) { return null; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(baos)) { original.write(out); } final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); try (DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais)) { @SuppressWarnings("unchecked") T copy = (T) instantiate(original.getClass()); copy.read(in); return copy; } }
/** * Clones the given writable using the {@link IOReadableWritable serialization}. * * @param original Object to clone * @param <T> Type of the object to clone * @return Cloned object * @throws IOException Thrown is the serialization fails. */ public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException { if (original == null) { return null; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(baos)) { original.write(out); } final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); try (DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais)) { @SuppressWarnings("unchecked") T copy = (T) instantiate(original.getClass()); copy.read(in); return copy; } }