Пример #1
1
  public static UUID generateUuidForName(String name) {
    TFM_Log.info("Generating spoof UUID for " + name);
    name = name.toLowerCase();
    try {
      final MessageDigest mDigest = MessageDigest.getInstance("SHA1");
      byte[] result = mDigest.digest(name.getBytes());
      final StringBuilder sb = new StringBuilder();
      for (int i = 0; i < result.length; i++) {
        sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
      }

      return UUID.fromString(
          sb.substring(0, 8)
              + "-"
              + sb.substring(8, 12)
              + "-"
              + sb.substring(12, 16)
              + "-"
              + sb.substring(16, 20)
              + "-"
              + sb.substring(20, 32));
    } catch (NoSuchAlgorithmException ex) {
      TFM_Log.severe(ex);
    }

    return UUID.randomUUID();
  }
Пример #2
0
    @Override
    public void readFromNBT(NBTTagCompound tagCom) {
      TEC.idToUsername.clear();
      NBTTagList idUsernameTag = tagCom.getTagList("idUsernames", 10);
      for (int i = 0; i < idUsernameTag.tagCount(); i++) {
        NBTTagCompound tag = idUsernameTag.getCompoundTagAt(i);
        TEC.idToUsername.put(
            UUID.fromString(tagCom.getString("UUID")), tagCom.getString("playerName"));
      }

      TEC.aspectBuffer.clear();
      NBTTagList bufferTag = tagCom.getTagList("bufferTag", 10);
      for (int i = 0; i < bufferTag.tagCount(); i++) {
        NBTTagCompound idedBuffer = bufferTag.getCompoundTagAt(i);
        UUID playerID = UUID.fromString(idedBuffer.getString("playerID"));
        NBTTagList playersBuffer = idedBuffer.getTagList("buffer", 10);
        for (int j = 0; j < playersBuffer.tagCount(); j++) {
          NBTTagCompound bufferEntry = playersBuffer.getCompoundTagAt(j);

          NBTTagCompound scanTag = bufferEntry.getCompoundTag("scan");
          ScanResult scan =
              new ScanResult(
                  scanTag.getByte("type"),
                  scanTag.getInteger("id"),
                  scanTag.getInteger("meta"),
                  EntityList.createEntityFromNBT(
                      scanTag.getCompoundTag("entityTag"), DimensionManager.getWorld(0)),
                  scanTag.getString("phenomena"));

          TEC.addAspect(
              playerID, scan, bufferEntry.getDouble("chance"), bufferEntry.getDouble("percent"));
        }
      }
    }
  protected CFSecurityTSecGroupBuff unpackTSecGroupResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackTSecGroupResultSetToBuff";
    int idxcol = 1;
    CFSecurityTSecGroupBuff buff = schema.getFactoryTSecGroup().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFSecurityMySqlSchema.convertTimestampString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFSecurityMySqlSchema.convertTimestampString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
    }
    idxcol++;
    buff.setRequiredTenantId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredTSecGroupId(resultSet.getInt(idxcol));
    idxcol++;
    buff.setRequiredName(resultSet.getString(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFAccFeeDetailBuff unpackFeeDetailResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackFeeDetailResultSetToBuff";
    int idxcol = 1;
    CFAccFeeDetailBuff buff = schema.getFactoryFeeDetail().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFAccSybaseSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFAccSybaseSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredTenantId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredFeeId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredFeeDetailId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredDescription(resultSet.getString(idxcol));
    idxcol++;
    buff.setRequiredAmountCharged(resultSet.getBigDecimal(idxcol));
    idxcol++;
    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFSecurityHostNodeBuff unpackHostNodeResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackHostNodeResultSetToBuff";
    int idxcol = 1;
    CFSecurityHostNodeBuff buff = schema.getFactoryHostNode().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFSecurityPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFSecurityPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredClusterId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredHostNodeId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredDescription(resultSet.getString(idxcol));
    idxcol++;
    buff.setRequiredHostName(resultSet.getString(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFInternetURLProtocolBuff unpackURLProtocolResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackURLProtocolResultSetToBuff";
    int idxcol = 1;
    CFInternetURLProtocolBuff buff = schema.getFactoryURLProtocol().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFDbTestPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFDbTestPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredURLProtocolId(resultSet.getInt(idxcol));
    idxcol++;
    buff.setRequiredName(resultSet.getString(idxcol));
    idxcol++;
    buff.setRequiredDescription(resultSet.getString(idxcol));
    idxcol++;
    buff.setRequiredIsSecure(resultSet.getBoolean(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFSecuritySecFormBuff unpackSecFormResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackSecFormResultSetToBuff";
    int idxcol = 1;
    CFSecuritySecFormBuff buff = schema.getFactorySecForm().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFCrmDb2LUWSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFCrmDb2LUWSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredClusterId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredSecFormId(resultSet.getInt(idxcol));
    idxcol++;
    buff.setRequiredSecAppId(resultSet.getInt(idxcol));
    idxcol++;
    buff.setRequiredJEEServletMapName(resultSet.getString(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFSecurityISOCountryLanguageBuff unpackISOCountryLanguageResultSetToBuff(
      ResultSet resultSet) throws SQLException {
    final String S_ProcName = "unpackISOCountryLanguageResultSetToBuff";
    int idxcol = 1;
    CFSecurityISOCountryLanguageBuff buff = schema.getFactoryISOCountryLanguage().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFCrmMySqlSchema.convertTimestampString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFCrmMySqlSchema.convertTimestampString(colString));
      }
    }
    idxcol++;
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
    }
    idxcol++;
    buff.setRequiredISOCountryId(resultSet.getShort(idxcol));
    idxcol++;
    buff.setRequiredISOLanguageId(resultSet.getShort(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
  protected CFCrmMemoDataBuff unpackMemoDataResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackMemoDataResultSetToBuff";
    int idxcol = 1;
    CFCrmMemoDataBuff buff = schema.getFactoryMemoData().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFCrmMSSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFCrmMSSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredTenantId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredMemoId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredContactId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredMemo(resultSet.getString(idxcol));
    idxcol++;
    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
Пример #10
0
  @Override
  public UUID saveStatement(Statement statement) throws Exception {
    HTTPRequest request = new HTTPRequest();
    request.setRequestContent(
        new ByteArrayBuffer(statement.toJSON(this.getVersion(), this.usePrettyJSON()), "UTF-8"));

    String url = this.getEndpoint() + "statements";
    if (statement.getId() == null) {
      request.setMethod(HttpMethods.POST);
    } else {
      request.setMethod(HttpMethods.PUT);
      url += "?statementId=" + statement.getId().toString();
    }
    request.setURL(url);

    HTTPResponse response = this.sendRequest(request);
    int status = response.getStatus();

    // TODO: handle 409 conflict, etc.
    if (status == 204) {
      return statement.getId();
    } else if (status == 200) {
      String content = request.getResponseContent();
      return UUID.fromString(
          Mapper.getInstance().readValue(content, ArrayNode.class).get(0).textValue());
    }

    throw new UnexpectedHTTPResponse(response);
  }
  @Override
  public List<Job> listJobs(UUID subscriptionId, String serviceName) throws AzureCmdException {
    String[] cmd =
        new String[] {
          "mobile", "job", "list", "--json", "-s", subscriptionId.toString(), serviceName,
        };

    String json = AzureCommandHelper.getInstance().consoleExec(cmd);

    CustomJsonSlurper slurper = new CustomJsonSlurper();
    List<Map<String, Object>> tempRes = (List<Map<String, Object>>) slurper.parseText(json);

    List<Job> res = new ArrayList<Job>();
    for (Map<String, Object> item : tempRes) {
      Job j = new Job();
      j.setAppName(item.get("appName").toString());
      j.setName(item.get("name").toString());
      j.setEnabled(item.get("status").equals("enabled"));
      j.setId(UUID.fromString(item.get("id").toString()));

      if (item.get("intervalPeriod") != null) {
        j.setIntervalPeriod((Integer) item.get("intervalPeriod"));
        j.setIntervalUnit(item.get("intervalUnit").toString());
      }

      res.add(j);
    }

    return res;
  }
Пример #12
0
 public Resident getOwner(Object object) {
   try {
     EntityPlayer player =
         getters.contains("owner")
             ? (EntityPlayer) getters.get("owner").invoke(EntityPlayer.class, object, object)
             : null;
     if (player == null) return null;
     return MyTownUniverse.instance.getOrMakeResident(player);
   } catch (GetterException ex) {
     try {
       String username =
           getters.contains("owner")
               ? (String) getters.get("owner").invoke(String.class, object, object)
               : null;
       if (username == null) return null;
       if (username.length() == 36 && (username.split("-", -1).length - 1) == 4) {
         UUID uuid = UUID.fromString(username);
         return MyTownUniverse.instance.getOrMakeResident(uuid);
       }
       return MyTownUniverse.instance.getOrMakeResident(username);
     } catch (GetterException ex2) {
       try {
         UUID uuid =
             getters.contains("owner")
                 ? (UUID) getters.get("owner").invoke(UUID.class, object, object)
                 : null;
         if (uuid == null) return null;
         return MyTownUniverse.instance.getOrMakeResident(uuid);
       } catch (GetterException ex3) {
         return null;
       }
     }
   }
 }
Пример #13
0
 final Set<UUID> getPlayers() {
   ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
   if (pool != null) {
     try (Jedis rsc = pool.getResource()) {
       List<String> keys = new ArrayList<>();
       for (String i : getServerIds()) {
         keys.add("proxy:" + i + ":usersOnline");
       }
       if (!keys.isEmpty()) {
         Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
         if (users != null && !users.isEmpty()) {
           for (String user : users) {
             try {
               setBuilder = setBuilder.add(UUID.fromString(user));
             } catch (IllegalArgumentException ignored) {
             }
           }
         }
       }
     } catch (JedisConnectionException e) {
       // Redis server has disappeared!
       getLogger()
           .log(
               Level.SEVERE,
               "Unable to get connection from pool - did your Redis server go away?",
               e);
       throw new RuntimeException("Unable to get all players online", e);
     }
   }
   return setBuilder.build();
 }
Пример #14
0
		public class BluetoothClientThread extends Thread {
    //クライアント側の処理
    private final BluetoothSocket clientSocket;
    private final BluetoothDevice mDevice;
    private Context mContext;
    //UUIDの生成
    public static final UUID TECHBOOSTER_BTSAMPLE_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
    static BluetoothAdapter myClientAdapter;
    public String myNumber;
 
    //コンストラクタ定義
    public BluetoothClientThread(Context context, String myNum , BluetoothDevice device, BluetoothAdapter btAdapter){
        //各種初期化
        mContext = context;
        BluetoothSocket tmpSock = null;
        mDevice = device;
        myClientAdapter = btAdapter;
        myNumber = myNum;
 
        try{
            //自デバイスのBluetoothクライアントソケットの取得
            tmpSock = device.createRfcommSocketToServiceRecord(TECHBOOSTER_BTSAMPLE_UUID);
        }catch(IOException e){
            e.printStackTrace();
        }
        clientSocket = tmpSock;
    }
 
    public void run(){
        //接続要求を出す前に、検索処理を中断する。
        if
Пример #15
0
  String getClaimWorld(File SourceFile) {
    // retrieves the World the Claim contained in the given file is a part
    // of.
    // steps: Open, read first line, close, parse, return.
    if (!SourceFile.exists()) return "";
    try {
      BufferedReader fr = new BufferedReader(new FileReader(SourceFile.getAbsolutePath()));
      String firstline = fr.readLine();
      try {
        // if it is a UUID, than we need to advance forward to the next line, which will be the
        // lesserBoundaryCorner.
        UUID ud = UUID.fromString(firstline);
        if (ud != null) firstline = fr.readLine();
      } catch (Exception exx) {
        // expected- for older data, the first line won't be a UUID, but rather the lesser corner.

      }

      fr.close();
      String[] splitresult = firstline.split(";");
      return splitresult[0];

    } catch (Exception exx) {
      return "";
    }
  }
Пример #16
0
 @Override
 public Community findByIdOrLegacyId(Context context, String id) throws SQLException {
   if (StringUtils.isNumeric(id)) {
     return findByLegacyId(context, Integer.parseInt(id));
   } else {
     return find(context, UUID.fromString(id));
   }
 }
 public CFSecurityTSecGroupMemberHBuff() {
   super();
   requiredTenantId = CFSecurityTSecGroupMemberBuff.TENANTID_INIT_VALUE;
   requiredTSecGroupMemberId = CFSecurityTSecGroupMemberBuff.TSECGROUPMEMBERID_INIT_VALUE;
   requiredTSecGroupId = CFSecurityTSecGroupMemberBuff.TSECGROUPID_INIT_VALUE;
   requiredSecUserId =
       UUID.fromString(CFSecurityTSecGroupMemberBuff.SECUSERID_INIT_VALUE.toString());
 }
Пример #18
0
 public static UUID getUUIDForPlayerTracker(ItemStack stack) {
   try {
     return UUID.fromString(stack.getTagCompound().getString("playerUUID"));
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Пример #19
0
  public static boolean isUniqueId(String uuid) {
    try {
      UUID.fromString(uuid);
    } catch (IllegalArgumentException ex) {
      return false;
    }

    return true;
  }
Пример #20
0
 public Player getReply() {
   if (reply != null) {
     return r.searchPlayer(reply);
   }
   if (!getPlayerConfig().contains("reply")) {
     return null;
   }
   return r.searchPlayer(UUID.fromString(getPlayerConfig().getString("reply")));
 }
Пример #21
0
  @Override
  public StatementsResultLRSResponse saveStatements(List<Statement> statements) {
    StatementsResultLRSResponse lrsResponse = new StatementsResultLRSResponse();
    if (statements.isEmpty()) {
      lrsResponse.setSuccess(true);
      return lrsResponse;
    }

    ArrayNode rootNode = Mapper.getInstance().createArrayNode();
    for (Statement statement : statements) {
      rootNode.add(statement.toJSONNode(getVersion()));
    }

    lrsResponse.setRequest(new HTTPRequest());
    lrsResponse.getRequest().setResource("statements");
    lrsResponse.getRequest().setMethod(HttpMethods.POST);
    lrsResponse.getRequest().setContentType("application/json");
    try {
      lrsResponse
          .getRequest()
          .setContent(Mapper.getWriter(this.usePrettyJSON()).writeValueAsBytes(rootNode));
    } catch (JsonProcessingException ex) {
      lrsResponse.setErrMsg("Exception: " + ex.toString());
      return lrsResponse;
    }

    HTTPResponse response = makeSyncRequest(lrsResponse.getRequest());
    int status = response.getStatus();

    lrsResponse.setResponse(response);

    if (status == 200) {
      lrsResponse.setSuccess(true);
      lrsResponse.setContent(new StatementsResult());
      try {
        Iterator it =
            Mapper.getInstance().readValue(response.getContent(), ArrayNode.class).elements();
        for (int i = 0; it.hasNext(); ++i) {
          lrsResponse.getContent().getStatements().add(statements.get(i));
          lrsResponse
              .getContent()
              .getStatements()
              .get(i)
              .setId(UUID.fromString(((JsonNode) it.next()).textValue()));
        }
      } catch (Exception ex) {
        lrsResponse.setErrMsg("Exception: " + ex.toString());
        lrsResponse.setSuccess(false);
      }
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }
Пример #22
0
 public Set<UUID> getPlayersOnProxy(String server) {
   checkArgument(getServerIds().contains(server), server + " is not a valid proxy ID");
   try (Jedis jedis = pool.getResource()) {
     Set<String> users = jedis.smembers("proxy:" + server + ":usersOnline");
     ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
     for (String user : users) {
       builder.add(UUID.fromString(user));
     }
     return builder.build();
   }
 }
Пример #23
0
 @Override
 public OfflinePlayer getPlayer() {
   if (getFieldValue("uuid") != null) {
     return Bukkit.getOfflinePlayer(UUID.fromString(getFieldStringValue("uuid")));
   } else {
     setFieldValue(
         "uuid", Bukkit.getOfflinePlayer(getFieldStringValue("ign")).getUniqueId().toString());
     setFieldValue("ign", null);
     return getPlayer();
   }
 }
Пример #24
0
 private static UUID getUUID(String id) {
   return UUID.fromString(
       id.substring(0, 8)
           + "-"
           + id.substring(8, 12)
           + "-"
           + id.substring(12, 16)
           + "-"
           + id.substring(16, 20)
           + "-"
           + id.substring(20, 32));
 }
Пример #25
0
  /**
   * Retrieves UUID value from parameters map.
   *
   * @param key Key.
   * @param params Parameters map.
   * @return UUID value from parameters map or {@code null} if null or not exists.
   * @throws GridException If parsing failed.
   */
  @Nullable
  private static UUID uuidValue(String key, Map<String, Object> params) throws GridException {
    assert key != null;

    String val = (String) params.get(key);

    try {
      return val == null ? null : UUID.fromString(val);
    } catch (NumberFormatException ignore) {
      throw new GridException("Failed to parse parameter of UUID type [" + key + "=" + val + "]");
    }
  }
Пример #26
0
 final Set<UUID> getPlayersOnServer(@NonNull String server) {
   checkArgument(getProxy().getServers().containsKey(server), "server does not exist");
   Collection<String> asStrings =
       (Collection<String>)
           getServerPlayersScript.eval(
               ImmutableList.<String>of(), ImmutableList.<String>of(server));
   ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
   for (String s : asStrings) {
     builder.add(UUID.fromString(s));
   }
   return builder.build();
 }
Пример #27
0
  @Override
  public StatementLRSResponse saveStatement(Statement statement) {
    StatementLRSResponse lrsResponse = new StatementLRSResponse();
    lrsResponse.setRequest(new HTTPRequest());

    lrsResponse.getRequest().setResource("statements");
    lrsResponse.getRequest().setContentType("application/json");

    try {
      lrsResponse
          .getRequest()
          .setContent(statement.toJSON(this.getVersion(), this.usePrettyJSON()).getBytes("UTF-8"));
    } catch (IOException ex) {
      lrsResponse.setErrMsg("Exception: " + ex.toString());
      return lrsResponse;
    }

    if (statement.getId() == null) {
      lrsResponse.getRequest().setMethod(HttpMethods.POST);
    } else {
      lrsResponse.getRequest().setMethod(HttpMethods.PUT);
      lrsResponse.getRequest().setQueryParams(new HashMap<String, String>());
      lrsResponse.getRequest().getQueryParams().put("statementId", statement.getId().toString());
    }

    lrsResponse.setResponse(makeSyncRequest(lrsResponse.getRequest()));
    int status = lrsResponse.getResponse().getStatus();

    lrsResponse.setContent(statement);

    // TODO: handle 409 conflict, etc.
    if (status == 200) {
      lrsResponse.setSuccess(true);
      String content = lrsResponse.getResponse().getContent();
      try {
        lrsResponse
            .getContent()
            .setId(
                UUID.fromString(
                    Mapper.getInstance().readValue(content, ArrayNode.class).get(0).textValue()));
      } catch (Exception ex) {
        lrsResponse.setErrMsg("Exception: " + ex.toString());
        lrsResponse.setSuccess(false);
      }
    } else if (status == 204) {
      lrsResponse.setSuccess(true);
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }
Пример #28
0
  @Override
  public void run() {
    this.subSocket = this.mqm.getSubscriber();

    this.subSocket.subscribe("EUR/USD".getBytes()); // @TODO: Enable other pairs!
    this.subSocket.subscribe("USD/CHF".getBytes());
    this.subSocket.subscribe("EUR/CHF".getBytes());

    int index = 0;
    EVENT event = null;

    while (true) {
      PAIR pair = this.getPair(new String(this.subSocket.recv(0)));
      assert (pair != null);

      UUID uuid = UUID.fromString(new String(this.subSocket.recv(0)));
      assert (uuid != null);

      StringTokenizer st = new StringTokenizer(new String(this.subSocket.recv(0)), "|");
      assert (st != null && st.hasMoreTokens());

      RATE_EVENT_INFO rei =
          new RATE_EVENT_INFO(
              pair,
              new TICK(
                  Long.parseLong(st.nextToken()),
                  Double.parseDouble(st.nextToken()),
                  Double.parseDouble(st.nextToken())));

      logger.log(Level.INFO, rei.toString());
      index = 0;
      while (true) {
        event = null;
        synchronized (this.events) {
          if (index < this.events.size()) {
            event = this.events.get(index++);
          } else {
            break;
          }
        }

        if (event != null) {
          if (event.match(rei)) {
            this.mqm.setUuid(uuid);
            event.handle(rei, this);
          }
        } else {
          throw new NullPointerException("event");
        }
      }
    }
  }
Пример #29
0
 @Test
 public void uuidFunctions() throws IOException {
   ServiceLocator locator = container;
   CompositeRepository repository = locator.resolve(CompositeRepository.class);
   UUID id = UUID.randomUUID();
   String uri = repository.insert(new Composite().setId(id));
   Composite found =
       repository.query().filter(it -> it.getId().toString().equals(uri)).findAny().get();
   Assert.assertEquals(id, found.getId());
   found =
       repository.query().filter(it -> UUID.fromString(it.getURI()).equals(id)).findAny().get();
   Assert.assertEquals(id, found.getId());
 }
Пример #30
0
  private boolean deploy(File f) {
    try {
      if (log != null) log.info("deploy:" + f.getCanonicalPath());
      QEntry qentry = (QEntry) dirMap.get(f);
      SAXBuilder builder = createSAXBuilder();
      Document doc;
      if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
        doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
      } else {
        doc = decrypt(builder.build(f));
      }

      Element rootElement = doc.getRootElement();
      String iuuid = rootElement.getAttributeValue("instance");
      if (iuuid != null) {
        UUID uuid = UUID.fromString(iuuid);
        if (!uuid.equals(getInstanceId())) {
          deleteFile(f, iuuid);
          return false;
        }
      }
      Object obj = factory.instantiate(this, rootElement);
      qentry.setObject(obj);

      ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
      qentry.setInstance(instance);
    } catch (InstanceAlreadyExistsException e) {
      /*
       * Ok, the file we tried to deploy, holds an object
       *  that already has been deployed.
       *
       * Rename it out of the way.
       *
       */
      tidyFileAway(f, DUPLICATE_EXTENSION);
      getLog().warn("deploy", e);
      return false;
    } catch (Exception e) {
      getLog().warn("deploy", e);
      tidyFileAway(f, ERROR_EXTENSION);
      // This will also save deploy error repeats...
      return false;
    } catch (Error e) {
      getLog().warn("deploy", e);
      tidyFileAway(f, ENV_EXTENSION);
      // This will also save deploy error repeats...
      return false;
    }
    return true;
  }