public byte[] calcDigest(InputStream is) throws IOException { add(is); return getDigest(); }
public String calcDigestString(InputStream is) throws IOException { add(is); return getDigestString(); }
@SuppressWarnings("unchecked") public String getResourceSubscriptionMD5(int resourceId) { MessageDigestGenerator md5Generator = new MessageDigestGenerator(); Query q = entityManager.createNamedQuery(Repo.QUERY_FIND_REPOS_BY_RESOURCE_ID); q.setParameter("resourceId", resourceId); List<Repo> repos = q.getResultList(); for (Repo repo : repos) { long modifiedTimestamp = repo.getLastModifiedDate(); Date modifiedDate = new Date(modifiedTimestamp); md5Generator.add(Integer.toString(modifiedDate.hashCode()).getBytes()); } String digestString = md5Generator.getDigestString(); return digestString; }
/** * Copies the input stream data to the output stream and returns the * copied data's digest string. * * Note: the streams are never closed - the caller is responsible for that. * * @param in input content * @param out where to write the input content * @return the copied content's digest string (aka hashcode) */ public String copyAndCalculateHashcode(InputStream in, OutputStream out) { try { byte[] buffer = new byte[32768]; BufferedInputStream bufferedStream = new BufferedInputStream(in, buffer.length); for (int bytesRead = bufferedStream.read(buffer); bytesRead != -1; bytesRead = bufferedStream.read(buffer)) { out.write(buffer, 0, bytesRead); this.generator.add(buffer, 0, bytesRead); } out.flush(); } catch (IOException ioe) { throw new RuntimeException("Stream data cannot be copied", ioe); } return this.generator.getDigestString(); } }
/** * Calculates a unique key based on parents' resource keys. * * @param prefixKey extra key to be appended at the beginning of the digest process * @return key */ private String getAncestryBasedResourceKey(String prefixKey) { MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256); if (prefixKey != null) { messageDigest.add(prefixKey.getBytes()); } messageDigest.add(this.resource.getResourceKey().getBytes()); ResourceContext<?> ancestor = this.parentResourceContext; while (ancestor != null) { messageDigest.add(ancestor.getResourceKey().getBytes()); ancestor = ancestor.getParentResourceContext(); } return messageDigest.getDigestString(); }
try { inputStream = new FileInputStream(file); messageDigest.add(inputStream); } finally { if (inputStream != null) {
numBytesCopied += bytesRead; if (digestGenerator != null) { digestGenerator.add(buffer, 0, bytesRead);
try { inputStream = new FileInputStream(file); messageDigest.add(inputStream); } finally { if (inputStream != null) {
hashcodeGenerator.add(bytes); hashcode = hashcodeGenerator.getDigestString(); } else {
generator.add(content.getBytes()); hashcode = generator.getDigestString(); } else {
hashcodeGenerator.add(bytes); hashcode = hashcodeGenerator.getDigestString(); } else {
/** * Will return the persisted Resource Configuration update, or null if the specified Configuration * is identical to the currently persisted Configuration. */ private ResourceConfigurationUpdate persistNewAgentReportedResourceConfiguration(Resource resource, Configuration liveConfig) throws ConfigurationUpdateStillInProgressException { if (liveConfig.getRawConfigurations() != null) { for (RawConfiguration raw : liveConfig.getRawConfigurations()) { MessageDigestGenerator sha256Generator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256); sha256Generator.add(raw.getContents().getBytes()); raw.setSha256(sha256Generator.getDigestString()); } } /* * NOTE: We pass the overlord, since this is a system side-effect. here, the system * and *not* the user, is choosing to persist the most recent configuration because it was different * from the last known value. again, the user isn't attempting to change the value; instead, *JON* * is triggering save based on the semantics that we want to provide for configuration updates. * For the same reason, we pass null as the subject. */ ResourceConfigurationUpdate update = this.configurationManager .persistResourceConfigurationUpdateInNewTransaction(this.subjectManager.getOverlord(), resource.getId(), liveConfig, ConfigurationUpdateStatus.SUCCESS, null, false); // resource.setResourceConfiguration(liveConfig.deepCopy(false)); resource.setResourceConfiguration(liveConfig.deepCopyWithoutProxies()); return update; }