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:nl.tudelft.graphalytics.reporting.html.StaticResource.java

@Override
public void write(Path reportPath) throws IOException {
    Path outputPath = reportPath.resolve(relativeOutputPath);
    // Ensure that the containing directory exists
    if (!outputPath.getParent().toFile().exists()) {
        Files.createDirectories(outputPath.getParent());
    } else if (!outputPath.getParent().toFile().isDirectory()) {
        throw new IOException(
                "Could not write static resource to \"" + outputPath + "\": parent is not a directory.");
    }//from ww  w  .  j av a 2  s.  c o m
    // Copy the resource to the output file
    FileUtils.copyInputStreamToFile(resourceUrl.openStream(), outputPath.toFile());
}

From source file:org.kawakicchi.bookshelf.infrastructure.storage.fs.FSContentStorage.java

public void store(final String key, final InputStream stream) {
    String[] s = key.split("/");
    Path path = Paths.get(BASE_DIR.getAbsolutePath(), s);
    if (2 <= s.length) {
        File parent = path.getParent().toFile();
        parent.mkdirs();/* w w  w . jav a  2 s  .  co m*/
    }

    OutputStream out = null;
    try {
        out = new FileOutputStream(path.toFile());

        byte[] buf = new byte[1024];
        int size = -1;
        while (-1 != (size = stream.read(buf, 0, 1024))) {
            out.write(buf, 0, size);
        }

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (null != out) {
            try {
                out.close();
            } catch (IOException ex) {

            }
        }
        if (null != stream) {
            try {
                stream.close();
            } catch (IOException ex) {

            }
        }
    }
}

From source file:org.hara.sodra.utils.SodraUtilsTest.java

@Test
public void testCopySolrConfigs() throws IOException {
    Path solrHome = SodraUtils.getSolrHome();
    Path solrTemplateConfDir = Paths.get(solrHome.getParent().toString(), "index_template_config");
    Path toTemplateConfDir = Paths.get(TEST_SODRA_HOME, "index_template_config_to");
    SodraUtils.copySolrConfigs(solrTemplateConfDir, toTemplateConfDir);
    assertTrue(toTemplateConfDir.toFile().exists());
    assertEquals(toTemplateConfDir.toFile().list().length, 1);
}

From source file:org.sakuli.services.forwarder.AbstractTemplateOutputBuilderTest.java

@Test(dataProvider = "getTemplatePathDP")
public void getTemplatePath(String converterName, String expectedTemplate) throws Exception {
    // to ensure file exists
    String expectedTemplatePath = tmp_output_builder_test.toString() + File.separator + expectedTemplate;
    Path expectedFile = Paths.get(expectedTemplatePath);
    Files.createDirectory(expectedFile.getParent());
    Files.createFile(expectedFile);

    doReturn(tmp_output_builder_test.toString()).when(sakuliProperties).getForwarderTemplateFolder();
    doReturn(converterName).when(testling).getConverterName();
    assertEquals(testling.getTemplatePath().toString(), expectedTemplatePath);
}

From source file:org.apache.beam.sdk.io.LocalResourceId.java

@Override
public LocalResourceId getCurrentDirectory() {
    if (isDirectory) {
        return this;
    } else {/*from w  ww . j  a va  2 s.com*/
        Path path = getPath();
        Path parent = path.getParent();
        if (parent == null && path.getNameCount() == 1) {
            parent = Paths.get(".");
        }
        checkState(parent != null, "Failed to get the current directory for path: [%s].", pathString);
        return fromPath(parent, true /* isDirectory */);
    }
}

From source file:com.netflix.spinnaker.halyard.config.config.v1.AtomicFileWriter.java

public AtomicFileWriter(Path path) throws IOException {
    FileSystem defaultFileSystem = FileSystems.getDefault();
    this.path = path;
    path.getParent().toFile().mkdir();
    String tmpDir = System.getProperty("java.io.tmpdir");
    this.tmpPath = defaultFileSystem.getPath(tmpDir, UUID.randomUUID().toString());
    this.writer = Files.newBufferedWriter(this.tmpPath, UTF_8, WRITE, APPEND, CREATE);
}

From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java

private File parentFolder(Path pagePath) {
    return pagePath.getParent().toFile();
}

From source file:com.autoupdater.server.services.FileServiceImp.java

@Override
public void saveFile(String storagePath, byte[] content) throws IOException {
    logger.debug("Attempting to save File: " + storagePath);
    Path path = Paths.get(storagePath);
    Files.createDirectories(path.getParent());
    Files.createFile(path);/* w w w  .  j av  a  2 s .  c om*/
    FileOutputStream fos;
    fos = new FileOutputStream(new File(storagePath));
    fos.write(content);
    fos.close();
    logger.debug("Saved File: " + storagePath);
}

From source file:alliance.docs.DocumentationTest.java

private Path getPath() throws URISyntaxException {
    Path testPath = Paths.get(this.getClass().getResource(EMPTY_STRING).toURI());
    Path targetDirectory = testPath.getParent().getParent().getParent();
    return Paths.get(targetDirectory.toString()).resolve(DOCS_DIRECTORY).resolve(HTML_DIRECTORY);
}

From source file:org.cryptomator.ui.settings.SettingsProvider.java

private void save(Settings settings) {
    Objects.requireNonNull(settings);
    try {
        final Path settingsPath = getSettingsPath();
        Files.createDirectories(settingsPath.getParent());
        final OutputStream out = Files.newOutputStream(settingsPath, StandardOpenOption.WRITE,
                StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
        objectMapper.writeValue(out, settings);
        LOG.info("Settings saved to " + settingsPath);
    } catch (IOException e) {
        LOG.error("Failed to save settings.", e);
    }//ww w.  j av  a 2s.  c  o  m
}