[ https://issues.apache.org/jira/browse/GIRAPH-1163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16201078#comment-16201078 ]
ASF GitHub Bot commented on GIRAPH-1163: ---------------------------------------- Github user yukselakinci commented on a diff in the pull request: https://github.com/apache/giraph/pull/52#discussion_r144152115 --- Diff: giraph-core/src/main/java/org/apache/giraph/writable/kryo/KryoWritableWrapper.java --- @@ -120,4 +126,50 @@ public static Writable wrapIfNeeded(Object object) { public static <T> T wrapAndCopy(T object) { return WritableUtils.createCopy(new KryoWritableWrapper<>(object)).get(); } + + /** + * Try converting the object to byte array. + * @param object Object + * @param <T> Type + * @return byte array + */ + public static <T> byte [] tryConvertToByteArray(T object) { + byte [] arr = null; + try { + KryoWritableWrapper<T> wrapper = + new KryoWritableWrapper<>(object); + arr = WritableUtils.toByteArrayUnsafe(wrapper); + // Checkstyle exception due to unsafe conversion + // CHECKSTYLE: stop IllegalCatch + } catch (Exception e) { + // CHECKSTYLE: resume IllegalCatch + LOG.error("Failed to convert to byte array: " + + ExceptionUtils.getStackTrace(e)); + } + return arr; + } + + /** + * Try converting from byte array + * @param arr byte array + * @param <T> type + * @return original object + */ + public static <T> T tryConvertFromByteArray(byte [] arr) { + T result = null; + try { + KryoWritableWrapper<T> wrapper = + new KryoWritableWrapper<>(); + WritableUtils.fromByteArrayUnsafe( --- End diff -- Agreed. > Changes to support sending exceptions over thrift calls. > -------------------------------------------------------- > > Key: GIRAPH-1163 > URL: https://issues.apache.org/jira/browse/GIRAPH-1163 > Project: Giraph > Issue Type: Bug > Reporter: Yuksel Akinci > -- This message was sent by Atlassian JIRA (v6.4.14#64029)