Java Code Examples for java.nio.file.Files

Following code examples demonstrate how to use java.nio.file.Filesfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.nio.file.Filesand various code implementation of this class.

    public void testInsertParam() throws IOException {
        String samplePath = "src/test/resources/insert/sample/FooParam.java";
        String srcPath = "src/test/resources/tmp/FooParam.java";
        String spoonedPath = "src/test/resources/insert/spooned/FooParam.java";
        String expectedPath = "src/test/resources/insert/expected/FooParam.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 


    public void testInsertIf() throws IOException {
        String samplePath = "src/test/resources/insert/sample/FooIf.java";
        String srcPath = "src/test/resources/tmp/FooIf.java";
        String spoonedPath = "src/test/resources/insert/spooned/FooIf.java";
        String expectedPath = "src/test/resources/insert/expected/FooIf.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testInsertMethodCall() throws IOException {
        String samplePath = "src/test/resources/insert/sample/FooMethodCall.java";
        String srcPath = "src/test/resources/tmp/FooMethodCall.java";
        String spoonedPath = "src/test/resources/insert/spooned/FooMethodCall.java";
        String expectedPath = "src/test/resources/insert/expected/FooMethodCall.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testInsertMethod() throws IOException {
        String samplePath = "src/test/resources/insert/sample/FooMethod.java";
        String srcPath = "src/test/resources/tmp/FooMethod.java";
        String spoonedPath = "src/test/resources/insert/spooned/FooMethod.java";
        String expectedPath = "src/test/resources/insert/expected/FooMethod.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testInsertField() throws IOException {
        String samplePath = "src/test/resources/insert/sample/FooField.java";
        String srcPath = "src/test/resources/tmp/FooField.java";
        String spoonedPath = "src/test/resources/insert/spooned/FooField.java";
        String expectedPath = "src/test/resources/insert/expected/FooField.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

  }

  public <A extends BasicFileAttributes> A readAttributes(
      Path pathRelativeToProjectRoot,
      Class<A> type,
      LinkOption... options)
    throws IOException {
    return java.nio.file.Files.readAttributes(
        getPathForRelativePath(pathRelativeToProjectRoot), type, options);
  } 

  public InputStream getInputStreamForRelativePath(Path path) throws IOException {
    Path file = getPathForRelativePath(path);
    return java.nio.file.Files.newInputStream(file);
  } 

  public boolean isFile(Path pathRelativeToProjectRoot) {
    return java.nio.file.Files.isRegularFile(
        getPathForRelativePath(pathRelativeToProjectRoot));
  } 

  public List<String> readLines(Path pathRelativeToProjectRoot) throws IOException {
    Path file = getPathForRelativePath(pathRelativeToProjectRoot);
    return java.nio.file.Files.readAllLines(file, Charsets.UTF_8);
  } 

  public long getLastModifiedTime(Path pathRelativeToProjectRoot) throws IOException {
    Path path = getPathForRelativePath(pathRelativeToProjectRoot);
    return java.nio.file.Files.getLastModifiedTime(path).toMillis();
  } 

  public boolean deleteFileAtPath(Path pathRelativeToProjectRoot) {
    try {
      java.nio.file.Files.delete(getPathForRelativePath(pathRelativeToProjectRoot));
      return true;
    } catch (IOException e) {
      return false;
    }
  } 

  }

  public Properties readPropertiesFile(Path pathToPropertiesFileRelativeToProjectRoot)
      throws IOException {
    Properties properties = new Properties();
    Path propertiesFile = getPathForRelativePath(pathToPropertiesFileRelativeToProjectRoot);
    if (java.nio.file.Files.exists(propertiesFile)) {
      properties.load(java.nio.file.Files.newBufferedReader(propertiesFile, Charsets.UTF_8));
      return properties;
    } else {
      throw new FileNotFoundException(propertiesFile.toString());
    }
  } 

  private Optional<String> readFileIfItExists(Path fileToRead, String pathRelativeToProjectRoot) {
    if (java.nio.file.Files.isRegularFile(fileToRead)) {
      String contents;
      try {
        contents = new String(java.nio.file.Files.readAllBytes(fileToRead), Charsets.UTF_8);
      } catch (IOException e) {
        throw new RuntimeException("Error reading " + pathRelativeToProjectRoot, e);
      }
      return Optional.of(contents);
    } else {
      return Optional.absent();
    }
  } 

  public void move(Path source, Path target, CopyOption... options) throws IOException {
    java.nio.file.Files.move(resolve(source), resolve(target), options);

  } 

  public ProjectFilesystem(Path projectRoot, ImmutableSet<Path> ignorePaths) {
    Preconditions.checkArgument(java.nio.file.Files.isDirectory(projectRoot));
    this.projectRoot = projectRoot;
    this.pathAbsolutifier = new Function<Path, Path>() {
      @Override
      public Path apply(Path path) {
        return resolve(path);
      }
    };
    this.ignorePaths = MorePaths.filterForSubpaths(ignorePaths, this.projectRoot);
    this.ignoreValidityOfPaths = false;
  } 

  }

  private void walkRelativeFileTree(
      Path pathRelativeToProjectRoot,
      EnumSet<FileVisitOption> visitOptions,
      final FileVisitor<Path> fileVisitor) throws IOException {
    Path rootPath = getPathForRelativePath(pathRelativeToProjectRoot);
    java.nio.file.Files.walkFileTree(
        rootPath,
        visitOptions,
        Integer.MAX_VALUE,
        new FileVisitor<Path>() {
          @Override
          public FileVisitResult preVisitDirectory(
              Path dir, BasicFileAttributes attrs) throws IOException {
            return fileVisitor.preVisitDirectory(projectRoot.relativize(dir), attrs);
          }

          @Override
          public FileVisitResult visitFile(
              Path file, BasicFileAttributes attrs) throws IOException {
            return fileVisitor.visitFile(projectRoot.relativize(file), attrs);
          }

          @Override
          public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            return fileVisitor.visitFileFailed(projectRoot.relativize(file), exc);
          }

          @Override
          public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return fileVisitor.postVisitDirectory(projectRoot.relativize(dir), exc);
          }
        });
  } 

  public long getFileSize(Path pathRelativeToProjectRoot) throws IOException {
    Path path = getPathForRelativePath(pathRelativeToProjectRoot);
    if (!java.nio.file.Files.isRegularFile(path)) {
      throw new IOException("Cannot get size of " + path + " because it is not an ordinary file.");
    }
    return java.nio.file.Files.size(path);
  } 

  public String computeSha1(Path pathRelativeToProjectRoot) throws IOException {
    Path fileToHash = getPathForRelativePath(pathRelativeToProjectRoot);
    return Hashing.sha1().hashBytes(java.nio.file.Files.readAllBytes(fileToHash)).toString();
  } 

  
  public void copyToPath(
      InputStream inputStream,
      Path pathRelativeToProjectRoot,
      CopyOption... options)
      throws IOException {
    java.nio.file.Files.copy(inputStream, getPathForRelativePath(pathRelativeToProjectRoot),
        options);
  } 

    switch (sourceMode) {
      case FILE:
        java.nio.file.Files.copy(
            resolve(source),
            resolve(target),
            StandardCopyOption.REPLACE_EXISTING);
        break;
      case DIRECTORY_CONTENTS_ONLY:
        MoreFiles.copyRecursively(resolve(source), resolve(target));
        break;
      case DIRECTORY_AND_CONTENTS:
        MoreFiles.copyRecursively(resolve(source), resolve(target.resolve(source.getFileName())));
        break;
    } 

  public Collection<Path> getDirectoryContents(Path pathRelativeToProjectRoot) {
    Path path = getPathForRelativePath(pathRelativeToProjectRoot);
    try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(path)) {
      return ImmutableList.copyOf(stream);
    } catch (IOException e) {
      return null;
    }
  } 

  public Optional<String> readFirstLineFromFile(Path file) {
    try {
      return Optional.fromNullable(
          java.nio.file.Files.newBufferedReader(file, Charsets.UTF_8).readLine());
    } catch (IOException e) {
      return Optional.absent();
    }
  } 

  public Optional<Reader> getReaderIfFileExists(Path pathRelativeToProjectRoot) {
    Path fileToRead = getPathForRelativePath(pathRelativeToProjectRoot);
    if (java.nio.file.Files.isRegularFile(fileToRead)) {
      try {
        return Optional.of(
            (Reader) new BufferedReader(
                new InputStreamReader(newFileInputStream(pathRelativeToProjectRoot))));
      } catch (Exception e) {
        throw new RuntimeException("Error reading " + pathRelativeToProjectRoot, e);
      }
    } else {
      return Optional.absent();
    }
  } 

  public void createZip(Iterable<Path> pathsToIncludeInZip, File out) throws IOException {
    Preconditions.checkState(!Iterables.isEmpty(pathsToIncludeInZip));
    try (CustomZipOutputStream zip = ZipOutputStreams.newOutputStream(out)) {
      for (Path path : pathsToIncludeInZip) {
        CustomZipEntry entry = new CustomZipEntry(path.toString());

        Path full = getPathForRelativePath(path);
        File file = full.toFile();
        if (file.canExecute()) {
          entry.setExternalAttributes(MorePosixFilePermissions.toMode(
              EnumSet.of(PosixFilePermission.OWNER_EXECUTE)) << 16);
        }

        zip.putNextEntry(entry);
        try (InputStream input = java.nio.file.Files.newInputStream(getPathForRelativePath(path))) {
          ByteStreams.copy(input, zip);
        }
        zip.closeEntry();
      }
    }
  } 

  }

  public InputStream newFileInputStream(Path pathRelativeToProjectRoot)
    throws IOException {
    return new BufferedInputStream(
        java.nio.file.Files.newInputStream(getPathForRelativePath(pathRelativeToProjectRoot)));
  } 

  }

  public OutputStream newFileOutputStream(
      Path pathRelativeToProjectRoot,
      FileAttribute<?>... attrs)
    throws IOException {
    return new BufferedOutputStream(
        Channels.newOutputStream(
            java.nio.file.Files.newByteChannel(
                getPathForRelativePath(pathRelativeToProjectRoot),
                ImmutableSet.<OpenOption>of(
                    StandardOpenOption.CREATE,
                    StandardOpenOption.TRUNCATE_EXISTING,
                    StandardOpenOption.WRITE),
                attrs)));
  } 

    private void processPaperFolder(Path paperFolder) throws IOException {
        try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(paperFolder, new WorkFolderFilter())) {
            for (Path workFolder : stream) {
                processWorkFolder(workFolder);
            }
        }
    } 

    public void releaseJob(String paperCode) throws IOException {
        Path workFolder = rootFolder.
                resolve(paperCode.substring(0, 3)).
                resolve(paperCode).
                resolve("work");
        String version = findNextVersion(paperCode);
        LOGGER.log(Level.INFO, "{0}", workFolder.getParent().resolve(version));
        java.nio.file.Files.move(workFolder, workFolder.getParent().resolve(version));
    } 

    private void copyFromBase(Job job, Path target) throws IOException {
        Path baseFolder = rootFolder.
                resolve(job.getBaseJob().substring(0, 3)).
                resolve(job.getBaseJob()).
                resolve(job.getBaseVersion());
        if (java.nio.file.Files.exists(baseFolder)) {
            try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(baseFolder, new GraphicsFileFilter())) {
                for (Path source : stream) {
                    String fileName = job.renameFile(source.getFileName().toString());
                    java.nio.file.Files.copy(source, target.resolve(fileName));
                }
            }
        }
    } 

    public List<String> findVersions(String paperCode) throws IOException {
        List<String> versions = new ArrayList<>();
        Path paperCodeFolder = rootFolder.
                resolve(paperCode.substring(0, 3)).
                resolve(paperCode);
        try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(paperCodeFolder, new VersionFolderFilter())) {
            for (Path versionFolder : stream) {
                versions.add(versionFolder.getFileName().toString());
            }
        }
        Collections.sort(versions);
        return versions;
    } 

    private void processWorkFolder(Path workFolder) throws IOException {
        Path jobFile = workFolder.resolve("job.properties");
        if (java.nio.file.Files.exists(jobFile)) {
            Properties p = new Properties();
            p.load(new FileInputStream(jobFile.toFile()));
            Job job = new Job(p);
            job.setPaperCode(workFolder.getParent().getFileName().toString());
            jobs.add(job);
        }
    } 

    public List<Job> getJobs() throws IOException {
        jobs.clear();
        try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(rootFolder, new CustomerFolderFilter())) {
            for (Path customerFolder : stream) {
                processCustomerFolder(customerFolder);
            }
        }
        Collections.sort(jobs, (o1, o2) -> {
            return o1.getPaperCode().compareTo(o2.getPaperCode());
        });
        return jobs;
    } 

    private String findLastVersion(String paperCode) throws IOException {
        Path paperCodeFolder = rootFolder.resolve(paperCode.substring(0, 3)).resolve(paperCode);
        List<String> versions = new ArrayList<>();
        try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(paperCodeFolder, new VersionFolderFilter())) {
            for (Path versionFolder : stream) {
                versions.add(versionFolder.getFileName().toString());
            }
        }
        Collections.sort(versions);
        return versions.isEmpty() ? "v_00" : versions.get(versions.size() - 1);
    } 

    private void processCustomerFolder(Path customerFolder) throws IOException {
        try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(customerFolder, new PaperCodeFolderFilter())) {
            for (Path paperFolder : stream) {
                processPaperFolder(paperFolder);
            }
        }
    } 

    public void createWorkFolder(Job job) throws Exception {
        Path workFolder = rootFolder.
                resolve(job.getCustomerCode()).
                resolve(job.getPaperCode()).
                resolve("work");
        if (java.nio.file.Files.exists(workFolder)) {
            throw new FileAlreadyExistsException(workFolder.toString());
        }
        java.nio.file.Files.createDirectories(workFolder);
        java.nio.file.Files.createDirectory(workFolder.resolve("inbox"));
        java.nio.file.Files.createDirectory(workFolder.resolve("outbox"));
        java.nio.file.Files.createDirectory(workFolder.resolve("press"));
        job.setStatusCode("dev");
        storeJobProperties(job.getPaperCode(), job.getUserName(), job.getStatusCode());
        normalizeBaseJob(job);
        copyFromBase(job, workFolder);
    } 

    private void copyCSSFiles() throws IOException{
        Path FROM;
        Path TO;
        CopyOption[] options = new CopyOption[]{
                StandardCopyOption.REPLACE_EXISTING,
                StandardCopyOption.COPY_ATTRIBUTES
        };

        FROM = Paths.get(COLOR_ONE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "ColorOneCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(COLOR_TWO);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "ColorTwoCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(COLOR_THREE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "ColorThreeCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(COLOR_FOUR);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "ColorFourCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(COLOR_FIVE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "ColorFiveCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(LAYOUT_ONE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "LayoutOneCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(LAYOUT_TWO);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "LayoutTwoCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(LAYOUT_THREE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "LayoutThreeCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(LAYOUT_FOUR);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "LayoutFourCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(LAYOUT_FIVE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "LayoutFiveCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(FONT_ONE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "FontOneCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(FONT_TWO);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "FontTwoCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(FONT_THREE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "FontThreeCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(FONT_FOUR);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "FontFourCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(FONT_FIVE);
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/css/" + "FontFiveCSS.css");
        java.nio.file.Files.copy(FROM, TO, options);
    } 

    public void copyImageFiles() throws IOException{
        Path FROM;
        Path TO;
        CopyOption[] options = new CopyOption[]{
                StandardCopyOption.REPLACE_EXISTING,
                StandardCopyOption.COPY_ATTRIBUTES
        };
        for(Page page: model.getPages()){
            for(Component component: page.getAllComponents()){
                if(component instanceof ImageComponent){
                    FROM = Paths.get(((ImageComponent) component).getImagePath() + ((ImageComponent) component).getImageName());
                    TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/" + ((ImageComponent) component).getImageName());
                    java.nio.file.Files.copy(FROM, TO, options);
                }

                if(component instanceof VideoComponent){
                    FROM = Paths.get(((VideoComponent) component).getVideoPath() + ((VideoComponent) component).getVideoName());
                    TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/" + ((VideoComponent) component).getVideoName());
                    java.nio.file.Files.copy(FROM, TO, options);
                }

                if(component instanceof SlideShowComponent){
                    for(ImageComponent imageComponent: ((SlideShowComponent) component).getImageSlides()){
                        FROM = Paths.get(imageComponent.getImagePath() + imageComponent.getImageName());
                        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/" + imageComponent.getImageName());
                        java.nio.file.Files.copy(FROM, TO, options);
                    }
                }
            }

            if(!page.getBannerImageName().equalsIgnoreCase("DefaultStartSlide.png") && page.getBannerImageName() != null && !page.getBannerImageName().equalsIgnoreCase("")){
                FROM = Paths.get(page.getBannerImagePath() + page.getBannerImageName());
                TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/" + page.getBannerImageName());
                java.nio.file.Files.copy(FROM, TO, options);
            }
        }

        FROM = Paths.get(IMAGES_PATH + "Play.png");
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/Play.png");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(IMAGES_PATH + "Pause.png");
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/Pause.png");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(IMAGES_PATH + "Next.png");
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/Next.png");
        java.nio.file.Files.copy(FROM, TO, options);

        FROM = Paths.get(IMAGES_PATH + "Previous.png");
        TO = Paths.get(SITES_PATH + model.getePortfolioTitle() + "/img/Previous.png");
        java.nio.file.Files.copy(FROM, TO, options);

        try {
            copyCSSFiles();
        }catch(IOException ex){
            System.out.println("Exception thrown when copying the skeleton files for css.");
        }
    } 

    public void createDirectories(){
        Path path = Paths.get(SITES_PATH + model.getePortfolioTitle());
        if(Files.exists(path)){
            deleteFile(new File(SITES_PATH + model.getePortfolioTitle()));
        }


        File directory = new File(SITES_PATH + model.getePortfolioTitle());
        directory.mkdir();

        directory = new File(SITES_PATH + model.getePortfolioTitle() + "/css");
        directory.mkdir();

        directory = new File(SITES_PATH + model.getePortfolioTitle() + "/js");
        directory.mkdir();

        directory = new File(SITES_PATH + model.getePortfolioTitle() + "/img");
        directory.mkdir();
    } 

    private void createFileIfNotExist(Path path) {
        if (exists(path)) {
            return;
        }
        try {
            Files.createFile(path);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    } 

    public void firstTest() throws IOException {

        String input = "";
        try (Stream<String> linesIn = java.nio.file.Files.lines(Paths.get("input/input00.txt"))) {
            input = linesIn.collect(Collectors.joining("\n"));
        }
        String expected = "";
        try (Stream<String> linesOut = java.nio.file.Files.lines(Paths.get("output/output00.txt"))) {
            expected= linesOut.collect(Collectors.joining("\n"));
        }

        systemInMock.provideLines(input);

        Solution.main(new String[] {});

        assertThat(stdOutLog.getLog(), is(expected + "\n"));
    } 

    public void fithTest() throws IOException {

        String input = "";
        try (Stream<String> linesIn = java.nio.file.Files.lines(Paths.get("input/input03.txt"))) {
            input = linesIn.collect(Collectors.joining("\n"));
        }
        String expected = "";
        try (Stream<String> linesOut = java.nio.file.Files.lines(Paths.get("output/output03.txt"))) {
            expected= linesOut.collect(Collectors.joining("\n"));
        }

        systemInMock.provideLines(input);

        Solution.main(new String[] {});

        assertThat(stdOutLog.getLog(), is(expected + "\n"));
    } 

    public void secondTest() throws IOException {

        String input = "";
        try (Stream<String> linesIn = java.nio.file.Files.lines(Paths.get("input/input01.txt"))) {
            input = linesIn.collect(Collectors.joining("\n"));
        }
        String expected = "";
        try (Stream<String> linesOut = java.nio.file.Files.lines(Paths.get("output/output01.txt"))) {
            expected= linesOut.collect(Collectors.joining("\n"));
        }

        systemInMock.provideLines(input);

        Solution.main(new String[] {});

        assertThat(stdOutLog.getLog(), is(expected + "\n"));
    } 

    public void thirdTest() throws IOException {

        String input = "";
        try (Stream<String> linesIn = java.nio.file.Files.lines(Paths.get("input/input02.txt"))) {
            input = linesIn.collect(Collectors.joining("\n"));
        }
        String expected = "";
        try (Stream<String> linesOut = java.nio.file.Files.lines(Paths.get("output/output02.txt"))) {
            expected= linesOut.collect(Collectors.joining("\n"));
        }

        systemInMock.provideLines(input);

        Solution.main(new String[] {});

        assertThat(stdOutLog.getLog(), is(expected + "\n"));
    } 

    public void deleteIfExistsQuietly_doesExist() throws IOException {
        final Path path = root.resolve("blah");
        SafeFiles.writeUTF8("hello world", path);
        Assert.assertTrue(java.nio.file.Files.exists(path));

        SafeFiles.deleteIfExistsQuietly(path);
        Assert.assertFalse(java.nio.file.Files.exists(path));
    } 

    public void write_direct_ok() throws IOException {
        final Path path = root.resolve("foo.bin");

        final byte[] wrote = "hello world".getBytes(Charsets.UTF_8);

        SafeFiles.write(wrote, path);
        checkFilePermissions(path);

        final byte[] read = com.google.common.io.Files.toByteArray(path.toFile());

        Assert.assertArrayEquals(wrote, read);

        Assert.assertEquals("no stray files", 1, Directories.count(root));
    } 

    public void write_asWritableByteChannel_fail() throws IOException {
        final Path path = root.resolve("foo.bin");

        final byte[] wrote = "hello world".getBytes(Charsets.UTF_8);

        try {
            try (final SafeOutputStream out = SafeFiles.createAtomicFile(path)) {
                out.write(ByteBuffer.wrap(wrote));
                throw new IOException("failed after write!");
            }
        } catch (IOException e) {
        }

        Assert.assertFalse(java.nio.file.Files.exists(path));

        Assert.assertEquals("no stray files", 0, Directories.count(root));
    } 

    public void ensureDirectoryExists() throws IOException {
        final Path path = root.resolve("dir");

        Assert.assertFalse(java.nio.file.Files.exists(path));

        SafeFiles.ensureDirectoryExists(path);
        Assert.assertTrue(java.nio.file.Files.exists(path));

        SafeFiles.ensureDirectoryExists(path);
        Assert.assertTrue(java.nio.file.Files.exists(path));
    } 

    public void write_asOutputStream_fail() throws IOException {
        final Path path = root.resolve("foo.bin");

        final byte[] wrote = "hello world".getBytes(Charsets.UTF_8);

        try {
            try (final SafeOutputStream out = SafeFiles.createAtomicFile(path)) {
                out.write(wrote);
                throw new IOException("failed after write!");
            }
        } catch (IOException e) {
        }

        Assert.assertFalse(java.nio.file.Files.exists(path));

        Assert.assertEquals("no stray files", 0, Directories.count(root));
    } 

    private static void checkFilePermissions(Path path) {
        try {
            final Path tempFile = java.nio.file.Files.createTempFile("tmp", "tmp", PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx")));
            final Set<PosixFilePermission> inverseUmask;
            try {
                inverseUmask = Files.getPosixFilePermissions(tempFile);
            } finally {
                java.nio.file.Files.delete(tempFile);
            }

            final Set<PosixFilePermission> posixFilePermissions = java.nio.file.Files.getPosixFilePermissions(path);
            if (inverseUmask.contains(PosixFilePermission.OWNER_READ)) {
                Assert.assertTrue("owner read permission not set", posixFilePermissions.contains(PosixFilePermission.OWNER_READ));
            }
            if (inverseUmask.contains(PosixFilePermission.OWNER_WRITE)) {
                Assert.assertTrue("owner write permission not set", posixFilePermissions.contains(PosixFilePermission.OWNER_WRITE));
            }
            if (inverseUmask.contains(PosixFilePermission.GROUP_READ)) {
                Assert.assertTrue("group read permission not set", posixFilePermissions.contains(PosixFilePermission.GROUP_READ));
            }
            if (inverseUmask.contains(PosixFilePermission.OTHERS_READ)) {
                Assert.assertTrue("other read permission not set", posixFilePermissions.contains(PosixFilePermission.OTHERS_READ));
            }
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    } 

    public void write_viaSafeFile_asOutputStream_rollback() throws IOException {
        final Path path = root.resolve("foo.bin");

        final byte[] wrote = "hello world".getBytes(Charsets.UTF_8);

        try (final SafeOutputStream out = SafeFiles.createAtomicFile(path)) {
            out.write(wrote);
            out.flush();
        }

        Assert.assertFalse(java.nio.file.Files.exists(path));

        Assert.assertEquals("no stray files", 0, Directories.count(root));
    } 

    public void write_viaSafeFile_asOutputStream() throws IOException {
        final Path path = root.resolve("foo.bin");

        final byte[] wrote = "hello world".getBytes(Charsets.UTF_8);

        try (final SafeOutputStream out = SafeFiles.createAtomicFile(path)) {
            out.write(wrote);
            out.flush();
            out.commit();
        }
        checkFilePermissions(path);

        final byte[] read = com.google.common.io.Files.toByteArray(path.toFile());

        Assert.assertArrayEquals(wrote, read);

        Assert.assertEquals("no stray files", 1, Directories.count(root));
    } 

    public void rename_diffDir() throws IOException {
        final byte[] data = "hello world".getBytes(Charsets.UTF_8);

        final Path dir1 = root.resolve("dir1");
        final Path dir2 = root.resolve("dir2");

        SafeFiles.ensureDirectoryExists(dir1);
        SafeFiles.ensureDirectoryExists(dir2);

        final Path origPath = dir1.resolve("orig.txt");
        final Path newPath = dir2.resolve("new.txt");
        SafeFiles.write(data, origPath);
        checkFilePermissions(origPath);

        Assert.assertTrue(java.nio.file.Files.exists(origPath));
        Assert.assertFalse(java.nio.file.Files.exists(newPath));
        Assert.assertEquals("no stray files", 1, Directories.count(dir1));
        Assert.assertEquals("no stray files", 0, Directories.count(dir2));

        SafeFiles.rename(origPath, newPath);

        Assert.assertFalse(java.nio.file.Files.exists(origPath));
        Assert.assertTrue(java.nio.file.Files.exists(newPath));
        Assert.assertEquals("no stray files", 0, Directories.count(dir1));
        Assert.assertEquals("no stray files", 1, Directories.count(dir2));
    } 

    public void fsyncRecursive() throws IOException {
        Assert.assertEquals(0, Directories.count(root));

        tempDir.newFile("foo1");
        tempDir.newFile("foo2");
        final File dir = tempDir.newFolder("dir");

        new File(dir, "bar1").createNewFile();
        new File(dir, "bar2").createNewFile();
        new File(dir, "bar3").createNewFile();

        final File dir2 = new File(dir, "sub");
        dir2.mkdir();

        new File(dir2, "baz").createNewFile();

        Assert.assertEquals(2 + 3 + 1, SafeFiles.fsyncRecursive(root));
    } 

    public void rename_sameDir() throws IOException {
        final byte[] data = "hello world".getBytes(Charsets.UTF_8);

        final Path origPath = root.resolve("orig.txt");
        final Path newPath = root.resolve("new.txt");
        SafeFiles.write(data, origPath);
        checkFilePermissions(origPath);

        Assert.assertTrue(java.nio.file.Files.exists(origPath));
        Assert.assertFalse(java.nio.file.Files.exists(newPath));
        Assert.assertEquals("no stray files", 1, Directories.count(root));

        SafeFiles.rename(origPath, newPath);

        Assert.assertFalse(java.nio.file.Files.exists(origPath));
        Assert.assertTrue(java.nio.file.Files.exists(newPath));
        Assert.assertEquals("no stray files", 1, Directories.count(root));
    } 

    public void deleteIfExistsQuietly_doesNotExist() {
        final Path path = root.resolve("blah");
        Assert.assertFalse(java.nio.file.Files.exists(path));
        SafeFiles.deleteIfExistsQuietly(path);
        Assert.assertFalse(java.nio.file.Files.exists(path));
    } 

    public void testUpdateIf() throws IOException {
        String samplePath = "src/test/resources/update/sample/FooIf.java";
        String srcPath = "src/test/resources/tmp/FooIf.java";
        String spoonedPath = "src/test/resources/update/spooned/FooIf.java";
        String expectedPath = "src/test/resources/update/expected/FooIf.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testUpdateMethodCall() throws IOException {
        String samplePath = "src/test/resources/update/sample/FooMethodCall.java";
        String srcPath = "src/test/resources/tmp/FooMethodCall.java";
        String spoonedPath = "src/test/resources/update/spooned/FooMethodCall.java";
        String expectedPath = "src/test/resources/update/expected/FooMethodCall.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testInsertParam() throws IOException {
        String samplePath = "src/test/resources/update/sample/FooParam.java";
        String srcPath = "src/test/resources/tmp/FooParam.java";
        String spoonedPath = "src/test/resources/update/spooned/FooParam.java";
        String expectedPath = "src/test/resources/update/expected/FooParam.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));


        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testUpdateMethod() throws IOException {
        String samplePath = "src/test/resources/update/sample/FooMethod.java";
        String srcPath = "src/test/resources/tmp/FooMethod.java";
        String spoonedPath = "src/test/resources/update/spooned/FooMethod.java";
        String expectedPath = "src/test/resources/update/expected/FooMethod.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testUpdateField() throws IOException {
        String samplePath = "src/test/resources/update/sample/FooField.java";
        String srcPath = "src/test/resources/tmp/FooField.java";
        String spoonedPath = "src/test/resources/update/spooned/FooField.java";
        String expectedPath = "src/test/resources/update/expected/FooField.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

	public void setInput(stepwat.input.ST.MortFlags mortFlags) throws IOException {
		this.summary = mortFlags.sumry;
		this.yearly = mortFlags.yearly;
		this.header = mortFlags.header;
		this.group = mortFlags.group;
		this.species = mortFlags.species;
		sep = mortFlags.sep;
		if(mortFlags.sep.compareTo("t") == 0)
			sep = "\t";
		if(mortFlags.sep.compareTo("s") == 0)
			sep = " ";
		if(!(this.summary || this.yearly)) {
			this.header = this.group = this.species = false;
		}
		
		Path mortavg = Paths.get(globals.prjDir, globals.files[Globals.F_MortAvg]);
		if(java.nio.file.Files.exists(mortavg.getParent())) {
			if(java.nio.file.Files.exists(mortavg))
				java.nio.file.Files.delete(mortavg);
		} else {
			java.nio.file.Files.createDirectories(mortavg.getParent());
			java.nio.file.Files.createFile(mortavg);
		}
		
		Path mortpre = Paths.get(globals.prjDir, globals.files[Globals.F_MortPre]);
		if(java.nio.file.Files.exists(mortpre.getParent())) {
			try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(mortpre.getParent(),
					mortpre.getFileName()+"*.{out}")) {
				for (Path entry : stream) {
					java.nio.file.Files.delete(entry);
				}
			} catch (DirectoryIteratorException ex) {
				throw ex.getCause();
			}
		} else {
			java.nio.file.Files.createDirectories(mortpre.getParent());
		} 

    public void testDeleteMethodCall() throws IOException {
        String samplePath = "src/test/resources/delete/sample/FooMethodCall.java";
        String srcPath = "src/test/resources/tmp/FooMethodCall.java";
        String spoonedPath = "src/test/resources/delete/spooned/FooMethodCall.java";
        String expectedPath = "src/test/resources/delete/expected/FooMethodCall.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testDeleteParam() throws IOException {
        String samplePath = "src/test/resources/delete/sample/FooParam.java";
        String srcPath = "src/test/resources/tmp/FooParam.java";
        String spoonedPath = "src/test/resources/delete/spooned/FooParam.java";
        String expectedPath = "src/test/resources/delete/expected/FooParam.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testDeleteIf() throws IOException {
        String samplePath = "src/test/resources/delete/sample/FooIf.java";
        String srcPath = "src/test/resources/tmp/FooIf.java";
        String spoonedPath = "src/test/resources/delete/spooned/FooIf.java";
        String expectedPath = "src/test/resources/delete/expected/FooIf.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testDeleteField() throws IOException {
        String samplePath = "src/test/resources/delete/sample/FooField.java";
        String srcPath = "src/test/resources/tmp/FooField.java";
        String spoonedPath = "src/test/resources/delete/spooned/FooField.java";
        String expectedPath = "src/test/resources/delete/expected/FooField.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

    public void testDeleteMethod() throws IOException {
        String samplePath = "src/test/resources/delete/sample/FooMethod.java";
        String srcPath = "src/test/resources/tmp/FooMethod.java";
        String spoonedPath = "src/test/resources/delete/spooned/FooMethod.java";
        String expectedPath = "src/test/resources/delete/expected/FooMethod.java";

        File tmp = new File(srcPath);
        Files.copy(new File(samplePath), tmp);

        SniperSpoon sniperSpoon = new SniperSpoon();
        sniperSpoon.compareFiles(srcPath, spoonedPath);

        String contentExpected = new String(java.nio.file.Files.readAllBytes(Paths.get(expectedPath)));
        String contentSniped = new String(java.nio.file.Files.readAllBytes(Paths.get(srcPath)));

        tmp.delete();

        assertEquals("should be the same", contentExpected, contentSniped);
    } 

	public void setInput(stepwat.input.ST.BmassFlags bmassFlags) throws IOException {
		this.summary = bmassFlags.sumry;
		this.yearly = bmassFlags.yearly;
		this.header = bmassFlags.header;
		this.yr = bmassFlags.yrnum;
		this.dist = bmassFlags.disturb;
		this.ppt = bmassFlags.ppt;
		this.pclass = bmassFlags.pclass;
		this.tmp = bmassFlags.temp;
		this.grpb = bmassFlags.grpBmass;
		this.pr = bmassFlags.grpPR;
		this.size = bmassFlags.grpSize;
		this.sppb = bmassFlags.sppBmass;
		this.indv = bmassFlags.indivs;
		sep = bmassFlags.sep;
		if(bmassFlags.sep.compareTo("t") == 0)
			sep = "\t";
		if(bmassFlags.sep.compareTo("s") == 0)
			sep = " ";
		
		Path bmassavg = Paths.get(globals.prjDir, globals.files[Globals.F_BMassAvg]);
		if(java.nio.file.Files.exists(bmassavg.getParent())) {
			if(java.nio.file.Files.exists(bmassavg))
				java.nio.file.Files.delete(bmassavg);
		} else {
			java.nio.file.Files.createDirectories(bmassavg.getParent());
			java.nio.file.Files.createFile(bmassavg);
		}
		
		Path bmasspre = Paths.get(globals.prjDir, globals.files[Globals.F_BMassPre]);
		if(java.nio.file.Files.exists(bmasspre.getParent())) {
			try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(bmasspre.getParent(),
					bmasspre.getFileName()+"*.{out}")) {
				for (Path entry : stream) {
					java.nio.file.Files.delete(entry);
				}
			} catch (DirectoryIteratorException ex) {
				throw ex.getCause();
			}
		} else {
			java.nio.file.Files.createDirectories(bmasspre.getParent());
		} 

    public boolean checkForIndices(String whichone) {
        boolean out = false;
        if (whichone.equals("CircularMapper")) {
            Path path = Paths.get(this.c.getGUI_reference());

            if (java.nio.file.Files.exists(path)) {
                String output_path = new File(this.c.getGUI_reference()).getParent();
                String extension = Files.getFileExtension(this.c.getGUI_reference());
                String output_stem = Files.getNameWithoutExtension(this.c.getGUI_reference());
                Path path2 = Paths.get(output_path + "/" + output_stem + "_" +this.c.getCM_elongationfac()+"."+extension + ".ann");
                System.out.println("Checking for file at path: " + path2 + "\n");
                if(java.nio.file.Files.notExists(path2)) {
                    out = true;
                }
            }
        }

        if (whichone.equals("CircGenerator")) {
            Path path = Paths.get(this.c.getGUI_reference());

            if (java.nio.file.Files.exists(path)) {
                String extension = Files.getFileExtension(this.c.getGUI_reference());
                String filename = Files.getNameWithoutExtension(this.c.getGUI_reference());
                Path path2 = Paths.get(filename + "_" + this.c.getCM_elongationfac() + "." + extension );
                System.out.println("Checking for file at path: " + path2 + "\n");
                if(java.nio.file.Files.notExists(path2)) {
                    out = true;
                }
            }
        }

        if (whichone.equals("whole")) {
            Path path = Paths.get(this.c.getGUI_reference() + ".ann");
            if (java.nio.file.Files.notExists(path)) {
                out = true;
            }
        }


        if (whichone.equals("SeqDict")) {
            Path path = Paths.get(this.c.getGUI_reference());
            if (java.nio.file.Files.exists(path)) {
                File f = new File(this.c.getGUI_reference());
                String absolutPath = f.getAbsolutePath();
                String filepath = absolutPath.substring(0, absolutPath.lastIndexOf(File.separator));
                Path path2 = Paths.get(filepath + "/" + Files.getNameWithoutExtension(absolutPath) + ".dict");
                System.out.println("Checking for file at path: " + path2 + "\n");
                if (java.nio.file.Files.notExists(path2)) {
                    out = true;
                }
            }


        }

        if (whichone.equals("faidx")) {
            Path path = Paths.get(this.c.getGUI_reference() + ".fai");
            if (java.nio.file.Files.notExists(path)) {
                out = true;
            }
        }

        if(whichone.equals("samindex")){
            Path path = Paths.get(this.c.getGUI_inputfiles().get(0) + ".bai");
            if(java.nio.file.Files.notExists(path)){
                out = true;
            }
        }

        if (whichone.equals("Stampy")) {
            Path indexpath = Paths.get(this.c.getGUI_reference() + ".stidx");
            Path hashpath = Paths.get(this.c.getGUI_reference() + ".sthash");
            if (java.nio.file.Files.notExists(indexpath) && java.nio.file.Files.notExists(hashpath)) {
                out = true;
            }
        }

        if (whichone.equals("BT2")) {
            Path path = Paths.get(this.c.getGUI_reference() + ".1.bt2");
            if (java.nio.file.Files.notExists(path)) {
                out = true;
            }
        }


        return out;
    } 

    public void move(Path source, Path target) throws IOException {
        source = path(source);
        if (java.nio.file.Files.exists(source)) {
            java.nio.file.Files.move(source, path(target), REPLACE_EXISTING);
        } else {
            delete(target);
        }
    } 

    public ByteSink put(Path path) throws IOException {
        File file = file(path);
        if (!file.getParentFile().isDirectory() && !file.getParentFile().mkdirs()) {
            throw new IOException("Cannot create parent directory");
        }
        return Files.asByteSink(file);
    } 

    public void write(Path path, String content) {

        path = path(path);

        {
            File parent = path.getParent().toFile();
            if (!parent.isDirectory() && !parent.mkdirs()) {
                throw new RuntimeException("Failed to create directory at " + parent.getPath());
            }
        }

        try {
            java.nio.file.Files.write(path, content.getBytes(charset));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    } 

    public String read(Path path) {

        path = path(path);

        if (!java.nio.file.Files.exists(path)) {
            return null;
        }

        try {
            return new String(java.nio.file.Files.readAllBytes(path), charset);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    } 

    public void delete(Path path) throws IOException {
        if (path.toFile().isDirectory()) {
            FileUtils.deleteDirectory(path(path).toFile());
        } else {
            java.nio.file.Files.deleteIfExists(path);
        }
    } 

Advertisement
Javadoc
This class consists exclusively of static methods that operate on files, directories, or other types

of files.

In most cases, the methods defined here will delegate to the associated file system provider to perform the file operations. @since 1.7

Read More
Advertisement