Example usage for java.io File toPath

List of usage examples for java.io File toPath

Introduction

In this page you can find the example usage for java.io File toPath.

Prototype

public Path toPath() 

Source Link

Document

Returns a Path java.nio.file.Path object constructed from this abstract path.

Usage

From source file:com.netease.hearttouch.hthotfix.patch.PatchRefGeneratorTransformExecutor.java

public void transformDirectory(File inputFile, File outputFile) throws IOException {

    Path inputDir = inputFile.toPath();
    Path outputDir = outputFile.toPath();

    if (!Files.isDirectory(inputDir)) {
        return;/* w  w w .j a  v a2  s  . co m*/
    }
    final OutputDirectory outputDirectory = new OutputDirectory(outputDir);
    Files.walkFileTree(inputDir, new ClasspathVisitor() {
        @Override
        protected void visitClass(Path path, byte[] bytecode) throws IOException {
            ClassReader cr = new ClassReader(bytecode);
            String className = cr.getClassName();
            if (extension.getGeneratePatch() && extension.getScanRef()) {
                if (!refScanInstrument.isPatchClass(className.replace("/", "."))) {
                    boolean bPatchRef = refScanInstrument.hasReference(bytecode, project);
                    if (bPatchRef) {
                        patchJarHelper.writeClassToDirectory(className, bytecode);
                    }
                }
            }
            outputDirectory.writeClass(className, bytecode);
        }

        @Override
        protected void visitResource(Path relativePath, byte[] content) throws IOException {
            outputDirectory.writeFile(relativePath, content);

        }
    });
}

From source file:controller.FileWatcher.java

@Override
public void onFileDelete(File arg0) {
    if (!Files.isSymbolicLink(arg0.toPath())) {
        String fileName = ServerUtil.convertPath(arg0.getAbsolutePath(), MyDropboxSwing.urls);
        FileDelete fileDelete = new FileDelete(fileName, Constants.IS_FILE);
        lstCommit.add(fileDelete);//  w w  w.j  ava2s . c o m
    }
}

From source file:org.wte4j.impl.SpringTemplateEngine.java

Path createFile(Template<Object> template, Object data) throws IOException {
    File tempFile = File.createTempFile(template.getDocumentName(), ".docx");
    try (OutputStream out = Files.newOutputStream(tempFile.toPath())) {
        template.toDocument(data, out);//from  w  w  w  .  j a  va 2s .  co m
        return tempFile.toPath();
    }
}

From source file:de.ks.file.FileStore.java

private String getMimeType(File file) {
    Path path = file.toPath();
    try {//  w w  w  . j a va 2 s .c  o  m
        return Files.probeContentType(path);
    } catch (IOException e) {
        log.error("Could not get mime type from ", file, e);
        return null;
    }
}

From source file:com.github.blindpirate.gogradle.common.GoSourceCodeFilter.java

@Override
protected boolean acceptDir(File dir) {
    if (Files.isSymbolicLink(dir.toPath())) {
        return false;
    }/*w ww. ja v  a  2  s.  c om*/
    if (fileNameStartsWithDotOrUnderline(dir)) {
        return false;
    }
    if (fileNameEqualsAny(dir, TESTDATA_DIRECTORY)) {
        return false;
    }
    return dirPredicate.test(dir);
}

From source file:com.oxiane.maven.xqueryMerger.Merger.java

