Esempio n. 1
0
  public Crystal loadCrystal(int id) throws ExpiredCrystalException, CrystalNotFoundException {
    FileInputStream stream;
    InputStreamReader streamReader;
    BufferedReader in;

    try {
      stream = new FileInputStream(storageFile);
      streamReader = new InputStreamReader(stream);
      in = new BufferedReader(streamReader);

      String line;
      while ((line = in.readLine()) != null) {
        int itemID = Integer.valueOf(line.split("==")[0]);
        if (itemID == id) {
          in.close();
          if (Long.valueOf(line.split("==")[1]) < System.currentTimeMillis()) {
            removeItem(
                new Crystal(
                    this,
                    itemID,
                    Long.valueOf(line.split("==")[1]),
                    Converters.fromBase64(line.split("==")[2])));
            throw new ExpiredCrystalException(id, Long.valueOf(line.split("==")[1]));
          }
          return new Crystal(
              this,
              itemID,
              Long.valueOf(line.split("==")[1]),
              Converters.fromBase64(line.split("==")[2]));
        }
      }

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    throw new CrystalNotFoundException(id);
  }