List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.java
List<DatanodeStorageInfo> removeZombieStorages() { List<DatanodeStorageInfo> zombies = null; synchronized (storageMap) { Iterator<Map.Entry<String, DatanodeStorageInfo>> iter = storageMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, DatanodeStorageInfo> entry = iter.next(); DatanodeStorageInfo storageInfo = entry.getValue(); if (storageInfo.getLastBlockReportId() != curBlockReportId) { LOG.info(storageInfo.getStorageID() + " had lastBlockReportId 0x" + Long.toHexString(storageInfo.getLastBlockReportId()) + ", but curBlockReportId = 0x" + Long.toHexString(curBlockReportId)); iter.remove();/*ww w . j a v a2 s.co m*/ if (zombies == null) { zombies = new LinkedList<DatanodeStorageInfo>(); } zombies.add(storageInfo); } storageInfo.setLastBlockReportId(0); } } return zombies == null ? EMPTY_STORAGE_INFO_LIST : zombies; }
From source file:org.mitre.ccv.mapred.GenerateFeatureVectors.java
@Override public int run(String[] args) throws Exception { JobConf conf = new JobConf(getConf()); int cardinality = Integer.MAX_VALUE; boolean cleanLogs = false; String listInput = null;//from w w w . j a v a 2 s. c o m // @TODO: use commons getopts, org.apache.hadoop.util.GenericOptionsParser used it ArrayList<String> other_args = new ArrayList<String>(); for (int i = 0; i < args.length; ++i) { try { if ("-m".equals(args[i])) { conf.setNumMapTasks(Integer.parseInt(args[++i])); } else if ("-r".equals(args[i])) { conf.setNumReduceTasks(Integer.parseInt(args[++i])); } else if ("-c".equals(args[i])) { cleanLogs = true; } else if ("-l".equals(args[i])) { listInput = args[++i]; } else if ("-t".equals(args[i])) { cardinality = Integer.parseInt(args[++i]); } else if ("-libjars".equals(args[i])) { conf.set("tmpjars", FileUtils.validateFiles(args[++i], conf)); URL[] libjars = FileUtils.getLibJars(conf); if (libjars != null && libjars.length > 0) { // Add libjars to client/tasks classpath conf.setClassLoader(new URLClassLoader(libjars, conf.getClassLoader())); // Adds libjars to our classpath Thread.currentThread().setContextClassLoader( new URLClassLoader(libjars, Thread.currentThread().getContextClassLoader())); } } else { other_args.add(args[i]); } } catch (NumberFormatException except) { System.out.println("ERROR: Integer expected instead of " + args[i]); return printUsage(); } catch (ArrayIndexOutOfBoundsException except) { System.out.println("ERROR: Required parameter missing from " + args[i - 1]); return printUsage(); } } // Make sure there are exactly 2 parameters left. if (other_args.size() != 2) { System.out.println("ERROR: Wrong number of parameters: " + other_args.size() + " instead of 3."); return printUsage(); } if (listInput == null || listInput.length() == 0) { System.out.println("Need kmer sequence file path!"); return printUsage(); } long now = System.currentTimeMillis(); Path listInputPath = new Path(listInput); Path listOutputPath = new Path(listInputPath.getParent(), "kmer_" + Long.toHexString(now) + "_tmp"); LOG.info(String.format("Loading %d sorted k-mers from %s to %s", cardinality, listInputPath.toString(), listOutputPath.toString())); int num = CompleteCompositionVectorUtils.flattenKmerEntropySequenceFile(conf, cardinality, listInputPath.toString(), listOutputPath.toString(), cleanLogs); initJob(conf, listOutputPath.toString(), num, other_args.get(0), other_args.get(1), cleanLogs); return 0; }
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.TestContainerLocalizer.java
static ResourceLocalizationSpec getMockRsrc(Random r, LocalResourceVisibility vis, Path p) { ResourceLocalizationSpec resourceLocalizationSpec = mock(ResourceLocalizationSpec.class); LocalResource rsrc = mock(LocalResource.class); String name = Long.toHexString(r.nextLong()); URL uri = mock(org.apache.hadoop.yarn.api.records.URL.class); when(uri.getScheme()).thenReturn("file"); when(uri.getHost()).thenReturn(null); when(uri.getFile()).thenReturn("/local/" + vis + "/" + name); when(rsrc.getResource()).thenReturn(uri); when(rsrc.getSize()).thenReturn(r.nextInt(1024) + 1024L); when(rsrc.getTimestamp()).thenReturn(r.nextInt(1024) + 2048L); when(rsrc.getType()).thenReturn(LocalResourceType.FILE); when(rsrc.getVisibility()).thenReturn(vis); when(resourceLocalizationSpec.getResource()).thenReturn(rsrc); when(resourceLocalizationSpec.getDestinationDirectory()).thenReturn(URL.fromPath(p)); return resourceLocalizationSpec; }
From source file:com.marklogic.contentpump.RDFReader.java
protected String resource(Node rsrc) { if (rsrc.isBlank()) { return "http://marklogic.com/semantics/blank/" + Long .toHexString(fuse(scramble((long) rsrc.hashCode()), fuse(scramble(milliSecs), randomValue))); } else {/* w w w .jav a 2s .c o m*/ return escapeXml(rsrc.toString()); } }
From source file:com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA.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 . j a v a 2 s . co m 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, ouyaPublicKey); byte[] encryptedKey = cipher.doFinal(keyBytes); purchasable = new Purchasable(product.getIdentifier(), Base64.encodeToString(encryptedKey, Base64.NO_WRAP), Base64.encodeToString(ivBytes, Base64.NO_WRAP), Base64.encodeToString(payload, Base64.NO_WRAP)); synchronized (ouyaOutstandingPurchaseRequests) { ouyaOutstandingPurchaseRequests.put(uniqueId, product); } }
From source file:org.cryptomator.crypto.aes256.Aes256Cryptor.java
/** * Each path component, i.e. file or directory name separated by path separators, gets encrypted for its own.<br/> * Encryption will blow up the filename length due to aes block sizes and base32 encoding. The result may be too long for some old file * systems.<br/>//from ww w. ja v a 2 s. co m * This means that we need a workaround for filenames longer than the limit defined in * {@link FileNamingConventions#ENCRYPTED_FILENAME_LENGTH_LIMIT}.<br/> * <br/> * In any case we will create the encrypted filename normally. For those, that are too long, we calculate a checksum. No * cryptographically secure hash is needed here. We just want an uniform distribution for better load balancing. All encrypted filenames * with the same checksum will then share a metadata file, in which a lookup map between encrypted filenames and short unique * alternative names are stored.<br/> * <br/> * These alternative names consist of the checksum, a unique id and a special file extension defined in * {@link FileNamingConventions#LONG_NAME_FILE_EXT}. */ private String encryptPathComponent(final String cleartext, final SecretKey key, CryptorIOSupport ioSupport) throws IllegalBlockSizeException, BadPaddingException, IOException { final byte[] mac = hmacSha256(hMacMasterKey).doFinal(cleartext.getBytes()); final byte[] partialIv = ArrayUtils.subarray(mac, 0, 10); final ByteBuffer iv = ByteBuffer.allocate(AES_BLOCK_LENGTH); iv.put(partialIv); final Cipher cipher = this.aesCtrCipher(key, iv.array(), Cipher.ENCRYPT_MODE); // add NULL padding to the cleartext to get a multiple of the block size: final byte[] cleartextBytes = cleartext.getBytes(StandardCharsets.UTF_8); final byte[] nullBytePadding = new byte[AES_BLOCK_LENGTH - cleartextBytes.length % AES_BLOCK_LENGTH]; final byte[] paddedCleartextBytes = ArrayUtils.addAll(cleartextBytes, nullBytePadding); final byte[] encryptedBytes = cipher.doFinal(paddedCleartextBytes); final String ivAndCiphertext = ENCRYPTED_FILENAME_CODEC.encodeAsString(partialIv) + IV_PREFIX_SEPARATOR + ENCRYPTED_FILENAME_CODEC.encodeAsString(encryptedBytes); if (ivAndCiphertext.length() + BASIC_FILE_EXT.length() > ENCRYPTED_FILENAME_LENGTH_LIMIT) { final String crc32 = Long.toHexString(crc32Sum(ivAndCiphertext.getBytes())); final String metadataFilename = crc32 + METADATA_FILE_EXT; final LongFilenameMetadata metadata = this.getMetadata(ioSupport, metadataFilename); final String alternativeFileName = crc32 + LONG_NAME_PREFIX_SEPARATOR + metadata.getOrCreateUuidForEncryptedFilename(ivAndCiphertext).toString() + LONG_NAME_FILE_EXT; this.storeMetadata(ioSupport, metadataFilename, metadata); return alternativeFileName; } else { return ivAndCiphertext + BASIC_FILE_EXT; } }
From source file:de.burlov.amazon.s3.dirsync.DirSync.java
/** * Methode laedt lokale Dateien die als geaendert erkannt wurden auf den Server hoch * //w w w .j av a 2s . com * @param folder * @param files * @param snapShot * @throws DirSyncException */ private void syncUp(Folder folder, Collection<LocalFile> files, boolean snapShot) throws DirSyncException { boolean dirty = false; long uploadedBytes = 0; for (LocalFile item : files) { File file = item.getLocalFile(); if (file.exists()) { /* * Den Hashwert der lokalen Datei berechnen und versuchen zuerst eine bereits * hochgeladene Dateie mit diesem Hash zu finden. Es kann je sein, dass lokale Datei * nur umbenannt oder kopiert wurde, dann braucht man nicht die Daten noch mal * hochzuladen. */ byte[] hash; try { hash = digestFile(file, shaDigest); } catch (IOException e1) { throw new DirSyncException("Unable to hash file: " + file.getAbsolutePath(), e1); } FileInfo info = folder.getFileInfo(hash); if (info != null) { /* * Eine Datei existiert bereits mit so einem Hashwert. Keine Daten hochladen * sondern nur bereits hochgeladene Datei zusaetzlich mit neuem Dateinamen * verknuepfen */ folder.getIndexData().put(item.getRelativeName(), info); log.info("Link file with uploaded data: " + item.getRelativeName()); info.setLastModified(file.lastModified()); dirty = true; } else { /* * Noch kein Datenobjekt auf dem Server mit so einem Hashwert. Daten muessen * hochgeladen werden. Hochgeladene Objekte immer unter neuem Key speichern. * Somit alte Daten auf jeden Fall erhalten bleiben bis Folder-Index hochgeladen * wurde */ info = new FileInfo(file.lastModified(), file.length(), Long.toHexString(mainIndex.getNextId())); try { log.info("Uploading " + file.getAbsolutePath()); /* * Neue/geaenderte Datei uploaden */ uploadFile(file, getFileKey(info.getStorageId())); dirty = true; uploadedBytes += file.length(); transferredData += file.length(); transferredFiles++; info.setHash(hash); } catch (Exception e) { throw new DirSyncException( "File upload '" + file.getAbsolutePath() + "' failed. " + e.getLocalizedMessage()); } folder.getIndexData().put(item.getRelativeName(), info); if (uploadedBytes > 10000000) { /* * In bestimmten Intervalen die Indexinformationen auf dem Server * aktualisieren, damit schon hochgeladenen Daten nicht verloren gehen */ saveFolder(folder); dirty = false; uploadedBytes = 0; } } } else if (snapShot) { /* * Lokale Datei wurde geloescht, in 'snap shot' Modus auch auf dem Server loeschen */ if (folder.getIndexData().remove(item.getRelativeName()) != null) { log.info("Remove file " + item.getRelativeName()); deletedFiles++; dirty = true; } } } /* * Jetzt Folder-Index speichern und nicht mehr referenzierte Objekte loschen */ Set<String> idsToDelete = folder.syncFileHashIndex(); if (dirty) { saveFolder(folder); } try { for (String id : idsToDelete) { deleteRemoteFile(id); } } catch (S3ServiceException e) { /* * Fehler ist nicht schwerwiegend. Es werden hochstens verwaiste Objekte uebrigbleiben * die mit 'cleanup' Befehle geloescht werden koennen */ log.error("Unable to delete remote file. " + e.getLocalizedMessage(), e); } }
From source file:com.marklogic.contentpump.RDFReader.java
private String resource(Resource rsrc) { if (rsrc.isAnon()) { return "http://marklogic.com/semantics/blank/" + Long .toHexString(fuse(scramble((long) rsrc.hashCode()), fuse(scramble(milliSecs), randomValue))); } else {// ww w . j a v a 2s . co m return escapeXml(rsrc.toString()); } }
From source file:interactivespaces.activity.component.route.ros.RosMessageRouterActivityComponent.java
/** * Create a new handler invocation ID./*w w w. j a va 2 s.com*/ * * @return a unique ID for the handler invocation */ private String newHandlerInvocationId() { return Long.toHexString(handlerInvocationId.getAndIncrement()); }
From source file:tv.ouya.sdk.TestOuyaFacade.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);// w w w .j a v a 2 s . 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("TestOuyaFacade", "TestOuyaFacade.requestPurchase(" + product.getIdentifier() + ")"); UnityPlayer.UnitySendMessage("OuyaGameObject", "DebugLog", "TestOuyaFacade.requestPurchase(" + product.getIdentifier() + ")"); ouyaFacade.requestPurchase(purchasable, new PurchaseListener(product)); }