List of usage examples for java.util UUID toString
public String toString()
From source file:com.nridge.core.base.std.FilUtl.java
/** * Generates a unique path and file name combination based on the parameters * provided./*from www.java 2 s.c om*/ * * @param aPathName Path name. * @param aFilePrefix File name prefix (appended with random id) * @param aFileExtension File name extension. * * @return A unique path and file name combination. */ static public String generateUniquePathFileName(String aPathName, String aFilePrefix, String aFileExtension) { String pathFileName; if (StringUtils.isNotEmpty(aPathName)) pathFileName = String.format("%s%c%s", aPathName, File.separatorChar, aFilePrefix); else pathFileName = aFilePrefix; // http://www.javapractices.com/topic/TopicAction.do?Id=56 UUID uniqueId = UUID.randomUUID(); byte idBytes[] = uniqueId.toString().getBytes(); Checksum checksumValue = new CRC32(); checksumValue.update(idBytes, 0, idBytes.length); long longValue = checksumValue.getValue(); if (StringUtils.startsWith(aFileExtension, ".")) return String.format("%s_%d%s", pathFileName, longValue, aFileExtension); else return String.format("%s_%d.%s", pathFileName, longValue, aFileExtension); }
From source file:io.hawkcd.agent.AgentConfiguration.java
private static String generateAgentId(Properties properties) { UUID agentId = UUID.randomUUID(); try {// ww w . j a v a 2 s. c o m File configFile = new File(ConfigConstants.AGENT_CONFIG_FILE_LOCATION); OutputStream output = new FileOutputStream(configFile); properties.setProperty("agentId", agentId.toString()); properties.store(output, null); output.close(); } catch (IOException io) { io.printStackTrace(); } return agentId.toString(); }
From source file:com.eryansky.common.utils.io.FileUtil.java
/** * ???? ??,UUID??,??????// ww w .j a v a 2 s. c o m * * @param fileName * ??+? * @return */ public static String generateUUIDFileName(String fileName) { UUID uuid = UUID.randomUUID(); String str = fileName; System.out.println(str); str = uuid.toString() + "." + str.substring(str.lastIndexOf(".") + 1); return str; }
From source file:org.brekka.phalanx.webservices.PhalanxEndpoint.java
protected static String id(UUID id) { return id.toString(); }
From source file:$.DeviceTypeServiceImpl.java
private static String shortUUID() { UUID uuid = UUID.randomUUID(); long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong(); return Long.toString(l, Character.MAX_RADIX); }//from w w w. ja va2 s.c o m
From source file:com.ntsync.android.sync.activities.VerifyPaymentProgressDialog.java
/** * Creates a Verify Progress Dialog// ww w. ja v a 2s .co m * * @param userName * @param pwdSalt * @param authtoken * @return invisible Dialog */ public static VerifyPaymentProgressDialog newInstance(UUID selectedPriceId, String jsonProofOfPayment, String accountName) { VerifyPaymentProgressDialog dlg = new VerifyPaymentProgressDialog(); Bundle args = new Bundle(); args.putString(PARAM_PRICEID, selectedPriceId.toString()); args.putString(PARAM_PROOFOFPAYMENT, jsonProofOfPayment); args.putString(PARAM_ACCOUNTNAME, accountName); dlg.setArguments(args); return dlg; }
From source file:com.baasbox.controllers.Root.java
/** * /admin/db/import (POST)/* ww w.j av a2 s . co m*/ * * the method allows to upload a json export file and apply it to the db. * WARNING: all data on the db will be wiped out before importing * * @return a 200 Status code when the import is successfull,a 500 status code otherwise */ @With({ RootCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result importDb() { String appcode = (String) ctx().args.get("appcode"); MultipartFormData body = request().body().asMultipartFormData(); if (body == null) return badRequest("missing data: is the body multipart/form-data?"); FilePart fp = body.getFile("file"); if (fp != null) { ZipInputStream zis = null; try { java.io.File multipartFile = fp.getFile(); java.util.UUID uuid = java.util.UUID.randomUUID(); File zipFile = File.createTempFile(uuid.toString(), ".zip"); FileUtils.copyFile(multipartFile, zipFile); zis = new ZipInputStream(new FileInputStream(zipFile)); DbManagerService.importDb(appcode, zis); zipFile.delete(); return ok(); } catch (Exception e) { BaasBoxLogger.error(ExceptionUtils.getStackTrace(e)); return internalServerError(ExceptionUtils.getStackTrace(e)); } finally { try { if (zis != null) { zis.close(); } } catch (IOException e) { // Nothing to do here } } } else { return badRequest("The form was submitted without a multipart file field."); } }
From source file:com.avatarproject.core.storage.UserCache.java
/** * Adds a player into the custom UserCache. * @param player Player to add to the cache. *///from w w w . jav a2 s . co m @SuppressWarnings("unchecked") public static void addUser(Player player) { String name = player.getName(); UUID uuid = player.getUniqueId(); JSONArray array = getUserCache(); try { for (int n = 0; n < array.size(); n++) { //Loop through all the objects in the array. JSONObject object = (JSONObject) array.get(n); if (object.get("id").equals(uuid.toString())) { //Check if the player's UUID exists in the cache. if (String.valueOf(object.get("name")).equalsIgnoreCase(name)) { return; } else { object.put("name", name); //Update the user. FileWriter fileOut = new FileWriter(usercache); fileOut.write(array.toJSONString()); //Write the JSON array to the file. fileOut.close(); return; } } } JSONObject newEntry = new JSONObject(); newEntry.put("id", uuid.toString()); newEntry.put("name", name); array.add(newEntry); //Add a new player into the cache. FileWriter fileOut = new FileWriter(usercache); fileOut.write(array.toJSONString()); //Write the JSON array to the file. fileOut.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.ku.brc.af.core.UsageTracker.java
/** * Gets the installation ID that 'uniquely' identifies the running instance * from other installations./* w ww. j a v a2 s . c om*/ * * @return the installation ID string */ public synchronized static String getInstallId() { AppPreferences appPrefs = AppPreferences.getLocalPrefs(); if (appPrefs.isAvailable()) { // get the first part of the install ID String installIdStart = appPrefs.get("InstallIdStart", null); //$NON-NLS-1$ if (installIdStart == null) { // create a new ID start (this is the first time the app has run) Random r = new Random(System.currentTimeMillis()); UUID idStart = new UUID(r.nextLong(), r.nextLong()); installIdStart = idStart.toString(); appPrefs.put("InstallIdStart", installIdStart); //$NON-NLS-1$ } // get the last part of the install ID String installIdEnd = appPrefs.get("InstallIdEnd", null); //$NON-NLS-1$ File pluginRegFile = XMLHelper.getConfigDir("plugin_registry.xml"); //$NON-NLS-1$ long lastMod = pluginRegFile.lastModified(); String lastModString = Long.toHexString(lastMod); if (installIdEnd == null || !installIdEnd.equals(lastModString)) { // somebody must have copied this install to a new storage // reset the InstallIdEnd preference clearUsageStats(); appPrefs.put("InstallIdEnd", lastModString); //$NON-NLS-1$ installIdEnd = lastModString; } String installId = installIdStart + "--" + installIdEnd; //$NON-NLS-1$ return installId; } return null; }
From source file:edu.monash.merc.util.DMUtil.java
public static String genUUID() { UUID uuid = UUID.randomUUID(); return uuid.toString(); }