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:listduplicatingfiles.ListDuplicatingFiles.java

public void listDuplicatingFiles(Path dir) {
    File myFile = dir.toFile();/*from   ww w  .ja v a2 s  . c om*/
    List<File> nonDuplicated = new LinkedList<File>();

    for (File fileEntry : myFile.listFiles()) {
        if (fileEntry.isDirectory()) {

            System.out.println(fileEntry.getName());
            listDuplicatingFiles(fileEntry.toPath());

        } else {
            if (!isDuplicated(nonDuplicated, fileEntry)) {
                nonDuplicated.add(fileEntry);
            }
            //System.out.println(fileEntry.getName());
        }
    }

    for (File file : nonDuplicated) {
        System.out.println(file);
    }

}

From source file:com.netease.hearttouch.hthotfix.HashTransformExecutor.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  a  2 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()) {
                hashFileGenerator.addClass(bytecode);
                outputDirectory.writeClass(className, hackInjector.inject(className, bytecode));
            } else {
                outputDirectory.writeClass(className, bytecode);
            }
        }

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

From source file:eu.freme.bpt.service.FailurePolicyTest.java

private File createDir() throws IOException {
    File dir = Files.createTempDirectory("testDir").toFile();
    try {//from  w  w w.ja  v a 2 s  .  co m
        FileUtils.forceDeleteOnExit(dir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // now create some files in it
    File file1 = new File(dir, "file1");
    File file2 = new File(dir, "file2");
    Files.write(file1.toPath(), "Hello".getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,
            StandardOpenOption.WRITE);
    Files.write(file2.toPath(), "World".getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,
            StandardOpenOption.WRITE);
    return dir;
}

From source file:com.ethercamp.harmony.service.wallet.FileSystemWalletStore.java

public List<WalletAddressItem> fromStore() {
    final ObjectMapper mapper = new ObjectMapper();

    try {//from w  w w .ja v  a2s .  c  o m
        final File file = getKeyStoreLocation().resolve(FILE_NAME).toFile();

        final String content = Files.readAllLines(file.toPath()).stream().collect(Collectors.joining(""));

        return mapper.readValue(content, new TypeReference<List<WalletAddressItem>>() {
        });
    } catch (NoSuchFileException e) {
        return Collections.EMPTY_LIST;
    } catch (IOException e) {
        throw new RuntimeException("Problem loading data. Message: " + e.getMessage(), e);
    }
}

From source file:org.apache.asterix.experiment.action.derived.RunSQLPPFileAction.java

@Override
public void doPerform() throws Exception {
    FileOutputStream csvFileOut = new FileOutputStream(csvFilePath.toFile());
    PrintWriter printer = new PrintWriter(csvFileOut, true);
    try {/* w  w  w.  ja  v a  2s  .c o  m*/
        if (aqlFilePath.toFile().isDirectory()) {
            for (File f : aqlFilePath.toFile().listFiles()) {
                queriesToRun.add(f.toPath());
            }
        } else {
            queriesToRun.add(aqlFilePath);
        }

        for (Path p : queriesToRun) {
            String sqlpp = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(p))).toString();
            String uri = MessageFormat.format(REST_URI_TEMPLATE, restHost, String.valueOf(restPort));
            HttpPost post = new HttpPost(uri);
            post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
            post.setEntity(new StringEntity(sqlpp, StandardCharsets.UTF_8));
            long start = System.currentTimeMillis();
            HttpResponse resp = httpClient.execute(post);
            HttpEntity entity = resp.getEntity();
            if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new HttpException("Query returned error" + EntityUtils.toString(entity));
            }
            EntityUtils.consume(entity);
            long end = System.currentTimeMillis();
            long wallClock = end - start;
            String currLine = p.getFileName().toString() + ',' + wallClock;
            System.out.println(currLine);
            printer.print(currLine + '\n');
        }
    } finally {
        printer.close();
    }
}

From source file:com.anuz.dummyclient.controller.ContentController.java

