Exemplo n.º 1
0
  // add the new user to the encrypted users file which has the detailed stats for all users
  // synchronize to make sure that only one thread can be inside this block at a time.
  public static synchronized String addUserAndIssueCode(UserStats stats)
      throws IOException, GeneralSecurityException, ClassNotFoundException, NoMoreCodesException {

    // ok, now we have a list of stats objects, representing all users.
    // add this user to the list.
    // the code assigned to this user will simply be codes.get(users.size())
    // but do an error check first to be sure we're not out of codes
    List<UserStats> users = readUsersFile();

    if (users.size() >= MemoryStudy.codes.size()) {
      log.warn("NOC WARNING: codes file exhausted!!!!");
      throw new NoMoreCodesException();
    }

    // ok, we have enough codes, just give out one
    String passkey = MemoryStudy.codes.get(users.size());
    int USERID_BASE =
        100; // userid numbering starts from USERID_BASE, new id is base + # existing codes
    stats.userid = Integer.toString(USERID_BASE + users.size());
    stats.code = passkey;
    users.add(stats);

    // encrypt and write the users file back
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(users);
    oos.close();
    CryptoUtils.writeEncryptedBytes(baos.toByteArray(), USERS_FILE);

    return passkey;
  }
Exemplo n.º 2
0
 public void recordStartTime() {
   stats.starttime = new Date().getTime();
 }
Exemplo n.º 3
0
 /*checks whether the test is done. if it is, it outputs the final log info and does time calculations*/
 public boolean checkForFinish() {
   if (questionIndex > questions.size()) {
     stats.endtime = new Date().getTime();
     return true;
   } else return false;
 }