Esempio n. 1
1
  public void writeTasks(OutputStream output) {
    try {
      output.write("[\n".getBytes());
      boolean needComma = false;
      File[] files = tasksDirectory.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
      List<Integer> numbers = new ArrayList<>();
      for (File directory : files) {
        try {
          numbers.add(Integer.valueOf(directory.getName()));
        } catch (Throwable ignored) {

        }
      }
      numbers.sort(Comparator.<Integer>reverseOrder());
      numbers = numbers.subList(0, Math.min(100, numbers.size()));
      for (int taskId : numbers) {
        File infoFile = new File(new File(tasksDirectory, String.valueOf(taskId)), "info.json");
        if (!infoFile.exists()) {
          continue;
        }
        if (needComma) {
          output.write(",\n".getBytes());
        } else {
          needComma = true;
        }
        try (FileInputStream fis = new FileInputStream(infoFile)) {
          IOUtils.copy(fis, output);
        }
      }
      output.write("]\n".getBytes());
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
  @Override
  protected boolean handleDirectory(File directory, int depth, Collection<VcmFileData> results)
      throws IOException {
    try {
      if (directory.getCanonicalPath().equals(outputRootFile.getCanonicalPath())) {
        log.debug(String.format("Ignoring %s", directory.getCanonicalPath()));
        return false;
      }

      log.info(String.format("Indexing %s", directory.getCanonicalPath()));
      String relativeParentPaths =
          StringUtils.remove(
              directory.getCanonicalPath(), new File(componentRootPath).getCanonicalPath());
      String outputPath = outputRootPath + relativeParentPaths;
      File outputDirectory = new File(outputPath);
      if (!outputDirectory.exists()) {
        if (!outputDirectory.mkdir()) {
          throw new CommandExecutionException(
              2, String.format("Could not create the %s directory", outputDirectory));
        }
      }

      VelocityContext velocityContext = new VelocityContext(velocityToolManager.createContext());
      velocityContext.put("baseURL", baseUrl);
      velocityContext.put(
          "folders",
          directory.listFiles(
              (FileFilter)
                  FileFilterUtils.and(
                      FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE)));
      velocityContext.put("parentFolders", getParentFolders(relativeParentPaths));
      List<VcmFileData> files = getFiles(directory, outputPath);
      velocityContext.put("files", files);
      if (depth == 0) {
        velocityContext.put("rootPath", ".");
      } else {
        velocityContext.put("rootPath", StringUtils.repeat("../", depth));
      }
      velocityContext.put("depth", depth);

      OutputStreamWriter writer = null;
      try {
        writer =
            new OutputStreamWriter(
                new FileOutputStream(new File(outputDirectory, "index.htm")), "UTF-8");
        velocityTemplate.merge(velocityContext, writer);
      } finally {
        IOUtils.closeQuietly(writer);
      }

      results.addAll(files);
      return true;
    } catch (ZipException e) {
      throw new CommandExecutionException(3, e);
    }
  }
Esempio n. 3
0
 public TaskPersistence() {
   try {
     tasksDirectory = new File(System.getProperty("user.home") + "/.floto/tasks");
     FileUtils.forceMkdir(tasksDirectory);
     long numberOfTasks =
         tasksDirectory.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()).length;
     nextTaskId = new AtomicLong(numberOfTasks + 1);
     objectMapper = new ObjectMapper();
     objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
     objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
     objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
     objectMapper.registerModule(new JSR310Module());
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
 /**
  * Returns a list of available, valid (contains 'valid' file) checkpoint directories, as File
  * instances, with the more recently-written appearing first.
  *
  * @return List of valid checkpoint directory File instances
  */
 @SuppressWarnings("unchecked")
 public List<File> findAvailableCheckpointDirectories() {
   File[] dirs =
       getCheckpointsDir().getFile().listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
   if (dirs == null) {
     return Collections.EMPTY_LIST;
   }
   Arrays.sort(dirs, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
   LinkedList<File> dirsList = new LinkedList<File>(Arrays.asList(dirs));
   Iterator<File> iter = dirsList.iterator();
   while (iter.hasNext()) {
     File cpDir = iter.next();
     if (!Checkpoint.hasValidStamp(cpDir)) {
       LOGGER.warning("checkpoint '" + cpDir + "' missing validity stamp file; ignoring");
       iter.remove();
     }
   }
   return dirsList;
 }
Esempio n. 5
0
  @Override
  protected final void parse() {
    for (File dir : getXMLDir()) {
      if (!dir.exists()) {
        warn("Dir " + dir.getAbsolutePath() + " not exists");
        return;
      }

      File dtd = new File(getXMLDir().get(0), getDTDFileName());
      if (!dtd.exists()) {
        info("DTD file: " + dtd.getName() + " not exists.");
        return;
      }

      initDTD(dtd);

      try {
        Collection<File> files =
            FileUtils.listFiles(
                dir,
                FileFilterUtils.suffixFileFilter(".xml"),
                FileFilterUtils.directoryFileFilter());

        for (File f : files) {
          if (!f.isHidden()) {
            if (!isIgnored(f)) {
              // if(!Config.ExcludeDataFiles.contains(f.getName()))
              // z{
              try {
                parseDocument(new FileInputStream(f), f.getName());
              } catch (Exception e) {
                info("Exception: " + e + " in file: " + f.getName(), e);
              }
              // }
            }
          }
        }
      } catch (Exception e) {
        warn("Exception: " + e, e);
      }
    }
  }
 public GenerateWebCatalogCommand() {
   super(FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE), -1);
 }