@RequestMapping(value = "files/{directory}/{fileName}", method = RequestMethod.GET)
public void image(@PathVariable("directory") String directory, @PathVariable("fileName") String fileName,
        @RequestHeader HttpHeaders headers, HttpServletResponse response) {
    try {//from w  ww  . j a  va  2  s  .c  o m
        logger.info(fileName);

        File file = new File(CONSTANT.CONTENTS + directory + "/" + fileName);
        Files.copy(file.toPath(), response.getOutputStream());

    } catch (IOException ex) {
        logger.info("Image not found");
        logger.debug(ex.getMessage());
    }
}

From source file:com.compomics.colims.core.io.colims_to_utilities.ColimsSpectrumMapperTest.java

/**
 * Test of map method, of class ColimsSpectrumMapper.
 * @throws java.lang.Exception in case of an exception
 *//*  ww  w  .j  a v  a 2 s  . c o m*/
@Test
public void testMap() throws Exception {
    Spectrum spectrum = new Spectrum();
    File inputSpectra = new ClassPathResource("data/input_spectra_Z.mgf.gz").getFile();
    byte[] data = Files.readAllBytes(inputSpectra.toPath());
    SpectrumFile spectrumFile = new SpectrumFile();
    spectrumFile.setContent(data);
    List<SpectrumFile> spectrumFileList = new ArrayList<>();
    spectrumFileList.add(spectrumFile);

    spectrum.setAccession("fake spectrum 1");
    spectrum.setFragmentationType(FragmentationType.CID);
    spectrum.setIntensity(1233123.32);
    spectrum.setRetentionTime(2123.1);
    spectrum.setMzRatio(123.12);
    spectrum.setCharge(3);
    spectrum.setSpectrumFiles(spectrumFileList);
    spectrum.setScanNumber(12L);
    spectrum.setScanTime(11231.1);
    spectrum.setPeptides(new ArrayList<>());

    MSnSpectrum targetSpectrum = new MSnSpectrum();
    colimsSpectrumMapper.map(spectrum, targetSpectrum);
    Assert.assertEquals(677, targetSpectrum.getPeakList().size());
    Assert.assertEquals("12", targetSpectrum.getScanNumber());
    Assert.assertEquals(1233123.32, targetSpectrum.getPrecursor().getIntensity(), 0.01);
    Assert.assertEquals(123.12, targetSpectrum.getPrecursor().getMz(), 0.01);
    Assert.assertEquals(new Charge(1, 3), targetSpectrum.getPrecursor().getPossibleCharges().get(0));
}

From source file:hydrograph.ui.graph.debug.service.PurgeViewDataFiles.java

/**
 * Purge the file on specific path/*from w  w  w  .  j  a va 2  s .c o m*/
 * @param filePath
 */
private void removeFiles(String filePath) {
    try {
        File file = new File(filePath);
        boolean result = Files.deleteIfExists(file.toPath());
        if (result) {
            logger.debug(filePath + " file deleted.");
        }
    } catch (Exception exception) {
        logger.error("Failed to remove ViewExecutionHistory log file.", exception);
    }
}

From source file:com.heliosdecompiler.helios.controller.files.OpenedFile.java

public OpenedFile(MessageHandler messageHandler, File target) {
    this.messageHandler = messageHandler;
    this.target = target.toPath();

    reset();//from  w ww. j  av a  2s . c o m
}

From source file:edu.chalmers.dat076.moviefinder.controller.AdminController.java

@RequestMapping(value = "/removePath/{id}", method = RequestMethod.DELETE)
public ResponseEntity<String> removePath(@PathVariable long id) {
    ListeningPath lp = listeningPathRepository.findOne(id);
    if (lp != null) {
        File f = new File(lp.getListeningPath());
        try {/*w  ww.  j a v  a  2 s . c o m*/
            databaseHelper.removePath(f.toPath());
            fileThreadService.removeListeningPath(f.toPath());
            movieDatabaseHelper.removeFile(f.toPath());
            return new ResponseEntity<>(HttpStatus.OK);
        } catch (NullPointerException e) {
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}