List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:com.ery.estorm.zk.ZooKeeperWatcher.java
/** * Called when there is a connection-related event via the Watcher callback. * <p>/*from w w w . ja va 2s . c om*/ * If Disconnected or Expired, this should shutdown the cluster. But, since * we send a KeeperException.SessionExpiredException along with the abort * call, it's possible for the Abortable to catch it and try to create a new * session with ZooKeeper. This is what the client does in HCM. * <p> * * @param event */ private void connectionEvent(WatchedEvent event) { switch (event.getState()) { case SyncConnected: // Now, this callback can be invoked before the this.zookeeper is // set. // Wait a little while. long finished = System.currentTimeMillis() + this.conf.getLong("hbase.zookeeper.watcher.sync.connected.wait", 2000); while (System.currentTimeMillis() < finished) { Threads.sleep(1); if (this.recoverableZooKeeper != null) break; } if (this.recoverableZooKeeper == null) { LOG.error( "ZK is null on connection event -- see stack trace " + "for the stack trace when constructor was called on this zkw", this.constructorCaller); throw new NullPointerException("ZK is null"); } this.identifier = this.identifier + "-0x" + Long.toHexString(this.recoverableZooKeeper.getSessionId()); // Update our identifier. Otherwise ignore. LOG.debug(this.identifier + " connected"); break; // Abort the server if Disconnected or Expired case Disconnected: LOG.debug(prefix("Received Disconnected from ZooKeeper, ignoring")); break; case Expired: String msg = prefix(this.identifier + " received expired from " + "ZooKeeper, aborting"); // TODO: One thought is to add call to ZooKeeperListener so say, // ZooKeeperNodeTracker can zero out its data values. if (this.abortable != null) { this.abortable.abort(msg, new KeeperException.SessionExpiredException()); } break; case ConnectedReadOnly: case SaslAuthenticated: break; default: throw new IllegalStateException("Received event is not valid: " + event.getState()); } }
From source file:org.jahia.utils.zip.legacy.ZipInputStream.java
private void readEnd(ZipEntry e) throws IOException { int n = inf.getRemaining(); if (n > 0) { ((PushbackInputStream) in).unread(buf, len - n, n); }// w w w . j av a2s . c o m if ((e.flag & 8) == 8) { /* EXT descriptor present */ readFully(tmpbuf, 0, EXTHDR); long sig = get32(tmpbuf, 0); if (sig != EXTSIG) { // no EXTSIG present e.crc = sig; e.csize = get32(tmpbuf, EXTSIZ - EXTCRC); e.size = get32(tmpbuf, EXTLEN - EXTCRC); ((PushbackInputStream) in).unread(tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC); } else { e.crc = get32(tmpbuf, EXTCRC); e.csize = get32(tmpbuf, EXTSIZ); e.size = get32(tmpbuf, EXTLEN); } } if (e.size != inf.getTotalOut()) { throw new ZipException( "invalid entry size (expected " + e.size + " but got " + inf.getTotalOut() + " bytes)"); } if (e.csize != inf.getTotalIn()) { throw new ZipException("invalid entry compressed size (expected " + e.csize + " but got " + inf.getTotalIn() + " bytes)"); } if (e.crc != crc.getValue()) { throw new ZipException("invalid entry CRC (expected 0x" + Long.toHexString(e.crc) + " but got 0x" + Long.toHexString(crc.getValue()) + ")"); } }
From source file:org.jenkinsci.remoting.protocol.impl.ConnectionHeadersFilterLayerTest.java
@Theory public void headerExchange(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception { Random entropy = new Random(); final SettableFuture<Map<String, String>> serverActualHeaders = SettableFuture.create(); Map<String, String> clientExpectedHeaders = new HashMap<String, String>(); for (int i = 1 + entropy.nextInt(50); i > 0; i--) { clientExpectedHeaders.put(Long.toHexString(entropy.nextLong()), Long.toHexString(entropy.nextLong())); }//www .j a v a 2 s . co m ProtocolStack<IOBufferMatcher> client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) .filter(new ConnectionHeadersFilterLayer(clientExpectedHeaders, new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map<String, String> headers) throws ConnectionRefusalException { serverActualHeaders.set(headers); } })) .build(new IOBufferMatcherLayer()); final SettableFuture<Map<String, String>> clientActualHeaders = SettableFuture.create(); Map<String, String> serverExpectedHeaders = new HashMap<String, String>(); for (int i = 1 + entropy.nextInt(50); i > 0; i--) { serverExpectedHeaders.put(Long.toHexString(entropy.nextLong()), Long.toHexString(entropy.nextLong())); } ProtocolStack<IOBufferMatcher> server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) .filter(new ConnectionHeadersFilterLayer(serverExpectedHeaders, new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map<String, String> headers) throws ConnectionRefusalException { clientActualHeaders.set(headers); } })) .build(new IOBufferMatcherLayer()); byte[] expected = "Here is some sample data".getBytes("UTF-8"); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); server.get().send(data); client.get().awaitByteContent(is(expected)); assertThat(client.get().asByteArray(), is(expected)); assertThat(serverActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(serverExpectedHeaders)); assertThat(clientActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(clientExpectedHeaders)); }
From source file:org.microg.gms.gcm.McsService.java
private LoginRequest buildLoginRequest() { LastCheckinInfo info = LastCheckinInfo.read(this); return new LoginRequest.Builder().adaptive_heartbeat(false) .auth_service(LoginRequest.AuthService.ANDROID_ID).auth_token(Long.toString(info.securityToken)) .id("android-" + SDK_INT).domain("mcs.android.com") .device_id("android-" + Long.toHexString(info.androidId)).network_type(1) .resource(Long.toString(info.androidId)).user(Long.toString(info.androidId)).use_rmq2(true) .setting(Collections.singletonList(new Setting("new_vc", "1"))) .received_persistent_id(GcmPrefs.get(this).getLastPersistedIds()).build(); }
From source file:com.guillaumesoft.escapehellprison.PurchaseActivity.java
public void requestPurchase(final Product product) throws GeneralSecurityException, UnsupportedEncodingException, JSONException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); // This is an ID that allows you to associate a successful purchase with // it's original request. The server does nothing with this string except // pass it back to you, so it only needs to be unique within this instance // of your app to allow you to pair responses with requests. String uniqueId = Long.toHexString(sr.nextLong()); JSONObject purchaseRequest = new JSONObject(); purchaseRequest.put("uuid", uniqueId); purchaseRequest.put("identifier", product.getIdentifier()); purchaseRequest.put("testing", "true"); // This value is only needed for testing, not setting it results in a live purchase String purchaseRequestJson = purchaseRequest.toString(); byte[] keyBytes = new byte[16]; sr.nextBytes(keyBytes);//from w w w . j a va2 s . com SecretKey key = new SecretKeySpec(keyBytes, "AES"); byte[] ivBytes = new byte[16]; sr.nextBytes(ivBytes); IvParameterSpec iv = new IvParameterSpec(ivBytes); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, key, iv); byte[] payload = cipher.doFinal(purchaseRequestJson.getBytes("UTF-8")); cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, mPublicKey); byte[] encryptedKey = cipher.doFinal(keyBytes); Purchasable purchasable = new Purchasable(product.getIdentifier()); synchronized (mOutstandingPurchaseRequests) { mOutstandingPurchaseRequests.put(uniqueId, product); } mOuyaFacade.requestPurchase(this, purchasable, new PurchaseListener(product)); }
From source file:edu.harvard.i2b2.fhir.FhirUtil.java
public static Bundle getResourceBundle(List<Resource> s, String basePath, String url) { Bundle b = new Bundle(); for (Resource r : s) { if (r.getMeta() == null) { r.setMeta(FhirUtil.createMeta()); }/*from www . j av a2 s.c o m*/ BundleEntry be = FhirUtil.newBundleEntryForResource(r); b.getEntry().add(be); } BundleType value = new BundleType(); value.setValue(BundleTypeList.SEARCHSET); b.setType(value); UnsignedInt total = new UnsignedInt(); total.setValue(BigInteger.valueOf(s.size())); b.setTotal(total); Uri u = new Uri(); u.setValue(basePath); FhirUtil.setId(b, Long.toHexString(new Random().nextLong())); b.setMeta(FhirUtil.createMeta()); // b.setBase(u); return b; }
From source file:com.untangle.app.web_filter.WebFilterDecisionEngine.java
/** * Calculate the CCITT-CRC checksum for a string * /*from www . ja v a 2s .co m*/ * @param value * The string * @return The checksum */ private String crcccitt(String value) { int crc = 0xffff; for (byte b : value.getBytes()) { int i = ((b ^ (crc >> 8)) & 0xff); crc = ((crc << 8) ^ CRC_TABLE[i]) & 0xffff; } return Long.toHexString(crc); }
From source file:org.sakaiproject.tool.assessment.contentpackaging.ManifestGenerator.java
public void appendLOMMetadataToElement(String title, Element parent) { // imsmd:lom// w w w . j a v a2 s. c o m Element imsmdLom = createLOMElement("lom"); // imsmd:general Element imsmdGeneral = createLOMElement("general"); // imsmd:identifier String identifier = Long.toHexString((new Date()).getTime()); Element imsmdIdentifier = createLOMElementWithLangstring("identifier", identifier); imsmdGeneral.appendChild(imsmdIdentifier); // imsmd:title Element imsmdTitle = createLOMElementWithLangstring("title", title); imsmdGeneral.appendChild(imsmdTitle); imsmdLom.appendChild(imsmdGeneral); parent.appendChild(imsmdLom); }
From source file:com.marklogic.contentpump.RDFReader.java
protected String object(Node node) { if (node.isLiteral()) { String text = node.getLiteralLexicalForm(); String type = node.getLiteralDatatypeURI(); String lang = node.getLiteralLanguage(); if (lang == null || "".equals(lang)) { lang = ""; } else {//ww w . j a v a 2 s . c o m lang = " xml:lang='" + escapeXml(lang) + "'"; } if ("".equals(lang)) { if (type == null) { type = "http://www.w3.org/2001/XMLSchema#string"; } type = " datatype='" + escapeXml(type) + "'"; } else { type = ""; } return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>"; } else if (node.isBlank()) { return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString( fuse(scramble((long) node.hashCode()), fuse(scramble(milliSecs), randomValue))) + "</sem:object>"; } else { return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>"; } }
From source file:tv.ouya.sdk.UnityOuyaFacade.java
public void requestPurchase(final Product product) throws GeneralSecurityException, UnsupportedEncodingException, JSONException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); // This is an ID that allows you to associate a successful purchase with // it's original request. The server does nothing with this string except // pass it back to you, so it only needs to be unique within this instance // of your app to allow you to pair responses with requests. String uniqueId = Long.toHexString(sr.nextLong()); JSONObject purchaseRequest = new JSONObject(); purchaseRequest.put("uuid", uniqueId); purchaseRequest.put("identifier", product.getIdentifier()); purchaseRequest.put("testing", "true"); // This value is only needed for testing, not setting it results in a live purchase String purchaseRequestJson = purchaseRequest.toString(); byte[] keyBytes = new byte[16]; sr.nextBytes(keyBytes);/* www. ja va 2s. c om*/ SecretKey key = new SecretKeySpec(keyBytes, "AES"); byte[] ivBytes = new byte[16]; sr.nextBytes(ivBytes); IvParameterSpec iv = new IvParameterSpec(ivBytes); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, key, iv); byte[] payload = cipher.doFinal(purchaseRequestJson.getBytes("UTF-8")); cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, mPublicKey); byte[] encryptedKey = cipher.doFinal(keyBytes); Purchasable purchasable = new Purchasable(product.getIdentifier(), Base64.encodeToString(encryptedKey, Base64.NO_WRAP), Base64.encodeToString(ivBytes, Base64.NO_WRAP), Base64.encodeToString(payload, Base64.NO_WRAP)); synchronized (mOutstandingPurchaseRequests) { mOutstandingPurchaseRequests.put(uniqueId, product); } //custom-iap-code Log.i(LOG_TAG, "UnityOuyaFacade.requestPurchase(" + product.getIdentifier() + ")"); UnityPlayer.UnitySendMessage("OuyaGameObject", "DebugLog", "UnityOuyaFacade.requestPurchase(" + product.getIdentifier() + ")"); ouyaFacade.requestPurchase(purchasable, new PurchaseListener(product)); }