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); } }
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()); }
@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) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
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; }
@Test(expected = NullPointerException.class) public void testChecksumNPE() { HashUtil.checksum(null); }
@Test(expected = NullPointerException.class) public void testChecksumNPE() { HashUtil.checksum(null); }
@Test(expected = NullPointerException.class) public void testChecksumNPE() { HashUtil.checksum(null); }
@Test(expected = NullPointerException.class) public void testChecksumNPE() { HashUtil.checksum(null); }
@Test(expected = NullPointerException.class) public void testChecksumNPE() { HashUtil.checksum(null); }
@Test public void testChecksum() throws Exception { byte[] data = new byte[] {Byte.MAX_VALUE, Byte.MIN_VALUE}; assertEquals("d41d8cd98f00b204e9800998ecf8427e", HashUtil.checksum(new byte[]{})); assertEquals("a494a8690b72391b13d3cbe27edb5c58", HashUtil.checksum(new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE})); }
@Test public void testChecksum() throws Exception { byte[] data = new byte[] {Byte.MAX_VALUE, Byte.MIN_VALUE}; assertEquals("d41d8cd98f00b204e9800998ecf8427e", HashUtil.checksum(new byte[]{})); assertEquals("a494a8690b72391b13d3cbe27edb5c58", HashUtil.checksum(new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE})); }
@Test public void testChecksum() throws Exception { byte[] data = new byte[] {Byte.MAX_VALUE, Byte.MIN_VALUE}; assertEquals("d41d8cd98f00b204e9800998ecf8427e", HashUtil.checksum(new byte[]{})); assertEquals("a494a8690b72391b13d3cbe27edb5c58", HashUtil.checksum(new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE})); }
@Test public void testChecksum() throws Exception { byte[] data = new byte[] {Byte.MAX_VALUE, Byte.MIN_VALUE}; assertEquals("d41d8cd98f00b204e9800998ecf8427e", HashUtil.checksum(new byte[]{})); assertEquals("a494a8690b72391b13d3cbe27edb5c58", HashUtil.checksum(new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE})); }
@Test public void testChecksum() throws Exception { byte[] data = new byte[] {Byte.MAX_VALUE, Byte.MIN_VALUE}; assertEquals("d41d8cd98f00b204e9800998ecf8427e", HashUtil.checksum(new byte[]{})); assertEquals("a494a8690b72391b13d3cbe27edb5c58", HashUtil.checksum(new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE})); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; featureChecksum = HashUtil.checksum((featureContent + debugContent).getBytes()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent); List<FeatureResource> allResources = Lists.newArrayList(resource); expect(registry.getAllFeatures()).andReturn(allResources).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }
public CssTree.StyleSheet parseDom(String content, Uri source) throws GadgetException { CssTree.StyleSheet parsedCss = null; boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { // TODO - Consider using the source if its under a certain size key = HashUtil.checksum(content.getBytes()); parsedCss = parsedCssCache.getElement(key); } if (parsedCss == null) { try { parsedCss = parseImpl(content, source); if (shouldCache) { parsedCssCache.addElement(key, parsedCss); } } catch (ParseException pe) { // Bad input; not server's fault. throw new GadgetException(GadgetException.Code.CSS_PARSE_ERROR, pe, HttpResponse.SC_BAD_REQUEST); } } if (shouldCache) { return (CssTree.StyleSheet)parsedCss.clone(); } return parsedCss; }
@Test public void testAlternativeConstructor() throws Exception { String xml = "<Module>" + "<ModulePrefs title=\"title\"/>" + "<UserPref name=\"foo\" datatype=\"string\"/>" + "<Content type=\"html\">Hello!</Content>" + "</Module>"; GadgetSpec spec = new GadgetSpec(SPEC_URL, XmlUtil.parse(xml), xml); assertEquals("title", spec.getModulePrefs().getTitle()); assertEquals(UserPref.DataType.STRING, spec.getUserPrefs().get("foo").getDataType()); assertEquals("Hello!", spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); assertEquals(HashUtil.checksum(xml.getBytes()), spec.getChecksum()); }
@Test public void testAlternativeConstructor() throws Exception { String xml = "<Module>" + "<ModulePrefs title=\"title\"/>" + "<UserPref name=\"foo\" datatype=\"string\"/>" + "<Content type=\"html\">Hello!</Content>" + "</Module>"; GadgetSpec spec = new GadgetSpec(SPEC_URL, XmlUtil.parse(xml), xml); assertEquals("title", spec.getModulePrefs().getTitle()); assertEquals(UserPref.DataType.STRING, spec.getUserPrefs().get("foo").getDataType()); assertEquals("Hello!", spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); assertEquals(HashUtil.checksum(xml.getBytes()), spec.getChecksum()); }
@Test public void testAlternativeConstructor() throws Exception { String xml = "<Module>" + "<ModulePrefs title=\"title\"/>" + "<UserPref name=\"foo\" datatype=\"string\"/>" + "<Content type=\"html\">Hello!</Content>" + "</Module>"; GadgetSpec spec = new GadgetSpec(SPEC_URL, XmlUtil.parse(xml), xml); assertEquals("title", spec.getModulePrefs().getTitle()); assertEquals(UserPref.DataType.STRING, spec.getUserPrefs().get("foo").getDataType()); assertEquals("Hello!", spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); assertEquals(HashUtil.checksum(xml.getBytes()), spec.getChecksum()); }