Exemple #1
0
  public List<String> getLogFilenames() {
    File logDir = getLogsDir();
    List<File> logDirnames = Arrays.asList(logDir.listFiles());
    List<String> logFilenames = new ArrayList<String>();

    for (File logMonthDir : logDirnames) {
      if (logMonthDir.isDirectory() && logMonthDir.listFiles().length > 0) {
        for (File logFile : logMonthDir.listFiles()) {
          if (logFile.getName().endsWith(".log")) {
            logFilenames.add(logMonthDir.getName() + File.separator + logFile.getName());
          }
        }
      }
    }

    Collections.sort(logFilenames, new LogFilenameComparator());
    Collections.reverse(logFilenames);

    return logFilenames;
  }
Exemple #2
0
  protected void setLastTaskId(int taskId) throws IOException {
    File lastTaskFile = new File(getTasksDir(), LAST_TASK_FILENAME);
    if (lastTaskFile.exists()) {
      File backupFile = new File(lastTaskFile.getParent(), lastTaskFile.getName() + ".bkp");
      FileUtil.copyFile(lastTaskFile, backupFile);
    }

    BufferedWriter writer = null;
    try {
      writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(lastTaskFile)));
      writer.write(new Integer(taskId).toString());
      writer.newLine();
    } catch (IOException e) {
      log.error("Error writing last task file", e);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }