/** * Static method to get an MD5Digest from a binary byte representation * @param md5Bytes * @return a filled out MD5Digest */ public static MD5Digest fromBytes(byte[] md5Bytes) { Preconditions.checkArgument(md5Bytes.length == MD5_BYTES_LENGTH, "md5 bytes must be " + MD5_BYTES_LENGTH + " bytes in length, found " + md5Bytes.length + " bytes."); String md5String = Hex.encodeHexString(md5Bytes); return new MD5Digest(md5String, md5Bytes); }
/** * Static method to get an MD5Digest from a binary byte representation. * @param md5Bytes * @param offset in the byte array to start reading from * @return a filled out MD5Digest */ public static MD5Digest fromBytes(byte[] md5Bytes, int offset) { byte[] md5BytesCopy = Arrays.copyOfRange(md5Bytes, offset, offset + MD5_BYTES_LENGTH); //TODO: Replace this with a version that encodes without needing a copy. String md5String = Hex.encodeHexString(md5BytesCopy); return new MD5Digest(md5String, md5BytesCopy); }
/** * Static method to get an MD5Digest from a human-readable string representation * @param md5String * @return a filled out MD5Digest */ public static MD5Digest fromString(String md5String) { byte[] bytes; try { bytes = Hex.decodeHex(md5String.toCharArray()); return new MD5Digest(md5String, bytes); } catch (DecoderException e) { throw new IllegalArgumentException("Unable to convert md5string", e); } }
/** * Static method to get an MD5Digest from a binary byte representation * @param md5Bytes * @return a filled out MD5Digest */ public static MD5Digest fromBytes(byte[] md5Bytes) { Preconditions.checkArgument(md5Bytes.length == MD5_BYTES_LENGTH, "md5 bytes must be " + MD5_BYTES_LENGTH + " bytes in length, found " + md5Bytes.length + " bytes."); String md5String = Hex.encodeHexString(md5Bytes); return new MD5Digest(md5String, md5Bytes); }
/** * Static method to get an MD5Digest from a binary byte representation. * @param md5Bytes * @param offset in the byte array to start reading from * @return a filled out MD5Digest */ public static MD5Digest fromBytes(byte[] md5Bytes, int offset) { byte[] md5BytesCopy = Arrays.copyOfRange(md5Bytes, offset, offset + MD5_BYTES_LENGTH); //TODO: Replace this with a version that encodes without needing a copy. String md5String = Hex.encodeHexString(md5BytesCopy); return new MD5Digest(md5String, md5BytesCopy); }
/** * Static method to get an MD5Digest from a human-readable string representation * @param md5String * @return a filled out MD5Digest */ public static MD5Digest fromString(String md5String) { byte[] bytes; try { bytes = Hex.decodeHex(md5String.toCharArray()); return new MD5Digest(md5String, bytes); } catch (DecoderException e) { throw new IllegalArgumentException("Unable to convert md5string", e); } }