Example usage for java.nio.file Path toString

List of usage examples for java.nio.file Path toString

Introduction

In this page you can find the example usage for java.nio.file Path toString.

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:com.samsung.sjs.SJSTest.java

protected void compareWithExpectedOutput(String actualOutput, String suffix, String outputFolder)
        throws IOException {
    Path basePath = Paths.get("src/test/resources/testoutput/" + outputFolder + "/");
    assertTrue(Files.exists(basePath));
    String testName = getName().substring(getName().indexOf('_') + 1);
    Path path = Paths.get(basePath.toString(), testName + suffix);
    if (Files.exists(path)) {
        String expectedOutput = readFileIntoString(path);
        assertEquals(expectedOutput, actualOutput);
    } else {//www.  j a v a  2 s  .  c  o  m
        // create the file
        Files.write(path, actualOutput.getBytes());
    }
}

From source file:company.gonapps.loghut.dao.TagDao.java

public List<TagDto> getList(String tagName, int year, int month) throws IOException, InvalidTagNameException {
    List<TagDto> tags = new LinkedList<>();
    rrwl.readLock().lock();//w  ww .  j a  va  2 s .com
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(Paths.get(settingDao.getSetting("tags.directory")
            + "/" + tagName + "/" + String.format("%04d", year) + "/" + String.format("%02d", month)))) {

        for (Path path : ds) {
            Matcher matcher = tagPathStringPattern.matcher(path.toString());
            if (matcher.find())
                tags.add(new TagDto().setName(matcher.group("name")).setPost(postDao.get(
                        Integer.parseInt(matcher.group("year")), Integer.parseInt(matcher.group("month")),
                        Integer.parseInt(matcher.group("day")), Integer.parseInt(matcher.group("number")),
                        matcher.group("secret").equals("s"))));
        }
    } finally {
        rrwl.readLock().unlock();
    }
    Collections.sort(tags, new TagDtoComparator());
    return tags;
}

From source file:com.ejisto.event.listener.SessionRecorderManager.java

private File selectOutputDirectory(Component parent, String directoryPath, boolean saveLastSelectionPath,
        SettingsRepository settingsRepository) {
    String targetPath = null;/*from w  w  w.j  av  a2 s  . c o  m*/
    Path savedPath = null;
    if (StringUtils.isNotBlank(directoryPath)) {
        savedPath = Paths.get(directoryPath);
        Path selectionPath = savedPath.getParent();
        if (selectionPath != null) {
            targetPath = selectionPath.toString();
        }
    }
    JFileChooser fileChooser = new JFileChooser(targetPath);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setSelectedFile(savedPath != null ? savedPath.toFile() : null);
    fileChooser.setDialogTitle(getMessage("session.record.save.target"));

    return GuiUtils.openFileSelectionDialog(parent, saveLastSelectionPath, fileChooser, LAST_OUTPUT_PATH,
            settingsRepository);
}

From source file:org.sakuli.starter.helper.SahiProxy.java

protected void injectCustomJavaScriptFiles() throws IOException {
    File injectFile = props.getSahiJSInjectConfigFile().toFile();
    String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8);
    if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) {
        injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END,
                SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END);
        FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8);
        logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG,
                props.getSahiJSInjectConfigFile().toString());
    }//  www .jav  a2 s.  c o  m

    Path source = props.getSahiJSInjectSourceFile();
    Path target = props.getSahiJSInjectTargetFile();
    if (isNewer(source, target)) {
        FileUtils.copyFile(source.toFile(), target.toFile(), false);
        logger.info("copied file '{}' to target '{}'", source.toString(), target.toString());
    }
}

From source file:com.ejisto.event.listener.SessionRecorderManager.java

private WebApplicationDescriptor createTempWebApplicationDescriptor(WebApplicationDescriptor original)
        throws IOException, JDOMException {
    Path path = Files.createTempDirectory(original.getContextPath().replaceAll("/", "_"));
    unzipFile(original.getWarFile(), path.toString());
    File targetDir = new File(FilenameUtils.normalize(path.toString() + "/WEB-INF/lib/"));
    copyEjistoLibs(true, targetDir.toPath());
    WebApplicationDescriptor temp = WebApplicationDescriptor.copyOf(original);
    temp.setDeployablePath(path.toString());
    modifyWebXml(temp);//from   w  w w.  ja v  a 2 s. com
    return temp;
}

From source file:edu.chalmers.dat076.moviefinder.service.MovieFileDatabaseHandlerImpl.java

