Example usage for java.nio.file Path toUri

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

Introduction

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

Prototype

URI toUri();

Source Link

Document

Returns a URI to represent this path.

Usage

From source file:com.sandeep.prototypes.address.AddressApplication.java

/**
 * <p>//from   w ww . j a  v  a  2s. co m
 * In this method we are initializing the Archaius configuration manager to load configurations
 * from a properties file.
 * 
 * The steps to initializing the configuration is as follows
 * <ul>
 * <li>Create a configuration source for the file which contains the properties</li>
 * <li>Create a dynamic configuration around the source so that the source is polled, the polling
 * can be configured to be at a different frequency</li>
 * </ul>
 * 
 * @return DynamicConfiguration
 * @throws ConfigurationException
 * @throws MalformedURLException
 */
private DynamicConfiguration getPropertiesConfiguration() throws ConfigurationException, MalformedURLException {
    String userHome = System.getProperty("user.home");
    Path properties = Paths.get(userHome, "config-root", "address", "address.properties");
    PolledConfigurationSource polledSource = new URLConfigurationSource(properties.toUri().toURL());
    return new DynamicConfiguration(polledSource, new FixedDelayPollingScheduler());
}

From source file:org.bimserver.plugins.classloaders.EclipsePluginClassloader.java

@Override
public URL findResource(String name) {
    Path file = projectFolder.resolve(name);
    if (Files.exists(file)) {
        try {// ww w  .  j a va  2s  . co m
            return file.toUri().toURL();
        } catch (MalformedURLException e) {
            LOGGER.error("", e);
        }
    }
    return null;
}

From source file:org.apache.hadoop.security.ssl.HopsSSLTestUtils.java

private void purgeFiles(List<Path> files) throws Exception {
    File file;/*from ww w  . ja  va2  s  .  co m*/
    for (Path path : files) {
        file = new File(path.toUri());
        if (file.exists()) {
            file.delete();
        }
    }
}

From source file:org.sakuli.services.forwarder.gearman.GearmanCacheService.java

/**
 * Writes results to Gearman cache file.
 * @param results/*w ww. j  a  va2s.co m*/
 */
public void cacheResults(List<NagiosCheckResult> results) {
    Path cacheFile = testSuiteProperties.getTestSuiteFolder().resolve(CACHE_FILE);
    File output = new File(cacheFile.toUri());
    if (!output.getParentFile().exists()) {
        output.getParentFile().mkdirs();
    }

    try (FileOutputStream fos = new FileOutputStream(output)) {
        for (NagiosCheckResult result : results) {
            fos.write((CACHE_SEPARATOR + " " + result.getQueueName() + ":" + result.getUuid() + LINE_SEPARATOR)
                    .getBytes(CHARSET_NAME));
            fos.write((result.getPayloadString().trim() + LINE_SEPARATOR).getBytes(CHARSET_NAME));
            fos.write((CACHE_SEPARATOR + LINE_SEPARATOR).getBytes(CHARSET_NAME));
        }

        if (results.isEmpty()) {
            fos.write(LINE_SEPARATOR.getBytes(CHARSET_NAME));
        }

        fos.flush();
    } catch (IOException e) {
        exceptionHandler.handleException(new SakuliForwarderException(e, "Failed to write Gearman cache file"),
                true);
    }
}

From source file:com.sandeep.prototypes.person.PersonApplication.java

/**
 * <p>/*  w w w  . ja  v  a 2  s. c  om*/
 * In this method we are initializing the Archaius configuration manager to load configurations
 * from a properties file.
 * 
 * The steps to initializing the configuration is as follows
 * <ul>
 * <li>Create a configuration source for the file which contains the properties</li>
 * <li>Create a dynamic configuration around the source so that the source is polled, the polling
 * can be configured to be at a different frequency</li>
 * </ul>
 * 
 * @return DynamicConfiguration
 * @throws ConfigurationException
 * @throws MalformedURLException
 */
private DynamicConfiguration getPropertiesConfiguration() throws ConfigurationException, MalformedURLException {
    String userHome = System.getProperty("user.home");
    Path properties = Paths.get(userHome, "config-root", "person", "person.properties");
    PolledConfigurationSource polledSource = new URLConfigurationSource(properties.toUri().toURL());
    return new DynamicConfiguration(polledSource, new FixedDelayPollingScheduler());
}

From source file:br.com.uol.runas.classloader.JarClassLoader.java

private void addUrlsFromDir(URL url) throws IOException, URISyntaxException {
    addURL(url);//from w  w w. j  a  v a2 s  . co m

    Files.walkFileTree(Paths.get(url.toURI()), new FileVisitor<Path>() {
        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            addURL(dir.toUri().toURL());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            addURL(file.toUri().toURL());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:org.bonitasoft.web.designer.workspace.WorkspaceTest.java

private void mockWidgetsBasePath(Path path) throws IOException {
    Resource resource = mock(Resource.class);
    when(resource.getURI()).thenReturn(path.toUri());
    when(resourceLoader.getResource(WebMvcConfiguration.WIDGETS_RESOURCES)).thenReturn(resource);
}

From source file:org.apache.taverna.robundle.manifest.PathMetadata.java

public void setFile(Path file) {
    this.file = file;
    Path root = this.file.resolve("/");
    URI uri = ROOT.resolve(root.toUri().relativize(file.toUri()));
    setUri(uri);//ww  w  . j  a va  2s  . c  o m
}

From source file:org.apache.impala.infra.tableflattener.SchemaFlattener.java

private URI createDir(String name) {
    try {/*from w w w .  j av  a  2 s . c o  m*/
        switch (outputDir_.getScheme().toUpperCase()) {
        case "FILE": {
            Path datasetPath = Paths.get(outputDir_).resolve(name);
            datasetPath.toFile().mkdirs();
            return datasetPath.toUri();
        }
        case "HDFS": {
            org.apache.hadoop.fs.Path outputDirPath = new org.apache.hadoop.fs.Path(outputDir_);
            org.apache.hadoop.fs.Path datasetPath = new org.apache.hadoop.fs.Path(outputDirPath, name);
            outputDirPath.getFileSystem(new Configuration()).mkdirs(datasetPath);
            return datasetPath.toUri();
        }
        default:
            throw new NotImplementedException(
                    String.format("Unexpected output dir scheme: %s", outputDir_.getScheme()));
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.seleritycorp.common.base.http.client.FileHttpClientTest.java

@Test
public void testExecuteGetNotFound() throws Exception {
    Path tmpFile = this.createTempDirectory();

    replayAll();/*ww  w  .  j a  v  a 2 s .  com*/

    HttpClient httpClient = createFileHttpClient();
    HttpGet method = new HttpGet(tmpFile.toUri().toString() + "/foo");
    org.apache.http.HttpResponse response = httpClient.execute(method);
    HttpEntity entity = response.getEntity();

    verifyAll();

    assertThat(response.getStatusLine().getProtocolVersion().getProtocol()).isEqualTo("FILE");
    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(404);
    assertThat(response.getStatusLine().getReasonPhrase()).isEqualTo("Not Found");

    assertThat(entity).isNull();
}