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.ecofactor.qa.automation.platform.ops.impl.IOSOperations.java

/**
 * Take screen shot./*  www  .java 2  s . c o  m*/
 * @param fileNames the file names
 * @throws DeviceException the device exception
 * @see com.ecofactor.qa.automation.mobile.ops.impl.AbstractDriverOperations#takeScreenShot(java.lang.String[])
 */
@Override
public void takeScreenShot(final String... fileNames) throws DeviceException {

    if (isTaken) {
        try {
            final JavascriptExecutor jsExecutor = (JavascriptExecutor) getDeviceDriver();
            final HashMap<String, String> execObject = new HashMap<String, String>();
            final Path screenShotFile = getTargetScreenshotPath(fileNames);
            execObject.put("file", screenShotFile.toString());
            jsExecutor.executeScript("mobile: localScreenshot", execObject);
        } catch (final Exception e) {
            isTaken = false;
            LOGGER.error("ERROR taking screenshot for " + fileNames, e);
            stopAppiumServer();
            smallWait();
            startAppiumServer();
            loadDeviceDriver();
            smallWait();
            switchToWebView();
        }
    }
}

From source file:com.sumzerotrading.intraday.trading.strategy.ReportGeneratorTest.java

@Test
public void testWriteRoundTrip() throws Exception {
    Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt");
    reportGenerator.outputFile = path.toString();
    String expected = "2016-03-19T07:01:10,LONG,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0";

    Ticker longTicker = new StockTicker("ABC");
    Ticker shortTicker = new StockTicker("XYZ");
    int longSize = 100;
    int shortSize = 50;
    double longEntryFillPrice = 100.23;
    double longExitFillPrice = 101.23;
    ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault());
    ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault());

    TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY);
    longEntry.setFilledPrice(longEntryFillPrice);
    longEntry.setOrderFilledTime(entryTime);
    TradeReferenceLine entryLine = new TradeReferenceLine();
    entryLine.correlationId = "123";
    entryLine.direction = Direction.LONG;
    entryLine.side = Side.ENTRY;//from   w  w  w .  ja va  2 s .  c  o m

    TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL);
    longExit.setFilledPrice(longExitFillPrice);
    longExit.setOrderFilledTime(exitTime);
    TradeReferenceLine exitLine = new TradeReferenceLine();
    exitLine.correlationId = "123";
    exitLine.direction = LONG;
    exitLine.side = Side.EXIT;

    RoundTrip roundTrip = new RoundTrip();
    roundTrip.addTradeReference(longEntry, entryLine);
    roundTrip.addTradeReference(longExit, exitLine);

    System.out.println("Writing out to file: " + path);

    reportGenerator.writeRoundTripToFile(roundTrip);

    List<String> lines = Files.readAllLines(path);
    assertEquals(1, lines.size());
    assertEquals(expected, lines.get(0));

    Files.deleteIfExists(path);

}

From source file:io.cloudslang.lang.tools.build.tester.parallel.report.SlangTestCaseRunReportGeneratorService.java

private void copyResourceFromClasspath(String reportDirectory, Path relativePathSource, Path relativePathDest)
        throws IOException {
    File destination = Paths.get(reportDirectory).resolve(relativePathDest).toFile();
    InputStream sourceStream = new DefaultResourceLoader()
            .getResource(CLASSPATH + relativePathSource.toString()).getInputStream();
    // overwrite if exists
    FileUtils.copyInputStreamToFile(sourceStream, destination);
}

From source file:com.netscape.cmstools.profile.ProfileEditCLI.java

public void execute(String[] args) throws Exception {
    // Always check for "--help" prior to parsing
    if (Arrays.asList(args).contains("--help")) {
        printHelp();//from w ww  .  j av  a2  s .c om
        return;
    }

    CommandLine cmd = parser.parse(options, args);

    String[] cmdArgs = cmd.getArgs();

    if (cmdArgs.length < 1) {
        throw new Exception("No Profile ID specified.");
    }

    String profileId = cmdArgs[0];

    ProfileClient profileClient = profileCLI.getProfileClient();

    // read profile into temporary file
    byte[] orig = profileClient.retrieveProfileRaw(profileId);
    ProfileCLI.checkConfiguration(orig, false /* requireProfileId */, true /* requireDisabled */);
    Path tempFile = Files.createTempFile("pki", ".cfg");

    try {
        Files.write(tempFile, orig);

        // invoke editor on temporary file
        String editor = System.getenv("EDITOR");
        String[] command;
        if (editor == null || editor.trim().isEmpty()) {
            command = new String[] { "/usr/bin/env", "vi", tempFile.toString() };
        } else {
            command = new String[] { editor.trim(), tempFile.toString() };
        }
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.inheritIO();
        int exitCode = pb.start().waitFor();
        if (exitCode != 0) {
            throw new Exception("Exited abnormally.");
        }

        // read data from temporary file and modify if changed
        byte[] cur = ProfileCLI.readRawProfileFromFile(tempFile);
        if (!Arrays.equals(cur, orig)) {
            profileClient.modifyProfileRaw(profileId, cur);
        }
        System.out.write(cur);
    } finally {
        Files.delete(tempFile);
    }
}

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

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

    try {//w  w w  . j  av  a 2  s . com
        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 {
            // get permissions
            final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder();
            fileMapper.put(filePath.toString(), filePath);
            final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build())
                    .getMetadataValue(filePath.toString());

            FileUtils.deleteDirectory(tempDirectory.toFile());

            // put old permissions back
            final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile));

            new MetadataReceivedListenerImpl(tempDirectory.toString()).metadataReceived(fileName, metadata);
        } finally {
            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    } catch (final Throwable t) {
        fail("Throwing exceptions from metadata est verbotten");
    }
}

