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:de.flapdoodle.embed.process.runtime.AbstractProcess.java

protected static int getPidFromFile(File pidFile) throws IOException {
    // wait for file to be created
    int tries = 0;
    while (!pidFile.exists() && tries < 5) {
        try {//  w w w. j a v a 2 s  . c o m
            Thread.sleep(100);
        } catch (InterruptedException e1) {
            // ignore
        }
        logger.warn("Didn't find pid file in try {}, waiting 100ms...", tries);
        tries++;
    }
    // don't check file to be there. want to throw IOException if
    // something happens
    if (!pidFile.exists()) {
        throw new IOException("Could not find pid file " + pidFile);
    }

    // read the file, wait for the pid string to appear
    String fileContent = StringUtils
            .chomp(StringUtils.strip(new String(java.nio.file.Files.readAllBytes(pidFile.toPath()))));
    tries = 0;
    while (StringUtils.isBlank(fileContent) && tries < 5) {
        fileContent = StringUtils
                .chomp(StringUtils.strip(new String(java.nio.file.Files.readAllBytes(pidFile.toPath()))));
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) {
            // ignore
        }
        tries++;
    }
    // check for empty file
    if (StringUtils.isBlank(fileContent)) {
        throw new IOException(
                "Pidfile " + pidFile + "does not contain a pid. Waited for " + tries * 100 + "ms.");
    }
    // pidfile exists and has content
    try {
        return Integer.parseInt(fileContent);
    } catch (NumberFormatException e) {
        throw new IOException("Pidfile " + pidFile + "does not contain a valid pid. Content: " + fileContent);
    }
}

From source file:com.clust4j.data.BufferedMatrixReader.java

static byte[] fileToBytes(final File file) throws IOException {
    return Files.readAllBytes(file.toPath());
}

From source file:com.esri.geoportal.harvester.unc.UncFolder.java

/**
 * Matches file//from  w  w  w  .  ja va  2  s .c  o  m
 * @param file file
 * @param pattern match patter (glob)
 * @return <code>true</code> if URL matches the pattern
 */
private boolean matchFileName(File file, String pattern) {
    Path path = file.toPath();
    PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + pattern);
    return pathMatcher.matches(path);
}

From source file:com.hortonworks.streamline.streams.common.event.EventLogFileReader.java

public Stream<EventInformation> loadEventLogFileAsStream(File eventLogFile) throws IOException {
    Stream<String> lines = Files.lines(eventLogFile.toPath(), ENCODING_UTF_8);
    return lines.map(line -> {
        try {/* w ww . java 2  s.c  o  m*/
            return (EventInformation) objectMapper.readValue(line, new TypeReference<EventInformation>() {
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}

From source file:io.druid.segment.writeout.TmpFileSegmentWriteOutMedium.java

@Override
public WriteOutBytes makeWriteOutBytes() throws IOException {
    File file = File.createTempFile("filePeon", null, dir);
    FileChannel ch = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE);
    closer.register(file::delete);/*from   w ww .  j a v  a 2s.  co  m*/
    closer.register(ch);
    return new FileWriteOutBytes(file, ch);
}

From source file:com.blackducksoftware.ohcount4j.FileFinder.java

private boolean canAddDirectoryForProcessing(File directory) {
    boolean isSymbolicLink = Files.isSymbolicLink(directory.toPath());
    if (isSymbolicLink) {
        return processSymbolicLinks;
    } else {//from  w  w w. j  a v  a2s  . c o  m
        return true;
    }
}

From source file:com.blackducksoftware.integration.hub.detect.workflow.diagnostic.RelevantFileTracker.java

private boolean isChildOfTrackedFolder(final File file) {
    final Path filePath = file.toPath();
    return Stream.of(relevantDirectory).anyMatch(trackedFile -> filePath.startsWith(trackedFile.toPath()));
}

From source file:org.agatom.springatom.web.controller.SVDefaultController.java

protected final Path getTempPath() {
    final File tempDir = this.getTempDir();
    return tempDir != null ? tempDir.toPath() : null;
}

From source file:ru.codemine.ccms.service.DataFileService.java

@Transactional
public void delete(DataFile file) {
    File f = new File(file.getFilename());
    try {/*from   w  ww . ja v  a2s .  co  m*/
        Files.deleteIfExists(f.toPath());
    } catch (IOException ex) {
        log.warn("    ? ?: " + file.getViewName() + "("
                + file.getFilename() + "), : " + ex.getLocalizedMessage());
    }
    dataFileDAO.delete(file);
}

From source file:fr.duminy.components.swing.path.JPathBuilder.java

public JPathBuilder initialPath(File initialPath) {
    this.initialPath = (initialPath == null) ? null : initialPath.toPath();
    return this;
}