@Test public void testDeepClonePersistent() throws Exception { CharSequence url = new Utf8("http: WebPage.Builder builder = WebPage.newBuilder() .setUrl(url) .setContent(ByteBuffer.wrap("Gora".getBytes("UTF-8"))); WebPage webPage = builder.build(); WebPage clonedWebPage = AvroUtils.deepClonePersistent(webPage); assertThat(clonedWebPage, is(notNullValue())); assertThat(clonedWebPage.getUrl(), is(equalTo(url))); assertThat(clonedWebPage.getContent(), is(notNullValue())); String clonedWebPageContent = new String(clonedWebPage.getContent().array(), "UTF-8"); assertThat(clonedWebPageContent, is(equalTo("Gora"))); }
public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }
AvroUtils { public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } } }
AvroUtils { public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }  }
AvroUtils { public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }  static Map<String, Field> getFieldMap(Schema schema); @SuppressWarnings("unchecked") static Object getEnumValue(Schema schema, String symbol); static Object getEnumValue(Schema schema, int enumOrdinal); static Schema getSchema(Class<? extends PersistentBase> clazz); static String[] getPersistentFieldNames(PersistentBase persistent); static String[] getSchemaFieldNames(Schema schema); static T deepClonePersistent(T persistent); }
AvroUtils { public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }  static Map<String, Field> getFieldMap(Schema schema); @SuppressWarnings("unchecked") static Object getEnumValue(Schema schema, String symbol); static Object getEnumValue(Schema schema, int enumOrdinal); static Schema getSchema(Class<? extends PersistentBase> clazz); static String[] getPersistentFieldNames(PersistentBase persistent); static String[] getSchemaFieldNames(Schema schema); static T deepClonePersistent(T persistent);  }