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:org.wte4j.ui.server.services.TemplateServiceIntegrationTest.java

@Test
public void createTemplateWithFile() throws URISyntaxException {
    TemplateDto dto = new TemplateDto();
    dto.setDocumentName("test");
    dto.setLanguage("en");
    dto.setInputType(TemplateDto.class.getName());

    MappingDto mappingDto = new MappingDto();
    mappingDto.setContentControlKey("template");
    mappingDto.setModelKey("documentName");

    dto.getMapping().add(mappingDto);//from   w  w  w .ja  va 2s.  com

    Path filePath = Paths.get(getClass().getResource("template.docx").toURI());

    TemplateDto created = templateService.createTemplate(dto, filePath.toString());

    assertNotNull(created);
    Template<TemplateDto> templateCreated = engine.getTemplateRepository().getTemplate("test", "en",
            TemplateDto.class);
    assertNotNull(templateCreated);
}

From source file:gr.upatras.ece.nam.baker.impl.InstalledBunLifecycleMgmt.java

private void startPackageDownloading() {
    logger.info("Downloading installation package: " + bunMetadata.getPackageLocation());

    Path destFile = repoWebClient.fetchPackageFromLocation(installedBun.getUuid(),
            bunMetadata.getPackageLocation());

    if ((destFile != null) && (extractPackage(destFile) == 0)) {
        installedBun.setStatus(InstalledBunStatus.DOWNLOADED);
        Path packageLocalPath = destFile.getParent();
        installedBun.setPackageLocalPath(packageLocalPath.toString());
    } else {/*from w ww .  j a  v  a  2 s. c  o  m*/
        logger.info("FAILED Downloading installation package from: " + bunMetadata.getPackageLocation());
        installedBun.setStatus(InstalledBunStatus.FAILED);
    }

}

From source file:com.spectralogic.ds3client.metadata.MetadataAccessImpl_Test.java

@Test
public void testMetadataAccessFailureHandler() throws IOException, InterruptedException {
    Assume.assumeFalse(Platform.isWindows());

    try {/* w w w.  j ava2s  . c o  m*/
        final String tempPathPrefix = null;
        final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

        final String fileName = "Gracie.txt";

        final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName));

        try {
            tempDirectory.toFile().setExecutable(false);

            final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder();

            fileMapper.put(filePath.toString(), filePath);
            new MetadataAccessImpl(fileMapper.build()).getMetadataValue(filePath.toString());
        } finally {
            tempDirectory.toFile().setExecutable(true);
            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    } catch (final Throwable t) {
        fail("Throwing exceptions from metadata est verbotten");
    }
}

From source file:com.twentyn.bioreactor.sensors.Sensor.java

private void setupFiles(String sensorReadingPath) {
    String logFilename = deviceName.concat(LOG_EXTENSION);
    Path sensorReadingDirectory = Paths.get(sensorReadingPath, sensorData.getDeviceType());
    this.sensorReadingFilePath = Paths.get(sensorReadingDirectory.toString(), deviceName);
    this.sensorReadingLogFilePath = Paths.get(sensorReadingDirectory.toString(), logFilename);
    if (!Files.exists(sensorReadingDirectory)) {
        Boolean madeDir = sensorReadingDirectory.toFile().mkdirs();
        if (!madeDir) {
            LOGGER.error("The following directory could not be accessed or created: %s",
                    sensorReadingDirectory);
        }/*  ww  w  .ja  v a2 s .  c o m*/
    }
    try {
        this.jsonGenerator = objectMapper.getFactory()
                .createGenerator(new File(sensorReadingLogFilePath.toString()), JsonEncoding.UTF8);
        this.sensorReadingTmp = File.createTempFile(sensorReadingFilePath.toString(), ".tmp");
    } catch (IOException e) {
        LOGGER.error("Error during reading/log files creation: %s", e);
        System.exit(1);
    }
}

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

@Before
public void before() throws LifecycleException, IOException {

    tomcat = new Tomcat();
    tomcat.setBaseDir(tempDir.toString());
    tomcat.getHost().setAppBase(tempDir.toString());
    tomcat.getHost().setAutoDeploy(true);
    tomcat.getHost().setDeployOnStartup(true);

    final Connector connector = new Connector(protocol.getProto());

    if (executor != null) {
        connector.setAttribute("executor", executor);
    }/*from   w w w. j av  a 2  s.c om*/
    connector.setAttribute("address", "localhost");
    connector.setPort(0);
    tomcat.setConnector(connector);
    tomcat.getService().addConnector(connector);

    tomcat.start();

    final Path root = Files.createDirectory(tempDir.resolve("ROOT"));
    final Context rootContext = tomcat.addContext("/", root.toString());
    for (final Entry<String, Servlet> entry : servlets.entrySet()) {
        Tomcat.addServlet(rootContext, entry.getValue().toString(), entry.getValue())
                .addMapping(entry.getKey());
        logger.info(getUri() + entry.getKey() + " => " + entry.getValue());
    }
}

From source file:com.spectralogic.ds3client.metadata.MetadataAccessImpl_Test.java

