List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:v7db.files.buckets.BucketsServletTest.java
public void testEchoPutPUT() throws IOException, SAXException { ServletUnitClient sc = sr.newClient(); {//from ww w. j a v a 2s . co m WebRequest request = new PutMethodWebRequest("http://test/myServlet/1", new ByteArrayInputStream("testPUT".getBytes()), "text/plain"); try { sc.getResponse(request); fail("bucket not found => 404"); } catch (HttpNotFoundException e) { assertEquals("Bucket '1' not found", e.getResponseMessage()); } } prepareBucket("1", "EchoPut", null, null); { WebRequest request = new PutMethodWebRequest("http://test/myServlet/1", new ByteArrayInputStream("testPUT".getBytes()), "text/plain"); request.setParameter("sha", "1234"); try { sc.getResponse(request); fail("uploads not allowed => 405"); } catch (HttpException e) { assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getResponseCode()); } } prepareBucket("2", "EchoPut", null, "EchoPut"); { WebRequest request = new PutMethodWebRequest("http://test/myServlet/2", new ByteArrayInputStream("testPUT".getBytes()), "text/plain"); WebResponse response = sc.getResponse(request); assertEquals(DigestUtils.shaHex("testPUT".getBytes()), response.getText()); assertMockMongoContainsDocument("test.v7files.content", DigestUtils.sha("testPUT".getBytes())); WebRequest get = new GetMethodWebRequest("http://test/myServlet/2"); get.setParameter("sha", response.getText()); assertEquals("testPUT", sc.getResponse(get).getText()); } }
From source file:v7db.files.mongodb.MongoContentStorageTest.java
public void testSaveAsChunks() throws IOException { byte[] data = new byte[10 * 1024 * 1024]; new Random(12345).nextBytes(data); byte[] sha = DigestUtils.sha(data); Mongo mongo = getMongo();/* w w w .j av a 2 s . c o m*/ MongoContentStorage storage = new MongoContentStorage(mongo.getDB("test")); ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data)); BSONObject doc = assertMockMongoContainsDocument("test.v7files.content", sha); assertEquals("cat", doc.get("store")); assertEquals(data.length, storage.getContent(pointer).getLength()); assertEquals(Hex.encodeHexString(sha), DigestUtils.shaHex(storage.getContent(pointer).getInputStream())); ContentSHA storeAgain = storage.storeContent(new ByteArrayInputStream(data)); assertEquals(Hex.encodeHexString(sha), storeAgain.getDigest()); }
From source file:v7db.files.mongodb.V7File.java
public String getDigest() { ContentPointer contentPointer = getContentPointer(); if (contentPointer instanceof ContentSHA) { return ((ContentSHA) contentPointer).getDigest(); }/* ww w . ja va 2s . c om*/ if (contentPointer instanceof InlineContent) { try { return DigestUtils.shaHex(((InlineContent) contentPointer).getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } } if (contentPointer.getLength() == 0) return ContentSHA.calculate(ArrayUtils.EMPTY_BYTE_ARRAY).getDigest(); // TODO: System.err.println("NO DIGEST!"); return null; }
From source file:v7db.files.ZipFileTest.java
public void testPullOutFileFromZip() throws MongoException, IOException, ZipException, DecoderException { ContentStorage storage = new MongoContentStorage(getMongo().getDB("test")); ContentPointer zip = storage.storeContent(getClass().getResourceAsStream("mongodb.epub")); ContentPointer png = ZipFile.extractFile(storage, zip, "images/img0.png"); assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils.shaHex(storage.getContent(png).getInputStream())); }
From source file:v7db.files.ZipFileTest.java
public void testIndexZipFile() throws MongoException, IOException, ZipException, DecoderException { ContentStorage storage = new MongoContentStorage(getMongo().getDB("test")); ContentPointer zip = storage.storeContent(getClass().getResourceAsStream("mongodb.epub")); ZipFile.index(storage, zip);//from w ww . j a v a 2 s .co m assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils.shaHex(storage .getContent(decodeHex("fc012bb0439382f709d3caebab958ff592811d17".toCharArray())).getInputStream())); }
From source file:VASL.build.module.map.ASLBoardPicker.java
public void addBoard(String name) { ////* w w w . ja va 2s .co m*/ final GameModule g = GameModule.getGameModule(); final String hstr = DigestUtils.shaHex(g.getGameName() + "_" + g.getGameVersion()); final File fpath = new File(boardDir, "bd" + name); final ASLTilingHandler th = new ASLTilingHandler(fpath.getAbsolutePath(), new File(Info.getConfDir(), "tiles/" + hstr), new Dimension(256, 256), 1024, 42); try { th.sliceTiles(); } catch (IOException e) { ReadErrorDialog.error(e, fpath); } /// final ASLBoard b = new ASLBoard(); b.setCommonName(name); possibleBoards.add(b); }
From source file:VASSAL.build.GameModule.java
public ImageTileSource getImageTileSource() { if (tcache == null) { // FIXME: There's no guarantee that getGameName() and getGameVersion() // are properly set at this point. final String hstr = DigestUtils.shaHex(getGameName() + "_" + getGameVersion()); final File tc = new File(Info.getConfDir(), "tiles/" + hstr); tcache = new ImageTileDiskCache(tc.getAbsolutePath()); }/*from w w w . java 2 s.c o m*/ return tcache; }
From source file:VASSAL.tools.image.tilecache.TileUtils.java
/** * Gets the name of a tile file.//from w w w .j av a 2 s. c o m * * @param iname the image name * @param tileX the X coordinate of the tile * @param tileY the Y coordinate of the tile * @param div the scale divisor * @return the name of the tile file */ public static String tileName(String iname, int tileX, int tileY, int div) { final String sha = DigestUtils.shaHex(iname + "(" + tileX + "," + tileY + "@1:" + div); return sha.substring(0, 1) + '/' + sha.substring(0, 2) + '/' + sha; }