/** * Produces a checksum for the given input data. Currently uses a hexified * message digest. * * @param data * @return The checksum. */ public static String checksum(byte[] data) { byte[] hashBytes = getMessageDigest().digest(Preconditions.checkNotNull(data)); return bytesToHex(hashBytes); }
/** * Produces a checksum for the given input data. Currently uses a hexified * message digest. * * @param data * @return The checksum. */ public static String checksum(byte[] data) { byte[] hashBytes = getMessageDigest().digest(Preconditions.checkNotNull(data)); return bytesToHex(hashBytes); }
public String getContentHash() { ensureDigestObjectExists(); String hash = HashUtil.bytesToHex(digest.digest()); digest = null; return hash; }
/** * Produces a checksum for the given input data. Currently uses a hexified * message digest. * * @param data * @return The checksum. */ public static String checksum(byte[] data) { byte[] hashBytes = getMessageDigest().digest(Preconditions.checkNotNull(data)); return bytesToHex(hashBytes); }
@Inject public AllJsIframeVersioner(FeatureRegistry registry) { String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); digest.reset(); for (FeatureResource resource : registry.getAllFeatures().getResources()) { // Emulate StringBuilder append of content update(digest, resource.getContent(), charset); update(digest, resource.getDebugContent(), charset); } allJsChecksum = HashUtil.bytesToHex(digest.digest()); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); try{ digest.update(featureContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(featureContent.getBytes()); } try{ digest.update(debugContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(debugContent.getBytes()); } featureChecksum = HashUtil.bytesToHex(digest.digest()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent, "js"); List<FeatureResource> allResources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(allResources); replay(lr); expect(registry.getAllFeatures()).andReturn(lr).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); try{ digest.update(featureContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(featureContent.getBytes()); } try{ digest.update(debugContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(debugContent.getBytes()); } featureChecksum = HashUtil.bytesToHex(digest.digest()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent, "js"); List<FeatureResource> allResources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(allResources); replay(lr); expect(registry.getAllFeatures()).andReturn(lr).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }