Пример #1
0
  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
  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
  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
  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);
    }
  }