@Test
public void testMetadataAccessFailureHandlerWithEventHandler() throws IOException, InterruptedException {
    Assume.assumeFalse(Platform.isWindows());

    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

    final String fileName = "Gracie.txt";

    final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName));

    try {//from  w  w  w  .  j  av  a2 s  .c  o  m
        tempDirectory.toFile().setExecutable(false);

        final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder();

        fileMapper.put(filePath.toString(), filePath);

        final AtomicInteger numTimesFailureHandlerCalled = new AtomicInteger(0);

        try (final InputStream inputStream = Runtime.getRuntime().exec("ls -lR").getInputStream()) {
            LOG.info(IOUtils.toString(inputStream));
        }
        new MetadataAccessImpl(fileMapper.build(), new FailureEventListener() {
            @Override
            public void onFailure(final FailureEvent failureEvent) {
                numTimesFailureHandlerCalled.incrementAndGet();
                assertEquals(FailureEvent.FailureActivity.RecordingMetadata, failureEvent.doingWhat());
            }
        }, "localhost").getMetadataValue("forceAFailureByUsingANonExistentFileBecauseTheDockerImageRunsAsRoot");

        assertEquals(1, numTimesFailureHandlerCalled.get());
    } finally {
        tempDirectory.toFile().setExecutable(true);
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

From source file:com.movilizer.mds.webservice.services.UploadFileService.java

private String getSuffixFromFilename(Path filename) {
    if (filename == null) {
        throw new MovilizerWebServiceException(String.format(Messages.MISSING_FILE_EXTENSION, "null filename"));
    }// ww w .  j av a 2  s.  co m
    return getSuffixFromFilename(filename.toString());
}

From source file:misc.FileHandler.java

/**
 * Returns a temporary file path that is on the same file store as the given
 * file. The temporary file is created without content, if the given file's
 * file store is identical to the system's default temporary directory file
 * store.//from  ww w.  j  a  v a2 s  . c  o m
 * 
 * @param target
 *            the file which determines the file store.
 * @return the path of the temporary file or <code>null</code>, if an error
 *         occurred.
 */
public static Path getTempFile(Path target) {
    Path tempFile = null;
    boolean success = false;

    target = target.normalize();

    try {
        Path targetDirectory = target.toAbsolutePath().getParent();
        tempFile = Files.createTempFile(target.getFileName().toString(), TEMP_FILE_SUFFIX);

        if (!Files.getFileStore(tempFile).equals(Files.getFileStore(targetDirectory))) {
            // the temporary file should be in the target directory.
            Files.delete(tempFile);
            tempFile = Paths.get(targetDirectory.toString(), tempFile.getFileName().toString());
            success = true;
        } else {
            success = true;
        }
    } catch (IOException e) {
        Logger.logError(e);
    } finally {
        if (!success && (tempFile != null)) {
            try {
                Files.deleteIfExists(tempFile);
            } catch (IOException innerE) {
                Logger.logError(innerE);
            }
        }
    }

    return success ? tempFile : null;
}

From source file:br.com.thiaguten.archive.ZipArchive.java

/**
 * Override to make use of the ZipFile class instead of the ZipArchiveInputStream class.
 * https://commons.apache.org/proper/commons-compress/zip.html
 *//*  w  w w . j a v a 2  s .  c o m*/
@Override
public Path decompress(Path path) throws IOException {
    Path decompressDir = removeExtension(path);

    logger.debug("reading archive file " + path);

    try (ZipFile zipFile = new ZipFile(path.toString())) {

        // creates a new decompress folder to not override if already exists
        // if you do not want this behavior, just comment this line
        decompressDir = createFile(ArchiveAction.DECOMPRESS, decompressDir.getParent(), decompressDir);

        createDirectories(decompressDir);

        logger.debug("creating the decompress destination directory " + decompressDir);

        Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
        while (entries.hasMoreElements()) {
            final ZipArchiveEntry zipArchiveEntry = entries.nextElement();

            if (zipFile.canReadEntryData(zipArchiveEntry)) {
                final String entryName = zipArchiveEntry.getName();
                final InputStream archiveInputStream = zipFile.getInputStream(zipArchiveEntry);
                final Path target = Paths.get(decompressDir.toString(), entryName);
                final Path parent = target.getParent();

                if (parent != null && !exists(parent)) {
                    createDirectories(parent);
                }

                logger.debug("reading compressed path " + entryName);

                if (!zipArchiveEntry.isDirectory()) {
                    try (OutputStream outputStream = new BufferedOutputStream(newOutputStream(target))) {

                        logger.debug("writting compressed " + entryName + " file in the decompress directory");

                        //                            byte[] content = new byte[(int) zipArchiveEntry.getSize()];
                        //                            outputStream.write(content);
                        IOUtils.copy(archiveInputStream, outputStream);
                    }
                }
            }
        }

        logger.debug("finishing the decompress in the directory: " + decompressDir);

    }

    return decompressDir;
}

From source file:com.serena.rlc.provider.filesystem.client.FilesystemClient.java

public void localExec(String execScript, String execDir, String execParams, boolean ignoreErrors)
        throws FilesystemClientException {
    Path script = Paths.get(execDir + File.separatorChar + execScript);

    try {//from w w w.  j a va 2  s. c o  m
        if (!Files.exists(script)) {
            if (ignoreErrors) {
                logger.debug("Execution script " + script.toString() + " does not exist, ignoring...");
            } else {
                throw new FilesystemClientException(
                        "Execution script " + script.toString() + " does not exist");
            }
        } else {
            ProcessBuilder pb = new ProcessBuilder(script.toString());
            pb.directory(new File(script.getParent().toString()));
            System.out.println(pb.directory().toString());
            logger.debug("Executing script " + execScript + " in directory " + execDir + " with parameters: "
                    + execParams);
            Process p = pb.start(); // Start the process.
            p.waitFor(); // Wait for the process to finish.
            logger.debug("Executed script " + execScript + " successfully.");
        }
    } catch (Exception e) {
        logger.debug(e.getLocalizedMessage());
        throw new FilesystemClientException(e.getLocalizedMessage());
    }

}