List of usage examples for java.nio.file Path toUri
URI toUri();
From source file:spdxedit.SpdxLogic.java
private static SpdxFile newSpdxFile(Path file, String baseUri) throws IOException, InvalidSPDXAnalysisException { String checksum = getChecksumForFile(file); FileType[] fileTypes = SpdxLogic.getTypesForFile(file); String relativeFileUrl = StringUtils.removeStart(file.toUri().toString(), baseUri); return new SpdxFile(relativeFileUrl, fileTypes, checksum, new SpdxNoAssertionLicense(), new AnyLicenseInfo[] { new SpdxNoAssertionLicense() }, null, "NOASSERTION", null, null); }
From source file:org.opencb.opencga.storage.core.variant.VariantStorageBaseTest.java
public static URI getResourceUri(String resourceName) throws IOException { Path rootDir = getTmpRootDir(); Path resourcePath = rootDir.resolve(resourceName); if (!resourcePath.getParent().toFile().exists()) { Files.createDirectory(resourcePath.getParent()); }//from ww w. j a va2 s .c o m if (!resourcePath.toFile().exists()) { Files.copy(VariantStorageManagerTest.class.getClassLoader().getResourceAsStream(resourceName), resourcePath, StandardCopyOption.REPLACE_EXISTING); } return resourcePath.toUri(); }
From source file:org.azyva.dragom.test.integration.IntegrationTestSuite.java
/** * Resets the test workspace./*w ww. j a v a2 s .c o m*/ */ public static void resetTestWorkspace() { InputStream inputStreamLoggingProperties; Path pathLoggingProperties; String loggingProperties; System.out.println("Resetting test workspace directory " + IntegrationTestSuite.pathTestWorkspace + '.'); try { LogManager.getLogManager().reset(); if (IntegrationTestSuite.pathTestWorkspace.toFile().exists()) { Path pathModel; InputStream inputStream; pathModel = IntegrationTestSuite.pathTestWorkspace.resolve("simple-model.xml"); inputStream = IntegrationTestSuite.class.getResourceAsStream("/simple-model.xml"); Files.copy(inputStream, pathModel, StandardCopyOption.REPLACE_EXISTING); inputStream.close(); System.setProperty("org.azyva.dragom.init-property.URL_MODEL", pathModel.toUri().toString()); try { ExecContextManagerTool.main(new String[] { "--workspace=" + IntegrationTestSuite.pathTestWorkspace.resolve("workspace"), "release" }); } catch (ExitException ee) { if (ee.status != 0) { throw ee; } } FileUtils.deleteDirectory(IntegrationTestSuite.pathTestWorkspace.toFile()); System.getProperties().remove("org.azyva.dragom.init-property.URL_MODEL"); } IntegrationTestSuite.pathTestWorkspace.toFile().mkdirs(); inputStreamLoggingProperties = IntegrationTestSuite.class.getResourceAsStream("/logging.properties"); pathLoggingProperties = IntegrationTestSuite.pathTestWorkspace.resolve("logging.properties"); Files.copy(inputStreamLoggingProperties, pathLoggingProperties, StandardCopyOption.REPLACE_EXISTING); inputStreamLoggingProperties.close(); loggingProperties = FileUtils.readFileToString(pathLoggingProperties.toFile()); loggingProperties = loggingProperties.replace("%test-workspace%", IntegrationTestSuite.pathTestWorkspace.toString()); FileUtils.write(pathLoggingProperties.toFile(), loggingProperties); inputStreamLoggingProperties = new FileInputStream(pathLoggingProperties.toFile()); LogManager.getLogManager().readConfiguration(inputStreamLoggingProperties); inputStreamLoggingProperties.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:com.cloudbees.clickstack.util.Files2.java
/** * Returns a zip file system/*from w ww. ja va 2 s. co m*/ * * @param zipFile to construct the file system from * @param create true if the zip file should be created * @return a zip file system * @throws java.io.IOException */ private static FileSystem createZipFileSystem(Path zipFile, boolean create) throws IOException { // convert the filename to a URI final URI uri = URI.create("jar:file:" + zipFile.toUri().getPath()); final Map<String, String> env = new HashMap<>(); if (create) { env.put("create", "true"); } return FileSystems.newFileSystem(uri, env); }
From source file:org.jboss.tools.central.internal.CentralHelper.java
public static String getLoadingPageUrl() { Path loadingPage = getLoadingPage(); try {/* w w w. ja v a 2 s .co m*/ if (!Files.exists(loadingPage) //file doesn't exit || loadingPage.getFileName().toString().contains(".qualifier")) { //or during development String packageFolder = CentralHelper.class.getPackage().getName().replace('.', '/'); URL scriptUrl = new URL("platform:/plugin/" + JBossCentralActivator.PLUGIN_ID + "/" + packageFolder //$NON-NLS-1$ + "/loading.html"); URL sourceUrl = FileLocator.resolve(scriptUrl); FileUtils.copyURLToFile(sourceUrl, loadingPage.toFile()); } } catch (IOException e) { JBossCentralActivator.log(e, "Unable to extract loading.html"); return null; } return loadingPage.toUri().toString(); }
From source file:org.opencb.opencga.storage.core.variant.VariantStorageBaseTest.java
@BeforeClass public static void _beforeClass() throws Exception { // System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "debug"); newRootDir();//from w w w. j a va 2 s . c o m if (rootDir.toFile().exists()) { IOUtils.deleteDirectory(rootDir); Files.createDirectories(rootDir); } Path inputPath = rootDir.resolve(VCF_TEST_FILE_NAME); Path smallInputPath = rootDir.resolve(SMALL_VCF_TEST_FILE_NAME); Path corruptedInputPath = rootDir.resolve(VCF_CORRUPTED_FILE_NAME); Files.copy(VariantStorageManagerTest.class.getClassLoader().getResourceAsStream(VCF_TEST_FILE_NAME), inputPath, StandardCopyOption.REPLACE_EXISTING); Files.copy(VariantStorageManagerTest.class.getClassLoader().getResourceAsStream(SMALL_VCF_TEST_FILE_NAME), smallInputPath, StandardCopyOption.REPLACE_EXISTING); Files.copy(VariantStorageManagerTest.class.getClassLoader().getResourceAsStream(VCF_CORRUPTED_FILE_NAME), corruptedInputPath, StandardCopyOption.REPLACE_EXISTING); inputUri = inputPath.toUri(); smallInputUri = smallInputPath.toUri(); corruptedInputUri = corruptedInputPath.toUri(); outputUri = rootDir.toUri(); // logger.info("count: " + count.getAndIncrement()); }
From source file:org.finra.herd.swaggergen.AbstractTest.java
protected String getFileAsString(Path path) throws IOException { return replaceLineSeparators(IOUtils.toString(path.toUri())); }
From source file:com.baifendian.swordfish.webserver.service.storage.FileSystemStorageService.java
@Override public Resource loadAsResource(String filename) { try {//from w w w . j av a2s . co m Path file = Paths.get(filename); Resource resource = new UrlResource(file.toUri()); if (resource.exists() || resource.isReadable()) { return resource; } else { throw new StorageFileNotFoundException("Could not read file: " + filename); } } catch (MalformedURLException e) { throw new StorageFileNotFoundException("Could not read file: " + filename, e); } }
From source file:org.apache.taverna.robundle.manifest.PathAnnotation.java
private URI relativizePath(Path path) { return URI.create("/.ro/").relativize(URI.create(path.toUri().getRawPath())); }
From source file:com.github.ukase.config.WebConfig.java
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { String location = "classpath:static/"; if (devMode) { Path path = Paths.get(getProjectRootRequired(), "ui", "target", "dist"); location = path.toUri().toString(); }// w w w . j a v a 2s .c o m newResourceHandler(registry, "/bundle.*.js", location).addTransformer(new AppCacheManifestTransformer()); newResourceHandler(registry, "/cache*.appcache", location); newResourceHandler(registry, "/**", location + "index.html").addResolver(new PathResourceResolver() { @Override protected Resource getResource(String resourcePath, Resource location) throws IOException { Resource resource = location.createRelative(resourcePath); return resource.exists() && resource.isReadable() ? resource : null; } }); }