List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void mergePatchKeyAsync(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); String name1 = Long.toHexString(RAND.nextLong()); final KvMetadata kvMetadata = insertItem(key, "{`name1`:`%s`}", name1); String name2 = Long.toHexString(RAND.nextLong()); final BlockingQueue<KvMetadata> queue = DataStructures.getLTQInstance(KvMetadata.class); client.kv(collection(), key).merge("{\"name2\":\"" + name2 + "\"}").on(new ResponseAdapter<KvMetadata>() { @Override/*from www . j a v a2s .co m*/ public void onFailure(final Throwable error) { fail(error.getMessage()); } @Override public void onSuccess(final KvMetadata object) { queue.add(object); } }); final KvMetadata patched = queue.poll(5000, TimeUnit.MILLISECONDS); assertNotEquals(kvMetadata, patched); final KvObject<ObjectNode> kvObject = client.kv(kvMetadata.getCollection(), kvMetadata.getKey()) .get(ObjectNode.class).get(); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name1, kvObject.getValue().get("name1").asText()); assertEquals(name2, kvObject.getValue().get("name2").asText()); }
From source file:org.zaproxy.zap.extension.api.API.java
/** * Returns a one time nonce to be used with the API call specified by the URL * @param apiUrl the API URL/* w w w . ja v a2s . com*/ * @return a one time nonce * @since 2.6.0 */ public String getOneTimeNonce(String apiUrl) { String nonce = Long.toHexString(random.nextLong()); this.nonces.put(nonce, new Nonce(nonce, apiUrl, true)); return nonce; }
From source file:org.zaproxy.zap.extension.api.API.java
/** * Returns a nonce that will be valid for the lifetime of the ZAP process to used with the API call specified by the URL * @param apiUrl the API URL/*from w w w. ja v a 2 s . com*/ * @return a nonce that will be valid for the lifetime of the ZAP process * @since 2.6.0 */ public String getLongLivedNonce(String apiUrl) { String nonce = Long.toHexString(random.nextLong()); this.nonces.put(nonce, new Nonce(nonce, apiUrl, false)); return nonce; }
From source file:com.wabacus.system.ReportRequest.java
private void createDataExportFileObj() { this.dataExportFilepath = DataExportLocalStroageBean.dataExportFileRootPath; this.dataExportFileurl = DataExportLocalStroageBean.dataExportFileRootUrl; if (this.dataexport_localstroageautodelete) {//?dataexport/temp/? this.dataExportFilepath += "temp" + File.separator; this.dataExportFileurl += "temp/"; }//from w ww . j a va 2 s . c o m if (!Tools.isEmpty(this.dataexport_localstroagedirectorydateformat) && !DataExportLocalStroageBean.ROOTDIRECTORY .equals(this.dataexport_localstroagedirectorydateformat)) { String datename = Tools.removeNonNumberFromDatetime( Tools.getStrDatetime(this.dataexport_localstroagedirectorydateformat, new Date())); this.dataExportFilepath += datename + File.separator; this.dataExportFileurl += datename + "/"; } FilePathAssistant.getInstance().checkAndCreateDirIfNotExist(this.dataExportFilepath); String tmp = Long.toHexString(System.currentTimeMillis()) + Tools.getRandomString(2); String filename = this.getDataExportFilename(); filename = Tools.isEmpty(filename) ? tmp : (filename + "_" + tmp); String filesuffix; if (this.showtype == Consts.DISPLAY_ON_PDF) { filesuffix = ".pdf"; } else if (this.showtype == Consts.DISPLAY_ON_PLAINEXCEL || this.showtype == Consts.DISPLAY_ON_RICHEXCEL) { filesuffix = ".xls"; } else if (this.showtype == Consts.DISPLAY_ON_WORD) { filesuffix = ".doc"; } else { filesuffix = ".tmp"; } this.dataExportFilepath += filename + filesuffix; this.dataExportFileurl += WabacusAssistant.getInstance().encodeAttachFilename(this.request, filename) + filesuffix; File fResult = new File(this.dataExportFilepath); try { if (!fResult.exists() || !fResult.isFile()) fResult.createNewFile(); } catch (IOException e) { throw new WabacusRuntimeException("" + this.dataExportFilepath + "", e); } }
From source file:com.alibaba.wasp.fserver.FServer.java
protected void handleReportForDutyResponse(final FServerStartupResponse c) throws IOException { try {/*from w ww . j a v a2 s . com*/ for (WaspProtos.StringStringPair e : c.getMapEntriesList()) { String key = e.getName(); // The hostname the master sees us as. if (key.equals(FConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) { String hostnameFromMasterPOV = e.getValue(); this.serverNameFromMasterPOV = new ServerName(hostnameFromMasterPOV, this.isa.getPort(), this.startcode); LOG.info("Master passed us hostname to use. Was=" + this.isa.getHostName() + ", Now=" + this.serverNameFromMasterPOV.getHostname()); continue; } String value = e.getValue().toString(); if (LOG.isDebugEnabled()) { LOG.debug("Config from master: " + key + "=" + value); } this.conf.set(key, value); } // Set our ephemeral znode up in zookeeper now we have a name. createMyEphemeralNode(); // Save it in a file, this will allow to see if we crash ZNodeClearer.writeMyEphemeralNodeOnDisk(getMyEphemeralNodePath()); this.metricsFServer = new MetricsFServer(new MetricsFServerWrapperImpl(this)); this.tableSchemaReader = TableSchemaCacheReader.getInstance(this.conf); startServiceThreads(); LOG.info("Serving as " + this.serverNameFromMasterPOV + ", RPC listening on " + this.isa + ", sessionid=0x" + Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId())); isOnline = true; } catch (Throwable e) { this.isOnline = false; stop("Failed initialization"); throw convertThrowableToIOE(cleanup(e, "Failed init"), "FServer startup failed"); } finally { sleeper.skipSleepCycle(); } }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void upsertPatchKey(@ForAll(sampleSize = 10) final String key) { assumeThat(key, not(isEmptyString())); KvObject<ObjectNode> kvBefore = client.kv(collection(), key).get(ObjectNode.class).get(); // assert the object is not present before the patch assertNull(kvBefore);/*from w ww . j a va 2 s . c o m*/ String name = Long.toHexString(RAND.nextLong()); final KvMetadata patched = client.kv(collection(), key).upsert() .patch(JsonPatch.builder().add("name", name).build()).get(); assertNotNull(patched); final KvObject<ObjectNode> kvObject = client.kv(patched.getCollection(), patched.getKey()) .get(ObjectNode.class).get(); assertNotNull(kvObject); assertEquals(patched.getCollection(), kvObject.getCollection()); assertEquals(patched.getKey(), kvObject.getKey()); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name, kvObject.getValue().get("name").asText()); }
From source file:org.trafodion.dtm.TmAuditTlog.java
public static int getRecord(final long lvTransid) throws IOException { if (LOG.isTraceEnabled()) LOG.trace("getRecord start"); TransState lvTxState = TransState.STATE_NOTX; String stateString;//from w w w . j a va2s . co m int lv_lockIndex = (int) (lvTransid & tLogHashKey); try { String transidString = new String(String.valueOf(lvTransid)); Get g; //create our own hashed key long key = (((lvTransid & tLogHashKey) << tLogHashShiftFactor) + (lvTransid & 0xFFFFFFFF)); if (LOG.isTraceEnabled()) LOG.trace("key: " + key + " hex: " + Long.toHexString(key)); g = new Get(Bytes.toBytes(key)); try { Result r = table[lv_lockIndex].get(g); byte[] value = r.getValue(TLOG_FAMILY, ASN_STATE); stateString = new String(Bytes.toString(value)); if (LOG.isTraceEnabled()) LOG.trace("stateString is " + stateString); if (stateString.compareTo("COMMITTED") == 0) { lvTxState = TransState.STATE_COMMITTED; } else if (stateString.compareTo("ABORTED") == 0) { lvTxState = TransState.STATE_ABORTED; } else if (stateString.compareTo("ACTIVE") == 0) { lvTxState = TransState.STATE_ACTIVE; } else if (stateString.compareTo("PREPARED") == 0) { lvTxState = TransState.STATE_PREPARED; } else if (stateString.compareTo("NOTX") == 0) { lvTxState = TransState.STATE_NOTX; } else if (stateString.compareTo("FORGOTTEN") == 0) { lvTxState = TransState.STATE_FORGOTTEN; } else if (stateString.compareTo("ABORTING") == 0) { lvTxState = TransState.STATE_ABORTING; } else if (stateString.compareTo("COMMITTING") == 0) { lvTxState = TransState.STATE_COMMITTING; } else if (stateString.compareTo("PREPARING") == 0) { lvTxState = TransState.STATE_PREPARING; } else if (stateString.compareTo("FORGETTING") == 0) { lvTxState = TransState.STATE_FORGETTING; } else if (stateString.compareTo("FORGETTING_HEUR") == 0) { lvTxState = TransState.STATE_FORGETTING_HEUR; } else if (stateString.compareTo("BEGINNING") == 0) { lvTxState = TransState.STATE_BEGINNING; } else if (stateString.compareTo("HUNGCOMMITTED") == 0) { lvTxState = TransState.STATE_HUNGCOMMITTED; } else if (stateString.compareTo("HUNGABORTED") == 0) { lvTxState = TransState.STATE_HUNGABORTED; } else if (stateString.compareTo("IDLE") == 0) { lvTxState = TransState.STATE_IDLE; } else if (stateString.compareTo("FORGOTTEN_HEUR") == 0) { lvTxState = TransState.STATE_FORGOTTEN_HEUR; } else if (stateString.compareTo("ABORTING_PART2") == 0) { lvTxState = TransState.STATE_ABORTING_PART2; } else if (stateString.compareTo("TERMINATING") == 0) { lvTxState = TransState.STATE_TERMINATING; } else { lvTxState = TransState.STATE_BAD; } if (LOG.isTraceEnabled()) LOG.trace("transid: " + lvTransid + " state: " + lvTxState); } catch (IOException e) { LOG.error("getRecord IOException"); throw e; } catch (Exception e) { LOG.error("getRecord Exception"); throw e; } } catch (Exception e2) { LOG.error("getRecord Exception2 " + e2); e2.printStackTrace(); } if (LOG.isTraceEnabled()) LOG.trace("getRecord end; returning " + lvTxState); return lvTxState.getValue(); }
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * CRC,8//from w ww. ja v a2 s .c o m */ public static String getCRC(InputStream in) { CRC32 crc32 = new CRC32(); byte[] b = new byte[4096]; int len = 0; try { while ((len = in.read(b)) != -1) { crc32.update(b, 0, len); } return Long.toHexString(crc32.getValue()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(in); } }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void upsertPatchKeyAsync(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); KvObject<ObjectNode> kvBefore = client.kv(collection(), key).get(ObjectNode.class).get(); // assert the object is not present before the patch assertNull(kvBefore);/*from w w w .ja va 2 s . c o m*/ String name = Long.toHexString(RAND.nextLong()); final BlockingQueue<KvMetadata> queue = DataStructures.getLTQInstance(KvMetadata.class); client.kv(collection(), key).upsert().patch(JsonPatch.builder().add("name", name).build()) .on(new ResponseAdapter<KvMetadata>() { @Override public void onFailure(final Throwable error) { fail(error.getMessage()); } @Override public void onSuccess(final KvMetadata object) { queue.add(object); } }); final KvMetadata patched = queue.poll(5000, TimeUnit.MILLISECONDS); assertNotNull(patched); final KvObject<ObjectNode> kvObject = client.kv(patched.getCollection(), patched.getKey()) .get(ObjectNode.class).get(); assertNotNull(kvObject); assertEquals(patched.getCollection(), kvObject.getCollection()); assertEquals(patched.getKey(), kvObject.getKey()); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name, kvObject.getValue().get("name").asText()); }
From source file:de.innovationgate.wgpublisher.url.TitlePathManager.java
public List<String> buildTitlePath(WGContent baseContent, String mediaKey, WGLanguageChooser chooser) throws WGAPIException { List<String> path = new ArrayList<String>(); // Build a path of all titles up to the root content WGContent content = baseContent;// w w w . java2 s . co m while (true) { // Title path conflict marked. We cannot use titlepath if (Boolean.TRUE.equals(content.getExtensionData(TitlePathManager.EXTDATA_TITLEPATH_CONFLICT))) { path = null; break; } String title = createPathTitle(content).toString(); // Add the language and media key suffix if we are on first level String language = content.getLanguage().getName(); if (!LanguageBehaviourTools.isMultiLanguageDB(content.getDatabase()) && language.equals(content.getDatabase().getDefaultLanguage())) { language = WGPDispatcher.DEFAULT_LANGUAGE_TOKEN; } if (content == baseContent) { String customTitlepath = (String) content.getMetaData("titlepath"); boolean hasCustomTitlepath = (customTitlepath != null && !customTitlepath.equals("")); StringBuffer baseContentSuffix = new StringBuffer(); if (_includeKeys) { if (hasCustomTitlepath) { title = normalizeURLTitle(customTitlepath); } if (_useStructKeysInPath) baseContentSuffix.append("~").append(String.valueOf(content.getStructKey())); else { // use page sequence as key long seq = content.getStructEntry().getPageSequence(); if (seq != 0) baseContentSuffix.append("~").append(Long.toHexString(seq)); else baseContentSuffix.append("~").append(String.valueOf(content.getStructKey())); } } baseContentSuffix.append(".").append(language).append(".").append(mediaKey); title += baseContentSuffix.toString(); // if custom titlepath is set, we are finished: if (hasCustomTitlepath && _includeKeys) { path.add(title); break; } } path.add(title); if (content.getStructEntry().isRoot()) { break; } // Go up in hierarchy // If we cannot build a complete hierarchy path (b.c. of no released contents on a node) we must cancel the title path creation WGContent parentContent = content.getParentContent(false); // Fallback to a language chosen by the language chooser if (parentContent == null && _allowMixedLang && chooser != null) { parentContent = chooser.selectContentForPage(content.getStructEntry().getParentEntry(), false); } // Cannot find parent content bc. no valid language. We cannot use titlepath. if (parentContent == null) { path = null; break; } content = parentContent; } if (path != null) { // Add area if the content is not a member of the shortcut area String areaName = baseContent.getStructEntry().getArea().getName(); if (getShortcutArea() == null || !getShortcutArea().equals(areaName)) { path.add(normalizeURLTitle(areaName)); } Collections.reverse(path); } return path; }