List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:org.apache.ofbiz.base.crypto.HashCrypt.java
public static String digestHash64(String hashType, byte[] bytes) { if (hashType == null) { hashType = "SHA"; }//from w w w. ja va 2 s . c om try { MessageDigest messagedigest = MessageDigest.getInstance(hashType); messagedigest.update(bytes); byte[] digestBytes = messagedigest.digest(); StringBuilder sb = new StringBuilder(); sb.append("{").append(hashType).append("}"); sb.append(Base64.encodeBase64URLSafeString(digestBytes).replace('+', '.')); return sb.toString(); } catch (NoSuchAlgorithmException e) { throw new GeneralRuntimeException("Error while computing hash of type " + hashType, e); } }
From source file:org.apache.rya.indexing.Md5Hash.java
public static String md5Base64(final byte[] data) { return Base64.encodeBase64URLSafeString(DigestUtils.md5(data)); }
From source file:org.apache.s4.core.ft.CheckpointingTest.java
@Test public void testCheckpointStorage() throws Exception { final ZooKeeper zk = CoreTestUtils.createZkClient(); // 2. generate a simple event that creates and changes the state of // the/*w w w .j av a 2 s. c o m*/ // PE // NOTE: coordinate through zookeeper final CountDownLatch signalValue1Set = new CountDownLatch(1); CoreTestUtils.watchAndSignalCreation("/value1Set", signalValue1Set, zk); final CountDownLatch signalCheckpointed = new CountDownLatch(1); CoreTestUtils.watchAndSignalCreation("/checkpointed", signalCheckpointed, zk); Injector injector = Guice.createInjector(new MockCommModule(), new MockCoreModuleWithFileBaseCheckpointingBackend(), new AppModule(getClass().getClassLoader())); TestApp app = injector.getInstance(TestApp.class); app.init(); app.start(); Event event = new Event(); event.setStreamId("stream1"); event.put("command", String.class, "setValue1"); event.put("value", String.class, "message1"); app.testStream.receiveEvent(event); signalValue1Set.await(); StatefulTestPE pe = (StatefulTestPE) app.getPE("statefulPE1").getInstanceForKey("X"); Assert.assertEquals("message1", pe.getValue1()); Assert.assertEquals("", pe.getValue2()); // 3. generate a checkpoint event event = new Event(); event.setStreamId("stream1"); event.put("command", String.class, "checkpoint"); app.testStream.receiveEvent(event); Assert.assertTrue(signalCheckpointed.await(10, TimeUnit.SECONDS)); // NOTE: the backend has asynchronous save operations Thread.sleep(1000); CheckpointId safeKeeperId = new CheckpointId(pe); File expected = new File(System.getProperty("user.dir") + File.separator + "tmp" + File.separator + "storage" + File.separator + safeKeeperId.getPrototypeId() + File.separator + Base64.encodeBase64URLSafeString(safeKeeperId.getStringRepresentation().getBytes())); // 4. verify that state was correctly persisted Assert.assertTrue(expected.exists()); StatefulTestPE refPE = new StatefulTestPE(); refPE.onCreate(); refPE.setValue1("message1"); Field idField = ProcessingElement.class.getDeclaredField("id"); idField.setAccessible(true); idField.set(refPE, "X"); byte[] refBytes = app.getSerDeser().serialize(refPE).array(); Assert.assertTrue(Arrays.equals(refBytes, Files.toByteArray(expected))); }
From source file:org.apache.s4.core.ft.DefaultFileSystemStateStorage.java
private static File checkpointID2File(CheckpointId key, String storageRootPath) { return new File(storageRootPath + File.separator + key.getPrototypeId() + File.separator + Base64.encodeBase64URLSafeString(key.getStringRepresentation().getBytes())); }
From source file:org.apache.s4.ft.DefaultFileSystemStateStorage.java
private static File safeKeeperID2File(SafeKeeperId key, String storageRootPath) { return new File(storageRootPath + File.separator + key.getPrototypeId() + File.separator + Base64.encodeBase64URLSafeString(key.getStringRepresentation().getBytes())); }
From source file:org.apache.whirr.service.mongodb.MongoDBCluster.java
private static String generateKeyFileContent() { final byte[] random = new byte[2048]; rng.nextBytes(random);/* w w w. j a v a 2 s . c o m*/ return Base64.encodeBase64URLSafeString(random); }
From source file:org.apereo.portal.portlet.dao.jpa.JpaPortletCookieDaoImpl.java
/** * Generates a 40 character unique value. * @return// w w w . j av a 2 s . c o m */ private String generateNewCookieId() { final byte[] keyBytes = new byte[30]; this.secureRandom.nextBytes(keyBytes); return Base64.encodeBase64URLSafeString(keyBytes); }
From source file:org.ardverk.gibson.EventUtils.java
public static String signature(Event event) { if (event == null) { throw new NullPointerException("event"); }/*from ww w . ja v a 2 s . c o m*/ MessageDigest md = createMessageDigest(ALGORITHM); append(md, event.getLogger()); append(md, event.getMarker()); append(md, event.getLevel()); append(md, event.getCondition()); return Base64.encodeBase64URLSafeString(md.digest()); }
From source file:org.auraframework.util.text.Hash.java
@Override public String toString() { if (value == null) { return "no-hash-value"; }/*from w ww. jav a 2 s . c o m*/ return Base64.encodeBase64URLSafeString(value); }
From source file:org.brekka.commons.tapestry.components.QrCode.java
void beginRender(MarkupWriter writer) throws Exception { String base64urlSafeString = Base64.encodeBase64URLSafeString(url.getBytes("UTF-8")); Link link = componentResources.createEventLink("action", base64urlSafeString, size); Element img = writer.element("img", "src", link.toURI(), "alt", "QR Code"); List<String> informalParameterNames = componentResources.getInformalParameterNames(); for (String param : informalParameterNames) { String value = componentResources.getInformalParameter(param, String.class); img.attribute(param, value);//from w w w. j a v a2 s. com } writer.end(); }