Example usage for java.util UUID toString

List of usage examples for java.util UUID toString

Introduction

In this page you can find the example usage for java.util UUID toString.

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this UUID .

Usage

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.ProfileObj.java

/**
 * Returns an Obj of type {@link #TYPE} with a profile representing
 * the local user. The profile is set with the given name and info fields.
 *//*from  w  w w.  j a  va  2 s.c o m*/
public static Obj forLocalUser(Context c, String name, String about) {
    JSONObject obj = new JSONObject();
    try {
        obj.put("name", name);
        obj.put("about", about);

        // TODO: Framework.
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter != null) {
            UUID btUuid = ContentCorral.getLocalBluetoothServiceUuid(c);
            String btMac = btAdapter.getAddress();
            obj.put(Contact.ATTR_BT_MAC, btMac);
            obj.put(Contact.ATTR_BT_CORRAL_UUID, btUuid.toString());
        }
        obj.put(Contact.ATTR_PROTOCOL_VERSION, App.POSI_VERSION);
    } catch (JSONException e) {
    }
    return new MemObj(TYPE, obj);
}

From source file:org.oscarehr.olis.OLISPollingUtil.java

public static String parseAndImportResponse(LoggedInInfo loggedInInfo, String response) throws Exception {
    String timeStampForNextStartDate = null;
    UUID uuid = UUID.randomUUID();
    String originalFile = "olis_" + uuid.toString() + ".response";
    String hl7Filename = "olis_" + uuid.toString() + ".hl7";
    //write full response to disk, this will make diagnosing issues easier
    Utilities.saveFile(new ByteArrayInputStream(response.getBytes("UTF-8")), originalFile);

    //Get HL7 Content from xml
    String responseContent = OLISUtils.getOLISResponseContent(response);

    //Write HL7 file to disk.
    String fileLocation = Utilities.saveFile(new ByteArrayInputStream(responseContent.getBytes("UTF-8")),
            hl7Filename);// w w  w. j  av a2s.  c o  m
    logger.debug(fileLocation);
    File file = new File(fileLocation);
    oscar.oscarLab.ca.all.upload.handlers.MessageHandler msgHandler = oscar.oscarLab.ca.all.upload.HandlerClassFactory
            .getHandler("OLIS_HL7");
    try {
        InputStream is = new FileInputStream(fileLocation);
        int check = FileUploadCheck.addFile(file.getName(), is, "0");
        if (check != FileUploadCheck.UNSUCCESSFUL_SAVE) {
            timeStampForNextStartDate = msgHandler.parse(loggedInInfo, "OLIS_HL7", fileLocation, check, null);

            if (timeStampForNextStartDate != null) {
                logger.info("Lab successfully added.");
            } else {
                logger.info("Error adding lab.");
            }
        } else {
            logger.info("Lab already in system.");
        }
        is.close();

    } catch (Exception e) {
        MiscUtils.getLogger().error("Couldn't add requested OLIS lab to Inbox.", e);
    }
    return timeStampForNextStartDate;
}

From source file:org.energyos.espi.common.test.FixtureFactory.java

public static String newXML(UUID uuid, String fileName) throws IOException {
    String s = newXML(fileName);/*w w  w. jav a  2s .com*/

    Pattern pattern = Pattern.compile("<id>urn:uuid:([A-Z0-9-]+)</id>");
    StringBuffer myStringBuffer = new StringBuffer();
    Matcher matcher = pattern.matcher(s);
    int i = 0;
    while (matcher.find()) {
        UUID replacement;
        if (i == 1) {
            replacement = uuid;
        } else {
            replacement = UUID.randomUUID();
        }
        matcher.appendReplacement(myStringBuffer,
                "<id>urn:uuid:" + replacement.toString().toUpperCase() + "</id>");
        i++;
    }
    matcher.appendTail(myStringBuffer);
    String subscription = myStringBuffer.toString().replaceAll("9B6C7066", uuid.toString());
    return subscription;
}

From source file:controllers.modules.opinionMiners.base.AspectOpinionMiner.java

public static Result getMined(UUID corpus, UUID lexicon, String engine, boolean detailed) {
    AspectOpinionMinedCorpusModel minedCorpusVM = getMined(corpus.toString(), lexicon.toString(), engine,
            detailed);/* w  w  w .ja  v a  2s  . c om*/
    if (minedCorpusVM == null) {
        return notFoundEntity(String.format("mined corpus for lexicon %s and corpus %s",
                UuidUtils.normalize(lexicon), UuidUtils.normalize(corpus)));
    }

    return ok(minedCorpusVM.asJson());
}

From source file:controllers.modules.opinionMiners.base.AspectOpinionMiner.java

public static Result resultsView(UUID corpus, UUID lexicon, String engine, boolean standalone) {
    AspectOpinionMinedCorpusModel minedCorpusFull = getMined(corpus.toString(), lexicon.toString(), engine,
            true);//  w w  w  .  j  a  v  a 2 s.c o  m
    if (standalone) {
        return ok(standaloneView.render("", aspectOpinionMinerResults.render(minedCorpusFull), null, null));
    }

    return ok(aspectOpinionMinerResults.render(minedCorpusFull));
}

