Example usage for java.io File toPath

List of usage examples for java.io File toPath

Introduction

In this page you can find the example usage for java.io File toPath.

Prototype

public Path toPath() 

Source Link

Document

Returns a Path java.nio.file.Path object constructed from this abstract path.

Usage

From source file:com.ontotext.s4.service.S4ServiceClientIntegrationTest.java

@Test
public void testClassifyFileContentsAsStreamUrlClient() throws Exception {
    ServiceDescriptor temp = ServicesCatalog.getItem("news-classifier");
    S4ServiceClient client = new S4ServiceClient(temp, testApiKeyId, testApiKeyPass);
    serializationFormat = ResponseFormat.JSON;
    File f = new File("test-file");
    try {//  ww  w  .j  av  a2 s. c  o m
        Path p = f.toPath();
        ArrayList<String> lines = new ArrayList<>(1);
        lines.add(documentText);
        Files.write(p, lines, Charset.forName("UTF-8"), StandardOpenOption.CREATE);

        InputStream result = client.annotateFileContentsAsStream(f, Charset.forName("UTF-8"),
                SupportedMimeType.PLAINTEXT, serializationFormat);
        StringWriter writer = new StringWriter();
        IOUtils.copy(result, writer, Charset.forName("UTF-8"));

        assertTrue(writer.toString().contains("category"));
        assertTrue(writer.toString().contains("allScores"));
    } finally {
        f.delete();
    }
}

From source file:com.thoughtworks.go.server.websocket.ConsoleLogSenderTest.java

private File makeConsoleFile(String message) throws IOException, IllegalArtifactLocationException {
    File console = File.createTempFile("console", ".log");
    console.deleteOnExit();/*ww w  .  ja  v  a 2 s . c om*/
    when(consoleService.consoleLogFile(jobIdentifier)).thenReturn(console);

    Files.write(console.toPath(), message.getBytes());
    return console;
}

From source file:com.caricah.iotracah.bootstrap.system.handler.impl.DefaultConfigHandler.java

private Path getConfigurationFileInDirectory(String directory) throws IOException {

    String configFileName = getConfigurationFileName();

    File configFile = new File(directory + File.separator + configFileName);
    if (configFile.exists()) {

        log.debug(" getConfigurationFileInDirectory : matched file {} in config directory {}.", configFileName,
                directory);//ww  w .java  2 s .c  o  m
        return configFile.toPath();

    }
    return null;
}

From source file:com.fizzed.blaze.ssh.SshExec.java

@Override
public SshExec command(File command) {
    ObjectHelper.requireNonNull("command", "command cannot be null");
    this.command = command.toPath();
    return this;
}

From source file:hudson.UtilSEC904Test.java

@Test
public void resolveSymlinkToFile() throws Exception {
    //  root/*from ww w. j a v a2s. c  o  m*/
    //      /a
    //          /aa
    //              aa.txt
    //          /_b => symlink to /root/b
    //      /b
    //          /_a => symlink to /root/a
    File root = tmp.getRoot();
    File a = new File(root, "a");
    File aa = new File(a, "aa");
    aa.mkdirs();
    File aaTxt = new File(aa, "aa.txt");
    FileUtils.write(aaTxt, "aa");

    File b = new File(root, "b");
    b.mkdir();

    File _a = new File(b, "_a");
    Util.createSymlink(_a.getParentFile(), a.getAbsolutePath(), _a.getName(), TaskListener.NULL);

    File _b = new File(a, "_b");
    Util.createSymlink(_b.getParentFile(), b.getAbsolutePath(), _b.getName(), TaskListener.NULL);

    assertTrue(Files.isSymbolicLink(_a.toPath()));
    assertTrue(Files.isSymbolicLink(_b.toPath()));

    // direct symlinks are resolved
    assertEquals(Util.resolveSymlinkToFile(_a), a);
    assertEquals(Util.resolveSymlinkToFile(_b), b);

    // intermediate symlinks are NOT resolved
    assertNull(Util.resolveSymlinkToFile(new File(_a, "aa")));
    assertNull(Util.resolveSymlinkToFile(new File(_a, "aa/aa.txt")));
}