From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallTask.java

/**
 * Installation//from w w  w  . j  a va2 s. c om
 *
 * @param task
 * @throws
 * com.github.ffremont.microservices.springboot.node.exceptions.InvalidInstallationException
 * @throws
 * com.github.ffremont.microservices.springboot.node.exceptions.FailCreateMsException
 */
@Override
public void run(MicroServiceTask task)
        throws InvalidInstallationException, FailCreateMsException, TaskException {
    LOG.info("Installation du micro service {}...", task.getMs().getName());
    Path msVersionFolder = helper.targetDirOf(task.getMs());
    LOG.debug("Rpertoire d'installation {}", msVersionFolder);

    try {
        if (Files.notExists(msVersionFolder)) {
            Files.createDirectories(msVersionFolder);
            LOG.debug("Rpertoire cr");
        }

        // vrification du CHECKSUM
        Path checksumPath = Paths.get(msVersionFolder.toString(), CHECKSUM_FILE_NAME + ".txt");

        if (Files.exists(checksumPath)) {
            LOG.debug("Checksum rcupr {}", checksumPath);
            if (!task.getMs().getSha1().equals(new String(Files.readAllBytes(checksumPath)))) {
                throw new InvalidInstallationException("Le checksum n'est pas valide : " + this.nodeBase);
            }
        } else {
            installJarTask.run(task);
        }

        installPropTask.run(task);
    } catch (IOException ex) {
        LOG.warn("Anomalie non prvue lors de l'installation", ex);
        throw new FailCreateMsException("Installation impossible", ex);
    }

    LOG.info("Micro service {} install", task.getMs().getName());
}

From source file:eu.forgetit.middleware.cmis.CmisRepositoryManager.java

public final Path getObjectStream(String cmisId, Path destPath, String fileName) throws IOException {

    Path streamPath = null;//from  w  ww .  ja  va2 s  .  c  o m

    Document document = (Document) session.getObject(cmisId);

    ContentStream contentStream = document.getContentStream();

    if (contentStream != null) {

        if (fileName == null)
            fileName = contentStream.getFileName();

        streamPath = Paths.get(destPath.toString(), fileName);

        File streamFile = new File(streamPath.toString());

        InputStream inputStream = contentStream.getStream();

        FileUtils.copyInputStreamToFile(inputStream, streamFile);

    }

    return streamPath;

}

From source file:de.elomagic.carafile.client.CaraCloud.java

public Set<CloudFileData> list(final Path remotePath) throws IOException {
    LOG.debug("List remote folder \"" + remotePath + "\" file at " + client.getRegistryURI());

    URI uri = CaraFileUtils.buildURI(client.getRegistryURI(), "cloud", "list", remotePath.toString());
    HttpResponse response = client.executeRequest(Request.Get(uri)).returnResponse();

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new IOException("HTTP responce code " + response.getStatusLine().getStatusCode() + " "
                + response.getStatusLine().getReasonPhrase());
    }//from   ww w . j a va 2 s  .  com

    Charset charset = ContentType.getOrDefault(response.getEntity()).getCharset();

    Set<CloudFileData> set = JsonUtil.read(new InputStreamReader(response.getEntity().getContent(), charset),
            Set.class);

    LOG.debug("Folder contains " + set.size() + " item(s)");

    return set;
}

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

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

    try {//from www  . j  ava2  s . co 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 {
            // get permissions
            final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder();
            fileMapper.put(filePath.toString(), filePath);
            final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build())
                    .getMetadataValue(filePath.toString());

            FileUtils.deleteDirectory(tempDirectory.toFile());

            // put old permissions back
            final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile));

            final AtomicInteger numTimesFailureHandlerCalled = new AtomicInteger(0);

            new MetadataReceivedListenerImpl(tempDirectory.toString(), new FailureEventListener() {
                @Override
                public void onFailure(final FailureEvent failureEvent) {
                    numTimesFailureHandlerCalled.incrementAndGet();
                    assertEquals(FailureEvent.FailureActivity.RestoringMetadata, failureEvent.doingWhat());
                }
            }, "localhost").metadataReceived(fileName, metadata);

            assertEquals(1, numTimesFailureHandlerCalled.get());
        } finally {
            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    } catch (final Throwable t) {
        fail("Throwing exceptions from metadata est verbotten");
    }
}

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

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

    try {/*from   ww w .jav a  2  s.  co 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 {
            // set permissions
            if (!Platform.isWindows()) {
                final PosixFileAttributes attributes = Files.readAttributes(filePath,
                        PosixFileAttributes.class);
                final Set<PosixFilePermission> permissions = attributes.permissions();
                permissions.clear();
                permissions.add(PosixFilePermission.OWNER_READ);
                permissions.add(PosixFilePermission.OWNER_WRITE);
                Files.setPosixFilePermissions(filePath, permissions);
            }

            // get permissions
            final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder();
            fileMapper.put(filePath.toString(), filePath);
            final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build())
                    .getMetadataValue(filePath.toString());

            FileUtils.deleteDirectory(tempDirectory.toFile());

            // put old permissions back
            final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile));

            new MetadataReceivedListenerImpl(tempDirectory.toString()).metadataReceived(fileName, metadata);
        } finally {
            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    } catch (final Throwable t) {
        fail("Throwing exceptions from metadata est verbotten");
    }
}