List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:org.apache.nutch.webui.model.User.java
public static String cryptPass(String password) { // TODO : use configuration file final String salt = "IB73*%^abD(^$#L<>deh"; return DigestUtils.shaHex(password); }
From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.JobControlCompiler.java
public static Path getFromCache(PigContext pigContext, Configuration conf, URL url) throws IOException { InputStream is1 = null;// w w w . ja v a2s .c o m InputStream is2 = null; OutputStream os = null; try { Path stagingDir = getCacheStagingDir(conf); String filename = FilenameUtils.getName(url.getPath()); is1 = url.openStream(); String checksum = DigestUtils.shaHex(is1); FileSystem fs = FileSystem.get(conf); Path cacheDir = new Path(stagingDir, checksum); Path cacheFile = new Path(cacheDir, filename); if (fs.exists(cacheFile)) { log.debug("Found " + url + " in jar cache at " + cacheDir); long curTime = System.currentTimeMillis(); fs.setTimes(cacheFile, -1, curTime); return cacheFile; } log.info("Url " + url + " was not found in jarcache at " + cacheDir); // attempt to copy to cache else return null fs.mkdirs(cacheDir, FileLocalizer.OWNER_ONLY_PERMS); is2 = url.openStream(); short replication = (short) conf.getInt(PigConfiguration.PIG_USER_CACHE_REPLICATION, conf.getInt("mapred.submit.replication", 10)); os = fs.create(cacheFile, replication); fs.setPermission(cacheFile, FileLocalizer.OWNER_ONLY_PERMS); IOUtils.copyBytes(is2, os, 4096, true); return cacheFile; } catch (IOException ioe) { log.info("Unable to retrieve jar from jar cache ", ioe); return null; } finally { org.apache.commons.io.IOUtils.closeQuietly(is1); org.apache.commons.io.IOUtils.closeQuietly(is2); // IOUtils should not close stream to HDFS quietly if (os != null) { os.close(); } } }
From source file:org.apache.sentry.hdfs.UniquePathsUpdate.java
public static String sha1(NotificationEvent event) { StringBuilder sb = new StringBuilder(); sb.append(event.getEventId());/* w w w . j av a2 s .co m*/ sb.append(event.getEventTime()); sb.append(event.getEventType()); sb.append(event.getDbName()); sb.append(event.getTableName()); sb.append(event.getMessage()); return DigestUtils.shaHex(sb.toString()); }
From source file:org.apache.vysper.xmpp.extension.xep0065_socks.Socks5IqHandler.java
@Override protected Stanza handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext) { /*// w ww . j a v a 2s . c o m C: <iq from='requester@example.com/foo' id='oqx6t1c9' to='streamer.example.com' type='set'> <query xmlns='http://jabber.org/protocol/bytestreams' sid='vxf9n471bn46'> <activate>target@example.org/bar</activate> </query> </iq> S: <iq from='streamer.example.com' id='oqx6t1c9' to='requester@example.com/foo' type='result'/> SHA1 Hash of: (SID + Requester JID + Target JID) */ try { XMLElement queryElm = stanza.getSingleInnerElementsNamed("query", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS); XMLElement activateElm = queryElm.getSingleInnerElementsNamed("activate", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS); String sid = queryElm.getAttributeValue("sid"); Entity target = EntityImpl.parse(activateElm.getInnerText().getText()); Entity requester = stanza.getFrom(); String hash = DigestUtils .shaHex(sid + requester.getFullQualifiedName() + target.getFullQualifiedName()); if (connections.activate(hash)) { Stanza result = StanzaBuilder.createIQStanza(jid, requester, IQStanzaType.RESULT, stanza.getID()) .build(); return result; } else { throw new RuntimeException("Pair not found"); } } catch (Exception e) { return ServerErrorResponses.getStanzaError(StanzaErrorCondition.BAD_REQUEST, stanza, StanzaErrorType.CANCEL, null, null, null); } }
From source file:org.apache.vysper.xmpp.extension.xep0065_socks.Socks5IqHandlerTest.java
@Test public void handleSetActivate() throws BindException, XMLSemanticError { IQStanza request = (IQStanza) IQStanza.getWrapper(StanzaBuilder .createIQStanza(FROM, TO, IQStanzaType.SET, "id1") .startInnerElement("query", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS).addAttribute("sid", "sid1") .startInnerElement("activate", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .addText(TARGET.getFullQualifiedName()).build()); String hash = DigestUtils.shaHex("sid1" + FROM.getFullQualifiedName() + TARGET.getFullQualifiedName()); when(connectionsRegistry.activate(hash)).thenReturn(true); Stanza response = handler.handleSet(request, serverRuntimeContext, sessionContext); Stanza expected = StanzaBuilder.createIQStanza(TO, FROM, IQStanzaType.RESULT, "id1").build(); StanzaAssert.assertEquals(expected, response); verify(connectionsRegistry).activate(hash); }
From source file:org.appcelerator.titanium.util.TiDownloadManager.java
protected void startDownload(URI uri, TiDownloadListener listener) { String hash = DigestUtils.shaHex(uri.toString()); ArrayList<SoftReference<TiDownloadListener>> listenerList = null; synchronized (listeners) { if (!listeners.containsKey(hash)) { listenerList = new ArrayList<SoftReference<TiDownloadListener>>(); listeners.put(hash, listenerList); } else {/* ww w . ja va2 s .co m*/ listenerList = listeners.get(hash); } // We only allow a listener once per URI for (SoftReference<TiDownloadListener> l : listenerList) { if (l.get() == listener) { return; } } listenerList.add(new SoftReference<TiDownloadListener>(listener)); } synchronized (downloadingURIs) { if (!downloadingURIs.contains(hash)) { downloadingURIs.add(hash); threadPool.execute(new DownloadJob(uri)); } } }
From source file:org.appcelerator.titanium.util.TiDownloadManager.java
protected void handleFireDownloadMessage(URI uri, int what) { ArrayList<SoftReference<TiDownloadListener>> toRemove = new ArrayList<SoftReference<TiDownloadListener>>(); synchronized (listeners) { String hash = DigestUtils.shaHex(uri.toString()); for (SoftReference<TiDownloadListener> listener : listeners.get(hash)) { if (listener.get() != null) { if (what == MSG_FIRE_DOWNLOAD_FINISHED) { fireDownloadFinished(uri, listener.get()); } else if (what == MSG_FIRE_DOWNLOAD_FAILED) { fireDownloadFailed(listener.get()); }//from w w w . java 2s . co m toRemove.add(listener); } } for (SoftReference<TiDownloadListener> listener : toRemove) { listeners.get(hash).remove(listener); } } }
From source file:org.appcelerator.titanium.util.TiResponseCache.java
public static boolean peek(URI uri) { TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault(); if (rc == null) return false; if (rc.cacheDir == null) return false; String hash = DigestUtils.shaHex(uri.toString()); File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX); File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX); if (!bFile.exists() || !hFile.exists()) return false; return true;//from w w w . j a v a2s . com }
From source file:org.appcelerator.titanium.util.TiResponseCache.java
public static InputStream openCachedStream(URI uri) { TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault(); if (rc == null) { return null; }//from ww w.ja va 2 s . c o m if (rc.cacheDir == null) { return null; } String hash = DigestUtils.shaHex(uri.toString()); File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX); File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX); if (!bFile.exists() || !hFile.exists()) { return null; } try { return new FileInputStream(bFile); } catch (FileNotFoundException e) { // Fallback to URL download? return null; } }
From source file:org.appcelerator.titanium.util.TiResponseCache.java
public static void addCompleteListener(URI uri, CompleteListener listener) { synchronized (completeListeners) { String hash = DigestUtils.shaHex(uri.toString()); if (!completeListeners.containsKey(hash)) { completeListeners.put(hash, new ArrayList<CompleteListener>()); }/*from www. ja va 2 s . c om*/ completeListeners.get(hash).add(listener); } }