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.simiacryptus.util.io.MarkdownNotebookOutput.java

/**
 * Get markdown notebook output.//from   www  .  j a  va 2s  . c o m
 *
 * @param sourceClass the source class
 * @param absoluteUrl the absolute url
 * @param suffix      the suffix
 * @return the markdown notebook output
 */
@javax.annotation.Nonnull
public static com.simiacryptus.util.io.MarkdownNotebookOutput get(
        @javax.annotation.Nonnull Class<?> sourceClass, @Nullable String absoluteUrl,
        @javax.annotation.Nonnull String... suffix) {
    try {
        final StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[2];
        final String methodName = callingFrame.getMethodName();
        final String className = sourceClass.getCanonicalName();
        @javax.annotation.Nonnull
        File path = new File(Util.mkString(File.separator, "reports",
                className.replaceAll("\\.", "/").replaceAll("\\$", "/")));
        for (int i = 0; i < suffix.length - 1; i++)
            path = new File(path, suffix[i]);
        String testName = suffix.length == 0 ? methodName : suffix[suffix.length - 1];
        path = new File(path, testName + ".md");
        path.getParentFile().mkdirs();
        @javax.annotation.Nonnull
        com.simiacryptus.util.io.MarkdownNotebookOutput notebookOutput = new com.simiacryptus.util.io.MarkdownNotebookOutput(
                path, testName);
        if (null != absoluteUrl) {
            try {
                String url = new URI(absoluteUrl + "/" + path.toPath().toString().replaceAll("\\\\", "/"))
                        .normalize().toString();
                notebookOutput.setAbsoluteUrl(url);
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
        return notebookOutput;
    } catch (@javax.annotation.Nonnull final FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.crossover.trial.weather.util.AirportLoader.java

@Override
public void run(ApplicationArguments args) throws Exception {
    if (args.containsOption("airports") && !args.getOptionValues("airports").isEmpty()) {
        File dataFile = new File(args.getOptionValues("airports").get(0));
        if (dataFile.canRead() && dataFile.isFile() && dataFile.exists()) {
            log.info("Loading airports from [{}]", dataFile);

            try (Stream<String> lines = Files.lines(dataFile.toPath())) {
                lines.map(Row::new).filter(Row::expectedTotalColumns).filter(Row::expectedColumnsFilled)
                        .map(Row::parse).filter(airport -> airport != null).forEach(airportRepository::save);
            }/*from  ww w.  j a  v  a2  s.  c o m*/

        } else
            log.error("Specified airports data file is not readable [{}]", dataFile.toPath());

    }
}

From source file:com.streamsets.datacollector.io.DataStore.java

public DataStore(File file) {
    Utils.checkNotNull(file, "file");
    File absFile = file.getAbsoluteFile();
    this.file = absFile.toPath();
    fileTmp = new File(absFile.getAbsolutePath() + "-tmp").toPath();
    fileNew = new File(absFile.getAbsolutePath() + "-new").toPath();
    fileOld = new File(absFile.getAbsolutePath() + "-old").toPath();
    LOG.trace("Create DataStore for '{}'", file);
}

From source file:algorithm.F5Steganography.java

private String getPayloadPathString(File carrier, File payload) throws IOException {
    PayloadSegment payloadSegment = new PayloadSegment(carrier, payload, this);
    File payloadSemgentFile = new File("tmp");
    FileUtils.writeByteArrayToFile(payloadSemgentFile, payloadSegment.getPayloadSegmentBytes());
    return "" + payloadSemgentFile.toPath();
}

From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java

public long getCreatedTime(String filePath) throws IOException {
    File file = new File(filePath);
    FileTime fileTime = (FileTime) Files.getAttribute(file.toPath(), "creationTime", LinkOption.NOFOLLOW_LINKS);
    if (fileTime != null) {
        return fileTime.to(TimeUnit.SECONDS);
    }/*from   w w  w  .  j  a  v a2 s  .  c  om*/
    return 0;
}

From source file:com.netflix.spinnaker.config.secrets.SecretManager.java

protected Path decryptedFilePath(String prefix, String decryptedContents) {
    try {//from  w w w .  j a v a  2s.co m
        File tempFile = File.createTempFile(prefix, ".secret");
        try (FileWriter fileWriter = new FileWriter(tempFile)) {
            fileWriter.write(decryptedContents);
        }
        tempFile.deleteOnExit();
        return tempFile.toPath();
    } catch (IOException e) {
        throw new SecretDecryptionException(e.getMessage());
    }
}

From source file:com.ontheserverside.batch.bank.tx.SimpleElixir0Generator.java

@Override
public void generate(final File outputFile, final int numberOfTransactions) throws IOException {
    final TxGenerator txGenerator = new TxGenerator();
    final BufferedWriter writer = Files.newBufferedWriter(outputFile.toPath(), StandardCharsets.UTF_8);
    try {//from   www .j  a  v  a2s .c om
        for (int i = 0; i < numberOfTransactions; i++) {
            writer.write(txGenerator.generate().toString());
            writer.newLine();
        }
    } finally {
        writer.close();
    }
}

From source file:org.fcrepo.integration.connector.file.AbstractFedoraFileSystemConnectorIT.java

@Test
public void testChangedFileFixity() throws RepositoryException, IOException, NoSuchAlgorithmException {
    final Session session = repo.login();

    final FedoraBinary binary = binaryService.findOrCreate(session, testFilePath());

    final String originalFixity = checkFixity(binary);

    final File file = fileForNode();
    write(file.toPath(), " ".getBytes("UTF-8"));

    final String newFixity = checkFixity(binary);

    assertNotEquals("Checksum is expected to have changed!", originalFixity, newFixity);

    session.save();/*from  www. jav  a  2 s.  c  om*/
    session.logout();
}