Beispiel #1
0
 private ApiKey loadLine(String line) {
   ApiKey key = null;
   String[] splitted = line.split(DELIMITER, 2);
   if (splitted.length == 2 && !splitted[0].isEmpty() && !splitted[1].isEmpty()) {
     key = new ApiKey();
     key.setKeyId(Integer.parseInt(splitted[0]));
     key.setVerificationString(splitted[1]);
   }
   return key;
 }
Beispiel #2
0
 public void save(List<ApiKey> storedKeys, OutputStream stream) throws IOException {
   if (storedKeys != null) {
     try (BufferedWriter writer =
         new BufferedWriter(new OutputStreamWriter(stream, Util.createDefaultFileCharset()))) {
       for (ApiKey key : storedKeys) {
         writer.write(String.valueOf(key.getKeyId()));
         writer.write(DELIMITER);
         writer.write(key.getVerificationString());
         writer.write("\n");
       }
       logger.log(Level.INFO, "saved {0} api keys.", storedKeys.size());
       writer.flush();
     }
   }
 }