@Override
public void execute() throws MojoExecutionException {
    Path sourceRootPath = inputSources.toPath();
    Path destinationRootPath = outputDirectory.toPath();
    IOFileFilter filter = buildFilter();
    Iterator<File> it = FileUtils.iterateFiles(inputSources, filter, FileFilterUtils.directoryFileFilter());
    if (!it.hasNext()) {
        getLog().warn("No file found matching " + filter.toString() + " in " + inputSources.getAbsolutePath());
    }// www . java  2s  .c  om
    while (it.hasNext()) {
        File sourceFile = it.next();
        Path fileSourcePath = sourceFile.toPath();
        Path relativePath = sourceRootPath.relativize(fileSourcePath);
        getLog().debug("[Merger] found source: " + fileSourcePath.toString());
        getLog().debug("[Merger]    relative path is " + relativePath.toString());
        StreamSource source = new StreamSource(sourceFile);
        XQueryMerger merger = new XQueryMerger(source);
        merger.setMainQuery();
        File destinationFile = destinationRootPath.resolve(relativePath).toFile();
        getLog().debug("[Merger]    destination will be " + destinationFile.getAbsolutePath());
        try {
            String result = merger.merge();
            destinationFile.getParentFile().mkdirs();
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(destinationFile),
                    merger.getEncoding());
            osw.write(result);
            osw.flush();
            osw.close();
            getLog().debug("[Merger] " + relativePath.toString() + " merged into "
                    + destinationFile.getAbsolutePath());
        } catch (ParsingException ex) {
            getLog().error(ex.getMessage());
            throw new MojoExecutionException("Merge of " + sourceFile.getAbsolutePath() + " fails", ex);
        } catch (FileNotFoundException ex) {
            getLog().error(ex.getMessage());
            throw new MojoExecutionException(
                    "Unable to create destination " + destinationFile.getAbsolutePath(), ex);
        } catch (IOException ex) {
            getLog().error(ex.getMessage());
            throw new MojoExecutionException("While writing " + destinationFile.getAbsolutePath(), ex);
        }
    }
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fileManagement.FileUtility.java

public boolean destroyDir(@NotNull File path) throws IOException {
    Path directory = path.toPath();

    @Getter/*from  w w  w  . j a  v  a2  s.  c  o  m*/
    @Setter
    class BooleanWrapper {
        boolean deleted;
    }
    BooleanWrapper status = new BooleanWrapper();

    Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            status.setDeleted(policy.delete(file.toFile()));
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            status.setDeleted(policy.delete(dir.toFile()));
            return FileVisitResult.CONTINUE;
        }
    });

    return status.isDeleted();
}

From source file:com.digitalgeneralists.assurance.model.entities.FileReference.java

@Override
public String toString() {
    File reference = this.getFile();
    return (reference != null) ? reference.toPath().getFileName().toString() : "<unknown file>";
}

From source file:com.netease.hearttouch.hthotfix.patch.PatchGeneratorTransformExecutor.java

public void transformDirectory(File inputFile, File outputFile) throws IOException {

    Path inputDir = inputFile.toPath();
    Path outputDir = outputFile.toPath();

    if (!Files.isDirectory(inputDir)) {
        return;/*from   www  .  j  a  v a2 s.c  o m*/
    }
    final OutputDirectory outputDirectory = new OutputDirectory(outputDir);
    Files.walkFileTree(inputDir, new ClasspathVisitor() {
        @Override
        protected void visitClass(Path path, byte[] bytecode) throws IOException {
            ClassReader cr = new ClassReader(bytecode);
            String className = cr.getClassName();

            if (extension.getGeneratePatch()) {
                if (hashFileParser == null) {
                    project.getLogger().error("hashFileParser is null,do you set  generatePath true?");
                }

                if ((hashFileParser != null) && (hashFileParser.isChanged(className, bytecode))) {
                    project.getLogger().error("has change classname,\t" + className);

                    ResourceDiffChecker.checkClass(project, className);
                    patchJarHelper.writeClassToDirectory(className, hackInjector.inject(className, bytecode));
                    refScanInstrument.addPatchClassName(className, hackInjector.getLastSuperName());

                }
            }
            outputDirectory.writeClass(className, bytecode);
        }

        @Override
        protected void visitResource(Path relativePath, byte[] content) throws IOException {
            outputDirectory.writeFile(relativePath, content);

        }
    });
}

From source file:fr.jetoile.hadoopunit.component.SolrBootstrap.java

private CoreContainer createCoreContainer(String solrHomeDirectory, File solrXmlFile) {
    return CoreContainer.createAndLoad(Paths.get(solrHomeDirectory), solrXmlFile.toPath());
}