コード例 #1
0
ファイル: PersistableWordStat.java プロジェクト: em881g/oies
  private void storeWordCount() throws IOException {
    final ArrayList<String> topWords = new ArrayList<String>(wordCount.keySet());
    Collections.sort(
        topWords,
        new Comparator<String>() {
          @Override
          public int compare(final String o1, final String o2) {
            Integer c1 = wordCount.containsKey(o1) ? wordCount.get(o1) : null;
            Integer c2 = wordCount.containsKey(o2) ? wordCount.get(o2) : null;
            return -c1.compareTo(c2);
          }
        });

    final PrintWriter writer = new PrintWriter(new FileWriter(Config.getStatOutFilename(), false));
    try {
      for (String topWord : topWords) {
        final String line = String.format("%s (%d)", topWord, wordCount.get(topWord));
        writer.append(line).append('\n');
      }
      writer.flush();
    } finally {
      writer.close();
    }

    System.out.println(">>> updated stats file");
  }
コード例 #2
0
ファイル: PersistableWordStat.java プロジェクト: em881g/oies
  private ReadProgress loadReadProgress(final ITweetFeed feed) {
    try {
      final BufferedReader is =
          new BufferedReader(new FileReader(Config.getStatProgressFilename()));
      final String line = is.readLine();

      final String[] split = line.split("\\s");

      return new ReadProgress(
          Long.valueOf(split[0]), Long.valueOf(split[1]), Integer.valueOf(split[2]));
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return null;
  }
コード例 #3
0
ファイル: PersistableWordStat.java プロジェクト: em881g/oies
  private void storeReadProgress(final ReadProgress progress) throws IOException {
    final String toWrite =
        String.format(
            "%d %d %d",
            progress.lastContinuouslyProcessedId,
            progress.lastProcessedId,
            progress.lastProcessedPage);

    final PrintWriter writer =
        new PrintWriter(new FileWriter(Config.getStatProgressFilename(), false));
    try {
      writer.append(toWrite);
      writer.flush();
    } finally {
      writer.close();
    }
  }
コード例 #4
0
ファイル: PersistableWordStat.java プロジェクト: em881g/oies
  private void loadWordCount() {
    try {
      final BufferedReader is = new BufferedReader(new FileReader(Config.getStatOutFilename()));

      while (true) {
        final String line = is.readLine();
        if (line == null) {
          return;
        }
        final Matcher matcher = STAT_LINE_PATTERN.matcher(line);
        if (!matcher.matches()) {
          throw new IllegalArgumentException();
        }
        wordCount.put(matcher.group(1), Integer.valueOf(matcher.group(2)));
      }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }