/** * Calculates the hashcode for the serializable object based on its content. * @param object serializable object. * @return the hashcode for serializable object. */ private static String getHashCodeBasedOnObjectContent(Serializable object) { try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // in-memory serialization of Configuration serialize(object, outputStream); // Instead of hexEncoding outputStream.toByteArray() directly we // use a message digest here to keep the length of the // hashcode reasonable final MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(outputStream.toByteArray()); return BaseEncoding.base16().upperCase().encode(digest.digest()); } catch (final IOException | NoSuchAlgorithmException ex) { // rethrow as unchecked exception throw new IllegalStateException("Unable to calculate hashcode.", ex); } }
/** * Calculates the hashcode for the serializable object based on its content. * @param object serializable object. * @return the hashcode for serializable object. */ private static String getHashCodeBasedOnObjectContent(Serializable object) { try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // in-memory serialization of Configuration serialize(object, outputStream); // Instead of hexEncoding outputStream.toByteArray() directly we // use a message digest here to keep the length of the // hashcode reasonable final MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(outputStream.toByteArray()); return BaseEncoding.base16().upperCase().encode(digest.digest()); } catch (final IOException | NoSuchAlgorithmException ex) { // rethrow as unchecked exception throw new IllegalStateException("Unable to calculate hashcode.", ex); } }