From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java

/**
 * Gets the name of a player for the specified UUID.
 *
 * @param uuid the uuid to lookup, cannot be null
 *
 * @return the player's name, or null if not found or for invalid input
 *//*from ww w .j  a va 2 s  .c  om*/
public static String getName(UUID uuid) {
    if (uuid == null)
        return null;
    try {
        URL url = new URL("http://uuid.turt2live.com/name/" + uuid.toString().replaceAll("-", ""));
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String parsed = "";
        String line;
        while ((line = reader.readLine()) != null)
            parsed += line;
        reader.close();

        Object o = JSONValue.parse(parsed);
        if (o instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) o;
            Object status = jsonObject.get("status");
            if (status instanceof String && ((String) status).equalsIgnoreCase("ok")) {
                o = jsonObject.get("name");
                if (o instanceof String) {
                    return (String) o;
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.apache.usergrid.services.assets.data.AssetUtils.java

/** Returns the key for the bucket in the following form: [appId]/[{@link org.apache.usergrid.persistence.entities
 * .Asset#getPath()} *///from  w  ww  .j  av  a2  s .c  o m
public static String buildAssetKey(UUID appId, Entity entity) {
    Preconditions.checkArgument(entity.getUuid() != null,
            "The asset provided to buildAssetKey had a null UUID");
    Preconditions.checkArgument(appId != null, "The appId provided to buildAssetKey was null");
    return appId.toString().concat("/").concat(entity.getUuid().toString());
}

From source file:de.thejeterlp.bukkit.login.SQLAccount.java

protected static Account convert(UUID uuid) throws SQLException {
    checkReflection();/*  w  ww.  j  av a 2 s.com*/
    Validate.notNull(uuid, "uuid cannot be null!");
    PreparedStatement st = Login.getInstance().getDB()
            .getPreparedStatement("SELECT * FROM `" + Statics.USER_TABLE + "` WHERE `uuid` = ? LIMIT 1;");
    st.setString(1, uuid.toString());
    ResultSet rs = st.executeQuery();
    while (rs.next()) {
        int id = rs.getInt("id");
        Login.getInstance().getDB().closeResultSet(rs);
        Login.getInstance().getDB().closeStatement(st);
        PreparedStatement sta = Login.getInstance().getDB().getPreparedStatement(
                "SELECT * FROM `" + Statics.PASSWORD_TABLE + "` WHERE `userID` = ? LIMIT 1;");
        sta.setInt(1, id);
        ResultSet rset = sta.executeQuery();
        while (rset.next()) {
            String hash = rset.getString("password");
            Login.getInstance().getDB().closeResultSet(rset);
            Login.getInstance().getDB().closeStatement(sta);
            return new Account(id, uuid, hash);
        }
    }
    return null;
}

From source file:com.nridge.core.base.std.FilUtl.java

/**
 * Generates a unique path based on the parameters provided.
 *
 * @param aPathName Optional path name - if not provided, then the current working directory will be used.
 * @param aPrefix Path name prefix (appended with random id)
 *
 * @return A unique path name./* w  w w  . j a  va2 s  .  c om*/
 */
static public String generateUniquePathName(String aPathName, String aPrefix) {
    if (StringUtils.isEmpty(aPathName))
        aPathName = getWorkingDirectory();
    if (StringUtils.isEmpty(aPathName))
        aPrefix = "subpath";

    // 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();

    return String.format("%s%c%s_%d", aPathName, File.separatorChar, aPrefix, longValue);
}

From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java

/**
 * Gets the known username history of a UUID. All dates are in UTC.
 * This returns a map of player names and when they were last seen (the
 * approximate date they stopped using that name).
 *
 * @param uuid the uuid to lookup, cannot be null
 *
 * @return a map of names and dates (UTC), or an empty map for invalid input or unknown/non-existent history
 *//*from w  ww  . j a  va 2s.c  om*/
public static Map<String, Date> getHistory(UUID uuid) {
    if (uuid == null)
        return new HashMap<>();
    try {
        URL url = new URL("http://uuid.turt2live.com/history/" + uuid.toString().replaceAll("-", ""));
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String parsed = "";
        String line;
        while ((line = reader.readLine()) != null)
            parsed += line;
        reader.close();

        Map<String, Date> map = new HashMap<>();
        Object o = JSONValue.parse(parsed);
        if (o instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) o;
            Object namesObj = jsonObject.get("names");
            if (namesObj instanceof JSONArray) {
                JSONArray names = (JSONArray) namesObj;
                for (Object name : names) {
                    o = name;
                    if (o instanceof JSONObject) {
                        JSONObject json = (JSONObject) o;

                        Object nameObj = json.get("name");
                        Object dateObj = json.get("last-seen");
                        if (nameObj instanceof String && dateObj instanceof String) {
                            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                            format.setTimeZone(TimeZone.getTimeZone("UTC"));
                            try {
                                Date date = format.parse((String) dateObj);
                                map.put((String) nameObj, date);
                            } catch (ParseException e) {
                                System.out.println("Could not parse " + dateObj + ": " + e.getMessage());
                            }
                        }
                    }
                }
            }
        }
        return map;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new HashMap<>();
}