@Test public void testDeepCopyGeneric() { Record record = new Record(Person.SCHEMA$); record.put("name", "John Doe"); record.put("age", 42); record.put("siblingnames", Lists.newArrayList()); Record deepCopyRecord = new AvroDeepCopier.AvroGenericDeepCopier(Person.SCHEMA$) .deepCopy(record); assertEquals(record, deepCopyRecord); assertNotSame(record, deepCopyRecord); }
public T deepCopy(T source) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder); T target = createCopyTarget(); try { datumWriter.write(source, binaryEncoder); binaryEncoder.flush(); binaryDecoder = DecoderFactory.get() .binaryDecoder(byteOutStream.toByteArray(), binaryDecoder); datumReader.read(target, binaryDecoder); } catch (Exception e) { throw new CrunchRuntimeException("Error while deep copying avro value " + source, e); } return target; }
AvroDeepCopier implements Serializable { public T deepCopy(T source) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder); T target = createCopyTarget(); try { datumWriter.write(source, binaryEncoder); binaryEncoder.flush(); binaryDecoder = DecoderFactory.get() .binaryDecoder(byteOutStream.toByteArray(), binaryDecoder); datumReader.read(target, binaryDecoder); } catch (Exception e) { throw new CrunchRuntimeException("Error while deep copying avro value " + source, e); } return target; } }
AvroDeepCopier implements Serializable { public T deepCopy(T source) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder); T target = createCopyTarget(); try { datumWriter.write(source, binaryEncoder); binaryEncoder.flush(); binaryDecoder = DecoderFactory.get() .binaryDecoder(byteOutStream.toByteArray(), binaryDecoder); datumReader.read(target, binaryDecoder); } catch (Exception e) { throw new CrunchRuntimeException("Error while deep copying avro value " + source, e); } return target; } protected  AvroDeepCopier(DatumWriter<T> datumWriter, DatumReader<T> datumReader); }
AvroDeepCopier implements Serializable { public T deepCopy(T source) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder); T target = createCopyTarget(); try { datumWriter.write(source, binaryEncoder); binaryEncoder.flush(); binaryDecoder = DecoderFactory.get() .binaryDecoder(byteOutStream.toByteArray(), binaryDecoder); datumReader.read(target, binaryDecoder); } catch (Exception e) { throw new CrunchRuntimeException("Error while deep copying avro value " + source, e); } return target; } protected  AvroDeepCopier(DatumWriter<T> datumWriter, DatumReader<T> datumReader); T deepCopy(T source); }
AvroDeepCopier implements Serializable { public T deepCopy(T source) { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder); T target = createCopyTarget(); try { datumWriter.write(source, binaryEncoder); binaryEncoder.flush(); binaryDecoder = DecoderFactory.get() .binaryDecoder(byteOutStream.toByteArray(), binaryDecoder); datumReader.read(target, binaryDecoder); } catch (Exception e) { throw new CrunchRuntimeException("Error while deep copying avro value " + source, e); } return target; } protected  AvroDeepCopier(DatumWriter<T> datumWriter, DatumReader<T> datumReader); T deepCopy(T source);  }