@Override
@Transactional//from  w w w .j a va 2  s .co  m
public void removeFile(Path path) {
    try {
        movieSemaphore.acquire();
        List<Movie> movies = movieRepository.findAllByFilePathStartingWith(path.toString());
        for (Movie m : movies) {
            movieRepository.delete(m);
        }
    } catch (InterruptedException ex) {
    } finally {
        movieSemaphore.release();
    }

    List<Episode> episodes = episodeRepository.findAllByFilePathStartingWith(path.toString());
    for (Episode m : episodes) {
        Semaphore sLock = serieLock.get(m.getSeries().getTitle());
        if (sLock == null) {
            sLock = new Semaphore(1, true);
            serieLock.put(m.getSeries().getTitle(), sLock);
        }

        try {
            sLock.acquire();
            Series s = m.getSeries();
            s.getEpisodes().remove(m);
            episodeRepository.delete(m);
            if (s.getEpisodes().isEmpty()) {
                seriesRepository.delete(s);
            } else {
                seriesRepository.save(s);
            }
        } catch (InterruptedException ex) {
        } finally {
            sLock.release();
        }

    }

}

From source file:fr.ortolang.diffusion.client.cmd.CheckBagCommand.java

private void checkPermissions(Path root) {
    Path metadata = Paths.get(root.toString(), "metadata");
    Path objects = Paths.get(root.toString(), "objects");
    try {// w  w w  . j  a v  a2  s .co m
        checkPathPermissions(objects, metadata, -1, new HashSet<>());
    } catch (IOException e) {
        System.out.println("Unable to walk file tree: " + e.getMessage());
    }
}

From source file:io.seqware.pipeline.plugins.FileProvenanceQueryTool.java

private void bulkImportH2(StringBuilder tableCreateBuilder, Connection connection, Path importFile)
        throws SQLException {
    tableCreateBuilder.append("AS SELECT * FROM CSVREAD('").append(importFile.toString())
            .append("', null, 'fieldSeparator=\t')");
    Log.debug("Table creation query is: " + tableCreateBuilder.toString());
    Statement createTableStatement = null;
    try {/* w w  w. j av a 2s. com*/
        createTableStatement = connection.createStatement();
        createTableStatement.executeUpdate(tableCreateBuilder.toString());
    } finally {
        DbUtils.closeQuietly(createTableStatement);
    }
}

From source file:io.seqware.pipeline.plugins.FileProvenanceQueryTool.java

private Path populateOriginalReportFromWS() throws IOException {
    Map<FileProvenanceParam, List<String>> map = ProvenanceUtility.convertOptionsToMap(options, metadata);
    // specify some standard filters that are required for filters
    map.put(FileProvenanceParam.skip, new ImmutableList.Builder<String>().add("false").build());
    map.put(FileProvenanceParam.workflow_run_status,
            new ImmutableList.Builder<String>().add(WorkflowRunStatus.completed.toString()).build());
    map.put(FileProvenanceParam.processing_status,
            new ImmutableList.Builder<String>().add(ProcessingStatus.success.toString()).build());
    Path originalReport = Files.createTempFile("file_provenance", "txt");
    Log.debug("Original report written to " + originalReport.toString());
    try (BufferedWriter originalWriter = Files.newBufferedWriter(originalReport, Charset.defaultCharset())) {
        metadata.fileProvenanceReport(map, originalWriter);
    }// w w  w  .  java2 s . c o m
    return originalReport;
}

From source file:com.github.jrialland.ajpclient.AbstractTomcatTest.java

@SuppressWarnings("serial")
protected void addStaticResource(final String mapping, final Path file) {

    if (!Files.isRegularFile(file)) {
        final FileNotFoundException fnf = new FileNotFoundException(file.toString());
        fnf.fillInStackTrace();//from ww w. java2 s  . c o  m
        throw new IllegalArgumentException(fnf);
    }

    String md5;
    try {
        final InputStream is = file.toUri().toURL().openStream();
        md5 = computeMd5(is);
        is.close();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    final String fMd5 = md5;

    addServlet(mapping, new HttpServlet() {
        @Override
        protected void service(final HttpServletRequest req, final HttpServletResponse resp)
                throws ServletException, IOException {
            resp.setContentLength((int) Files.size(file));
            resp.setHeader("Content-MD5", fMd5);
            final String mime = Files.probeContentType(file);
            if (mime != null) {
                resp.setContentType(mime);
            }
            final OutputStream out = resp.getOutputStream();
            Files.copy(file, out);
            out.flush();
        }
    });
}