From source file:ch.sourcepond.maven.plugin.jenkins.config.ConfigBuilderImpl.java

@Override
public ConfigBuilder setStdin(final File pStdin) {
    if (pStdin != null) {
        config.setStdin(pStdin.toPath());
    }/*from   ww  w  . java 2s .  c om*/
    return this;
}

From source file:com.msopentech.ThaliClient.ProxyDesktop.java

public void initialize() throws URISyntaxException, IOException {
    // Initialize the relay - We find the root directory of the install and navigate down to the web directory
    File rootDirectoryOfInstall = new File(
            getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
    String webPath = "web"; // For production
    //String webPath = "install/Java/web"; // For debugging from inside of intelliJ
    File webDirectory = rootDirectoryOfInstall.toPath().getParent().getParent().resolve(webPath).toFile();
    if (webDirectory.exists() == false) {
        throw new RuntimeException(
                "Either the web directory wasn't installed or we have the wrong location or you are debugging AND DIDN'T READ THE README.md!!!!!!!! - "
                        + webDirectory.getAbsolutePath());
    }/*from   ww w  .  j  a v  a 2  s. co  m*/

    // Useful for debugging
    // webPath = new File(new File(System.getProperty("user.dir")).getParent(), "web").toPath();

    // This is sleezy, we should really have a function that gets us the httpkeys file and share that
    // function with the Java TDH but I really don't want to put in a cross project dependency to share
    // a few strings.
    File httpKeysFileDirectory = new File(System.getProperty("user.home"), ".thaliTdh");
    File httpKeysFile = new File(httpKeysFileDirectory, "httpkeys");
    if (httpKeysFile.exists() == false) {
        throw new RuntimeException("We can't find the httpkeys file! Someone start up the TDH!!!!");
    }
    ObjectMapper mapper = new ObjectMapper();
    HttpKeyTypes httpKeyTypes = mapper.readValue(httpKeysFile, HttpKeyTypes.class);

    try {
        server = new RelayWebServer(new JavaEktorpCreateClientBuilder(), webDirectory, httpKeyTypes, relayHost,
                relayPort);
    } catch (Exception e) {
        throw new RuntimeException("cannot start relay web server!", e);
    }

    // Initialize the local web server
    System.out.println("Setting web root to: " + webDirectory.getAbsolutePath());
    host = new SimpleWebServer("localhost", localWebserverPort, webDirectory, false);

    // Start both listeners
    try {
        System.out.println("Starting WebServer at http://localhost:" + localWebserverPort);
        host.start();

        System.out.println("Starting Relay on http://" + relayHost + ":" + relayPort);
        server.start();
    } catch (IOException ioe) {
        System.out.println("Exception: " + ioe.toString());
    }
    System.out.println("Started.");
}

From source file:com.itemanalysis.jmetrik.file.JmetrikFileReader.java

public JmetrikFileReader(File f) {
    this.f = f.toPath();
}

From source file:ch.sourcepond.maven.plugin.jenkins.config.ConfigBuilderImpl.java

@Override
public ConfigBuilder setStdout(final File pStdout) {
    if (pStdout != null) {
        config.setStdout(pStdout.toPath());
    }/*from www  .  j  av  a  2  s. com*/
    return this;
}

From source file:ch.eitchnet.csvrestendpoint.components.CsvDataHandler.java

public List<String> getCsvNames() {

    File csvDataDir = getCsvDataDir();
    if (!csvDataDir.isDirectory()) {
        logger.error("CSV Data Dir is not a directory at " + csvDataDir.getAbsolutePath());
        return Collections.emptyList();
    }// w  w  w.  j av  a  2s  . c  om

    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(csvDataDir.toPath())) {

        List<String> names = new ArrayList<>();

        for (Iterator<Path> iter = directoryStream.iterator(); iter.hasNext();) {
            Path path = iter.next();
            String name = path.toFile().getName();
            if (name.endsWith(".csv"))
                names.add(name.substring(0, name.length() - 4));
        }

        return names;

    } catch (Exception e) {
        throw new RuntimeException("Failed to read CSV names due to " + e.getMessage());
    }
}