Example usage for java.nio.file Path getParent

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

Introduction

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

Prototype

Path getParent();

Source Link

Document

Returns the parent path, or null if this path does not have a parent.

Usage

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void saveMRUBankFolder(String path) {
    Path pathE = Paths.get(path);

    String pathS = pathE.getParent().toString();
    String nameS = pathE.getFileName().toString();

    prefs.put("MRUBankFolder", pathS);
    prefs.put("MRUBankFileName", nameS);
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void saveMRUPatchFolder(String path) {
    Path pathE = Paths.get(path);

    String pathS = pathE.getParent().toString();
    String nameS = pathE.getFileName().toString();

    prefs.put("MRUPatchFolder", pathS);
    prefs.put("MRUPatchFileName", nameS);
}

From source file:org.codice.ddf.configuration.migration.ConfigurationMigrationManagerTest.java

private void createMigrationPropsFile(String contents) throws IOException {
    Path migrationPropsPath = ddfHome.resolve(Paths.get("etc", "migration.properties"));
    Files.createDirectories(migrationPropsPath.getParent());
    Files.createFile(migrationPropsPath);
    Files.write(migrationPropsPath, contents.getBytes(), StandardOpenOption.CREATE,
            StandardOpenOption.TRUNCATE_EXISTING);
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java

/**
 * This will save the HTML markup + css file to a specified folder
 *
 * @param tempFilepath the temp folder where
 * @return//from   w w  w  .j  a  v a 2s.c om
 */
private Path exportMarkup(Path tempFilepath) {
    Path resultPath;
    if (outputPath != null) {
        resultPath = outputPath;
    } else {
        resultPath = workingDirectory;
    }

    Path markupDir = resultPath.resolve(title + "-markup");
    try {
        try {
            Files.createDirectory(markupDir);
        } catch (FileAlreadyExistsException e) {
            // do nothing
        }

        Path tempDirPath = tempFilepath.getParent();
        File tempDir = tempDirPath.toFile();

        // Copy all files from temp folder to the markup output folder
        String[] files = tempDir.list(FileFileFilter.FILE);
        for (int i = 0; i < files.length; i++) {
            Files.copy(tempDirPath.resolve(files[i]), markupDir.resolve(files[i]),
                    StandardCopyOption.REPLACE_EXISTING);
        }

        logger.info("Exported markup to folder: " + markupDir.toAbsolutePath().toString());
    } catch (IOException e) {
        logger.error("Error saving markup files: " + e.getMessage(), e);
        return null;
    }
    return markupDir;
}

From source file:org.roda.core.storage.fs.FileStorageService.java

@Override
public CloseableIterable<BinaryVersion> listBinaryVersions(StoragePath storagePath)
        throws GenericException, RequestNotValidException, NotFoundException, AuthorizationDeniedException {
    Path fauxPath = FSUtils.getEntityPath(historyDataPath, storagePath);
    Path parent = fauxPath.getParent();
    final String baseName = fauxPath.getFileName().toString();

    CloseableIterable<BinaryVersion> iterable;

    if (!FSUtils.exists(parent)) {
        return new EmptyClosableIterable<>();
    }/*from w  ww.j  a v a2 s  . c om*/

    try {
        final DirectoryStream<Path> directoryStream = Files.newDirectoryStream(parent,
                new DirectoryStream.Filter<Path>() {

                    @Override
                    public boolean accept(Path entry) throws IOException {
                        return entry.getFileName().toString().startsWith(baseName);
                    }
                });

        final Iterator<Path> pathIterator = directoryStream.iterator();
        iterable = new CloseableIterable<BinaryVersion>() {

            @Override
            public Iterator<BinaryVersion> iterator() {
                return new Iterator<BinaryVersion>() {

                    @Override
                    public boolean hasNext() {
                        return pathIterator.hasNext();
                    }

                    @Override
                    public BinaryVersion next() {
                        Path next = pathIterator.next();
                        BinaryVersion ret;
                        try {
                            ret = FSUtils.convertPathToBinaryVersion(historyDataPath, historyMetadataPath,
                                    next);
                        } catch (GenericException | NotFoundException | RequestNotValidException e) {
                            LOGGER.error(
                                    "Error while list path " + basePath + " while parsing resource " + next, e);
                            ret = null;
                        }

                        return ret;
                    }

                };
            }

            @Override
            public void close() throws IOException {
                directoryStream.close();
            }
        };

    } catch (NoSuchFileException e) {
        throw new NotFoundException("Could not find versions of " + storagePath, e);
    } catch (IOException e) {
        throw new GenericException("Error finding version of " + storagePath, e);
    }

    return iterable;
}

From source file:org.sakuli.actions.screenbased.ScreenshotActions.java

/**
 * Takes a screenshot of the assigned area and save in the given format;
 *
 * @param picturePath Path to the final image
 * @param rectangle   if not null, the screenshot only shows the defined rectangle
 * @return {@link Path} ot the screenshot.
 *///from  w w  w. j a  v  a  2  s  .  c  o  m
public Path takeScreenshot(Path picturePath, Rectangle rectangle) {
    try {
        if (Files.isDirectory(picturePath)) {
            throw new IOException("Path to a file in format [folder-path]" + File.separator
                    + "screenshotname[.png|jpg] expected!");
        }
        String filename = picturePath.getFileName().toString();
        String format = defaultScreenshotFormat;
        if (filename.contains(".")) {
            format = filename.substring(filename.lastIndexOf(".") + 1);
        } else {
            //add default screenshot format
            picturePath = picturePath.getParent().resolve(filename + "." + format);
        }
        return createPictureFromBufferedImage(picturePath, format, createBufferedImage(rectangle));
    } catch (Exception e) {
        baseActionLoader.getExceptionHandler().handleException(
                new SakuliException(e, "Can't create Screenshot for path '" + picturePath + "'"));
        return null;
    }

}

From source file:org.fao.geonet.api.records.formatters.FormatterApiIntegrationTest.java

@Test
public void testExecXslt() throws Exception {
    final ServletContext context = _applicationContext.getBean(ServletContext.class);
    MockHttpServletRequest request = new MockHttpServletRequest(context, "GET",
            "http://localhost:8080/geonetwork/srv/eng/md.formatter");
    request.getSession();/* www  . ja va2s  .c  o  m*/
    request.setPathInfo("/eng/md.formatter");

    final String applicationContextAttributeKey = "srv";
    request.getServletContext().setAttribute(applicationContextAttributeKey, _applicationContext);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);

    RequestContextHolder.setRequestAttributes(requestAttributes);
    final String formatterName = "xsl-test-formatter";
    final URL testFormatterViewFile = FormatterApiIntegrationTest.class
            .getResource(formatterName + "/view.xsl");
    final Path testFormatter = IO.toPath(testFormatterViewFile.toURI()).getParent();
    final Path formatterDir = this.dataDirectory.getFormatterDir();
    Files.deleteIfExists(formatterDir.resolve("functions.xsl"));
    IO.copyDirectoryOrFile(testFormatter, formatterDir.resolve(formatterName), false);
    IO.copyDirectoryOrFile(testFormatter.getParent().resolve("functions.xsl"), formatterDir, true);
    JeevesDelegatingFilterProxy.setApplicationContextAttributeKey(applicationContextAttributeKey);

    final MockHttpServletResponse response = new MockHttpServletResponse();
    formatService.exec("eng", "html", "" + id, null, formatterName, "true", false, _100,
            new ServletWebRequest(request, response));
    final String viewXml = response.getContentAsString();
    final Element view = Xml.loadString(viewXml, false);
    assertEqualsText("fromFunction", view, "*//p");
    assertEqualsText("Title", view, "*//div[@class='tr']");
}

From source file:com.splicemachine.storage.HNIOFileSystem.java

@Override
public void concat(Path target, Path... sources) throws IOException {
    org.apache.hadoop.fs.Path[] srcPaths = new org.apache.hadoop.fs.Path[sources.length];
    for (int i = 0; i < sources.length; i++) {
        srcPaths[i] = new org.apache.hadoop.fs.Path(sources[i].getParent().toString(),
                sources[i].getFileName().toString());
    }//from w  ww.j  a va  2  s .  c  o  m
    org.apache.hadoop.fs.Path targetPath = new org.apache.hadoop.fs.Path(target.getParent().toString(),
            target.getFileName().toString());

    if (isDistributedFS) {
        fs.concat(targetPath, srcPaths);
    } else {
        for (org.apache.hadoop.fs.Path src : srcPaths) {
            fs.copyFromLocalFile(true, false, src, targetPath);
        }
    }
}

From source file:org.apache.nifi.controller.repository.FileSystemRepository.java

public static Path getArchivePath(final Path contentClaimPath) {
    final Path sectionPath = contentClaimPath.getParent();
    final String claimId = contentClaimPath.toFile().getName();
    return sectionPath.resolve(ARCHIVE_DIR_NAME).resolve(claimId);
}

From source file:org.fao.geonet.api.records.formatters.FormatterApi.java

private synchronized boolean isFormatterInSchemaPlugin(Path formatterDir, Path schemaDir) throws IOException {
    final Path canonicalPath = formatterDir.toRealPath();
    Boolean isInSchemaPlugin = this.isFormatterInSchemaPluginMap.get(canonicalPath);
    if (isInSchemaPlugin == null) {
        isInSchemaPlugin = false;//ww  w  .j  av  a2s.com
        Path current = formatterDir;
        while (current.getParent() != null && Files.exists(current.getParent())) {
            if (current.equals(schemaDir)) {
                isInSchemaPlugin = true;
                break;
            }
            current = current.getParent();
        }

        this.isFormatterInSchemaPluginMap.put(canonicalPath, isInSchemaPlugin);
    }
    return isInSchemaPlugin;
}