public RpcSwfServlet(String swfResource) { try { InputStream is = ResourceLoader.openResource(swfResource); if (is == null) { throw new RuntimeException("Failed to locate Flash SWF"); } this.swfBytes = IOUtils.toByteArray(is); this.hash = HashUtil.checksum(swfBytes); } catch (IOException e) { throw new RuntimeException(e); } }
/** * 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 raw checksum for the given input data. Currently uses a message digest * * @param data * @return The checksum. */ public static String rawChecksum(byte[] data) { return new String(getMessageDigest().digest(Preconditions.checkNotNull(data))); }
@Test(expected = NullPointerException.class) public void testRawChecksumNPE() { HashUtil.rawChecksum(null); }
public String getContentHash() { ensureDigestObjectExists(); String hash = HashUtil.bytesToHex(digest.digest()); digest = null; return hash; }
/** * Produces a raw checksum for the given input data. Currently uses a message digest * * @param data * @return The checksum. */ public static String rawChecksum(byte[] data) { return new String(getMessageDigest().digest(Preconditions.checkNotNull(data))); }
@Test(expected = NullPointerException.class) public void testRawChecksumNPE() { HashUtil.rawChecksum(null); }
protected String makeCacheKey(String code, String externs, JsUri uri, CompilerOptions options) { // TODO: include compilation options in the cache key return Joiner.on(":").join( HashUtil.checksum(code.getBytes()), HashUtil.checksum(externs.getBytes()), uri.getCompileMode(), uri.isDebug(), options.isExternExportsEnabled()); }
/** * 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 raw checksum for the given input data. Currently uses a message digest * * @param data * @return The checksum. */ public static String rawChecksum(byte[] data) { return new String(getMessageDigest().digest(Preconditions.checkNotNull(data))); }
@Test(expected = NullPointerException.class) public void testRawChecksumNPE() { HashUtil.rawChecksum(null); }
@Inject public AllJsIframeVersioner(FeatureRegistry registry) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
/** * 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 raw checksum for the given input data. Currently uses a message digest * * @param data * @return The checksum. */ public static String rawChecksum(byte[] data) { return new String(getMessageDigest().digest(Preconditions.checkNotNull(data))); }
@Test(expected = NullPointerException.class) public void testRawChecksumNPE() { HashUtil.rawChecksum(null); }
@Inject public AllJsIframeVersioner(FeatureRegistry registry) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
@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()); }
/** * Produces a raw checksum for the given input data. Currently uses a message digest * * @param data * @return The checksum. */ public static String rawChecksum(byte[] data) { return new String(getMessageDigest().digest(Preconditions.checkNotNull(data))); }
@Test(expected = NullPointerException.class) public void testRawChecksumNPE() { HashUtil.rawChecksum(null); }
public String version(Uri gadgetUri, final String container, Collection<String> extern) { GadgetContext ctx = new GadgetContext() { @Override public String getContainer() { return container; } @Override public RenderingContext getRenderingContext() { return RenderingContext.GADGET; } }; // Registry itself will cache these requests. List<FeatureResource> resources = registry.getFeatureResources(ctx, extern, null); if (versionCache.containsKey(resources)) { return versionCache.get(resources); } StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : resources) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } String checksum = HashUtil.checksum(jsBuf.toString().getBytes()); versionCache.put(resources, checksum); return checksum; }