GORA-487 Edited AvroUtils.java duplicate code lines
Project: http://git-wip-us.apache.org/repos/asf/gora/repo Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/4192c875 Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/4192c875 Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/4192c875 Branch: refs/heads/master Commit: 4192c8751e546890e50da550cc7b8f737c91e502 Parents: 6428e5d Author: cihad guzel <[email protected]> Authored: Thu Aug 18 21:41:37 2016 +0300 Committer: cihad guzel <[email protected]> Committed: Thu Aug 18 21:41:37 2016 +0300 ---------------------------------------------------------------------- .../main/java/org/apache/gora/util/AvroUtils.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/gora/blob/4192c875/gora-core/src/main/java/org/apache/gora/util/AvroUtils.java ---------------------------------------------------------------------- diff --git a/gora-core/src/main/java/org/apache/gora/util/AvroUtils.java b/gora-core/src/main/java/org/apache/gora/util/AvroUtils.java index 690cbd0..d07c6c2 100644 --- a/gora-core/src/main/java/org/apache/gora/util/AvroUtils.java +++ b/gora-core/src/main/java/org/apache/gora/util/AvroUtils.java @@ -100,26 +100,21 @@ public class AvroUtils { } public static <T extends PersistentBase> T deepClonePersistent(T persistent) { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - BinaryEncoder enc = EncoderFactory.get().binaryEncoder(bos, null); - SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>( - persistent.getSchema()); + final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); + final byte[] byteData; try { - writer.write(persistent, enc); - enc.flush(); + 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."); } - byte[] value = bos.toByteArray(); - Decoder dec = DecoderFactory.get().binaryDecoder(value, null); + @SuppressWarnings("unchecked") - SpecificDatumReader<T> reader = new SpecificDatumReader<>( - (Class<T>) persistent.getClass()); + final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { - return reader.read(null, dec); + return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - "
