List of usage examples for java.nio.file Path toUri
URI toUri();
From source file:org.roda.core.RodaCoreFactory.java
public static URL getConfigurationFile(String configurationFile) { Path config = RodaCoreFactory.getConfigPath().resolve(configurationFile); URL configUri;//from w w w . j a v a 2 s . c om if (FSUtils.exists(config) && !FSUtils.isDirectory(config) && config.toAbsolutePath().startsWith(getConfigPath().toAbsolutePath().toString())) { try { configUri = config.toUri().toURL(); } catch (MalformedURLException e) { LOGGER.error("Configuration {} doesn't exist", configurationFile); configUri = null; } } else { URL resource = RodaCoreFactory.class .getResource("/" + RodaConstants.CORE_CONFIG_FOLDER + "/" + configurationFile); if (resource != null) { configUri = resource; } else { LOGGER.error("Configuration {} doesn't exist", configurationFile); configUri = null; } } return configUri; }
From source file:org.apache.flink.runtime.webmonitor.history.HistoryServerTest.java
private static void createLegacyArchive(Path directory) throws IOException { JobID jobID = JobID.generate();/*from w ww.ja va2 s .co m*/ StringWriter sw = new StringWriter(); try (JsonGenerator gen = JACKSON_FACTORY.createGenerator(sw)) { try (JsonObject root = new JsonObject(gen)) { try (JsonArray finished = new JsonArray(gen, "finished")) { try (JsonObject job = new JsonObject(gen)) { gen.writeStringField("jid", jobID.toString()); gen.writeStringField("name", "testjob"); gen.writeStringField("state", JobStatus.FINISHED.name()); gen.writeNumberField("start-time", 0L); gen.writeNumberField("end-time", 1L); gen.writeNumberField("duration", 1L); gen.writeNumberField("last-modification", 1L); try (JsonObject tasks = new JsonObject(gen, "tasks")) { gen.writeNumberField("total", 0); gen.writeNumberField("pending", 0); gen.writeNumberField("running", 0); gen.writeNumberField("finished", 0); gen.writeNumberField("canceling", 0); gen.writeNumberField("canceled", 0); gen.writeNumberField("failed", 0); } } } } } String json = sw.toString(); ArchivedJson archivedJson = new ArchivedJson("/joboverview", json); FsJobArchivist.archiveJob(new org.apache.flink.core.fs.Path(directory.toUri()), jobID, Collections.singleton(archivedJson)); }
From source file:org.apache.taverna.prov.W3ProvenanceExport.java
protected URI toURI(Path file) { return file.toUri(); }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.AreaServiceBean.java
private Map<String, List<Property>> readShapeFile(Path shapeFilePath, Integer srid) throws IOException, ServiceException { Map<String, Object> map = new HashMap<>(); map.put("url", shapeFilePath.toUri().toURL()); DataStore dataStore = DataStoreFinder.getDataStore(map); Map<String, List<Property>> geometries = new HashMap<>(); String typeName = dataStore.getTypeNames()[0]; FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName); FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(Filter.INCLUDE); FeatureIterator<SimpleFeature> iterator = collection.features(); try {/*from w w w.j a v a2 s . c om*/ CoordinateReferenceSystem sourceCRS = GeometryUtils.toCoordinateReferenceSystem(srid); CoordinateReferenceSystem coordinateReferenceSystem = GeometryUtils .toDefaultCoordinateReferenceSystem(); MathTransform transform = CRS.findMathTransform(sourceCRS, coordinateReferenceSystem); while (iterator.hasNext()) { final SimpleFeature feature = iterator.next(); geometries.put(feature.getID(), new ArrayList<>(feature.getProperties())); Geometry targetGeometry = (Geometry) feature.getDefaultGeometry(); if (targetGeometry != null) { if (coordinateReferenceSystem.getName().equals(sourceCRS.getName())) { targetGeometry = JTS.transform(targetGeometry, transform); } } else { throw new ServiceException("TARGET GEOMETRY CANNOT BE NULL"); } targetGeometry.setSRID(databaseDialect.defaultSRID()); feature.setDefaultGeometry(targetGeometry); } return geometries; } catch (FactoryException | TransformException e) { log.error(e.getMessage(), e); throw new ServiceException(e.getMessage(), e); } finally { iterator.close(); dataStore.dispose(); } }
From source file:org.tinymediamanager.core.Utils.java
/** * Unzips the specified zip file to the specified destination directory. Replaces any files in the destination, if they already exist. * // ww w . ja v a 2 s.co m * @param zipFile * the name of the zip file to extract * @param destDir * the directory to unzip to * @throws IOException */ public static void unzip(Path zipFile, final Path destDir) { Map<String, String> env = new HashMap<>(); try { // if the destination doesn't exist, create it if (!Files.exists(destDir)) { Files.createDirectories(destDir); } // check if file exists env.put("create", String.valueOf(!Files.exists(zipFile))); // use a Zip filesystem URI URI fileUri = zipFile.toUri(); // here URI zipUri = new URI("jar:" + fileUri.getScheme(), fileUri.getPath(), null); try (FileSystem zipfs = FileSystems.newFileSystem(zipUri, env)) { final Path root = zipfs.getPath("/"); // walk the zip file tree and copy files to the destination Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { final Path destFile = Paths.get(destDir.toString(), file.toString()); LOGGER.debug("Extracting file {} to {}", file, destFile); Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = Paths.get(destDir.toString(), dir.toString()); if (!Files.exists(dirToCreate)) { LOGGER.debug("Creating directory {}", dirToCreate); Files.createDirectory(dirToCreate); } return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("Failed to create zip file!" + e.getMessage()); } }
From source file:org.opencb.opencga.app.cli.main.executors.catalog.FilesCommandExecutor.java
private QueryResponse<File> copy() throws CatalogException { logger.debug("Creating a new file"); //openCGAClient.getFileClient(). /******************* Falta el create en FileClient.java ?? **// // OptionsParser.FileCommands.CreateCommand c = optionsParser.getFileCommands().createCommand; FileCommandOptions.CopyCommandOptions copyCommandOptions = filesCommandOptions.copyCommandOptions; long studyId = catalogManager.getStudyId(copyCommandOptions.studyId); Path inputFile = Paths.get(copyCommandOptions.inputFile); URI sourceUri;//from w ww . j a v a 2 s .c o m try { sourceUri = new URI(null, copyCommandOptions.inputFile, null); } catch (URISyntaxException e) { throw new CatalogException("Input file is not a proper URI"); } if (sourceUri.getScheme() == null || sourceUri.getScheme().isEmpty()) { sourceUri = inputFile.toUri(); } if (!catalogManager.getCatalogIOManagerFactory().get(sourceUri).exists(sourceUri)) { throw new CatalogException("File " + sourceUri + " does not exist"); } QueryResult<File> file = catalogManager.createFile(studyId, copyCommandOptions.format, copyCommandOptions.bioformat, Paths.get(copyCommandOptions.path, inputFile.getFileName().toString()).toString(), copyCommandOptions.description, copyCommandOptions.parents, -1, sessionId); new CatalogFileUtils(catalogManager).upload(sourceUri, file.first(), null, sessionId, false, false, copyCommandOptions.move, copyCommandOptions.calculateChecksum); FileMetadataReader.get(catalogManager).setMetadataInformation(file.first(), null, new QueryOptions(), sessionId, false); return new QueryResponse<>(new QueryOptions(), Arrays.asList(file)); }
From source file:com.samsung.sjs.Compiler.java
public static void compile(CompilerOptions opts, boolean typecheckonly, boolean checkTypes) throws IOException, SolverException { Path p = Paths.get(opts.getInputFileName()); AstRoot sourcetree = null;/*from w w w . ja v a2 s .co m*/ Map<AstNode, Type> types; JSEnvironment env = opts.getRuntimeEnvironment(); switch (opts.getTargetPlatform()) { case Web: // Fall-through case Native: // This may be the most hideous line of code I've ever written InputStream jsenv = Compiler.class.getClass().getResourceAsStream("/environment.json"); assert (jsenv != null); env.includeFile(jsenv); } for (Path fname : opts.getExtraDeclarationFiles()) { env.includeFile(fname); } ModuleSystem modsys = new ModuleSystem(opts); assert (opts.useConstraints()); FFILinkage ffi = new FFILinkage(); InputStream stdlib_linkage = Compiler.class.getClass().getResourceAsStream("/linkage.json"); ffi.includeFile(stdlib_linkage); for (Path fname : opts.getExtraLinkageFiles()) { ffi.includeFile(fname); } String script = IOUtils.toString(p.toUri(), Charset.defaultCharset()); org.mozilla.javascript.Parser parser = new org.mozilla.javascript.Parser(); sourcetree = parser.parse(script, "", 1); ConstraintFactory factory = new ConstraintFactory(); ConstraintGenerator generator = new ConstraintGenerator(factory, env, modsys); generator.generateConstraints(sourcetree); Set<ITypeConstraint> constraints = generator.getTypeConstraints(); if (opts.shouldDumpConstraints()) { System.err.println("Constraints:"); System.err.println(generator.stringRepresentationWithTermLineNumbers(constraints)); } if (!opts.oldExplanations()) { SatSolver satSolver = new Sat4J(); SJSTypeTheory theorySolver = new SJSTypeTheory(env, modsys, sourcetree); List<ITypeConstraint> initConstraints = theorySolver.getConstraints(); ConstraintGenerator g = theorySolver.hackyGenerator(); List<Integer> hardConstraints = new ArrayList<>(initConstraints.size()); List<Integer> softConstraints = new ArrayList<>(initConstraints.size()); for (int i = 0; i < initConstraints.size(); ++i) { boolean isSoft = g.hasExplanation(initConstraints.get(i)); (isSoft ? softConstraints : hardConstraints).add(i); } FixingSetFinder<Integer> finder = FixingSetFinder.getStrategy(opts.explanationStrategy()); Pair<TypeAssignment, Collection<Integer>> result = TheorySolver.solve(theorySolver, finder, hardConstraints, softConstraints); if (!finder.isOptimal() && !result.getRight().isEmpty()) { result = TheorySolver.minimizeFixingSet(theorySolver, hardConstraints, softConstraints, result.getLeft(), result.getRight()); } if (!result.getRight().isEmpty()) { System.out.println("Found " + result.getRight().size() + " type errors"); g = theorySolver.hackyGenerator(); int i = 0; for (ITypeConstraint c : theorySolver.hackyConstraintAccess()) { if (result.getRight().contains(i++)) { System.out.println(); g.explainFailure(c, result.getLeft()).prettyprint(System.out); } } System.exit(1); } types = result.getLeft().nodeTypes(); if (opts.shouldDumpConstraintSolution()) { System.err.println("Solved Constraints:"); System.err.println(result.getLeft().debugString()); } } else { DirectionalConstraintSolver solver = new DirectionalConstraintSolver(constraints, factory, generator); TypeAssignment solution = null; try { solution = solver.solve(); } catch (SolverException e) { System.out.println("type inference failed"); String explanation = e.explanation(); System.out.println(explanation); System.exit(1); } if (opts.shouldDumpConstraintSolution()) { System.err.println("Solved Constraints:"); System.err.println(solution.debugString()); } types = solution.nodeTypes(); } if (typecheckonly) { return; } if (checkTypes) { new RhinoTypeValidator(sourcetree, types).check(); } // Translate Rhino IR to SJS IR. RhinoToIR rti = new RhinoToIR(opts, sourcetree, types); com.samsung.sjs.backend.asts.ir.Script ir = rti.convert(); // Collect the set of explicit property / slot names IRFieldCollector fc = new IRFieldCollector(env, modsys); ir.accept(fc); IRFieldCollector.FieldMapping m = fc.getResults(); if (opts.debug()) { System.out.println(m.toString()); } boolean iterate_constant_inlining = true; if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* Pre-constant inlining: *"); System.err.println("**********************************************"); System.err.println(ir.toSource(0)); } while (iterate_constant_inlining) { ConstantInliningPass cip = new ConstantInliningPass(opts, ir); ir = cip.visitScript(ir); // Replacing may make more things constant (vars aren't const) so repeat iterate_constant_inlining = cip.didSomething(); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* Post-constant inlining: *"); System.err.println("**********************************************"); System.err.println(ir.toSource(0)); } } IREnvironmentLayoutPass envlayout = new IREnvironmentLayoutPass(ir, opts.debug()); ir.accept(envlayout); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* IR Env Layout Result: *"); System.err.println("**********************************************"); System.err.println(ir.toSource(0)); } SwitchDesugaringPass sdp = new SwitchDesugaringPass(opts, ir); com.samsung.sjs.backend.asts.ir.Script post_switch_desugar = sdp.convert(); IntrinsicsInliningPass iip = new IntrinsicsInliningPass(post_switch_desugar, opts, ffi); com.samsung.sjs.backend.asts.ir.Script post_intrinsics = iip.convert(); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* IR Intrinsics Inlining Result: *"); System.err.println("**********************************************"); System.err.println(post_intrinsics.toSource(0)); } IRClosureConversionPass ccp = new IRClosureConversionPass(post_intrinsics, envlayout.getMainCaptures(), opts.debug(), opts.isGuestRuntime() ? "__sjs_main" : "main"); com.samsung.sjs.backend.asts.ir.Script post_cc = ccp.convert(); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* IR Closure Conversion Result: *"); System.err.println("**********************************************"); System.err.println(post_cc.toSource(0)); } post_cc = new ThreeAddressConversion(post_cc).visitScript(post_cc); if (logger.isDebugEnabled()) { System.err.println("**********************************************"); System.err.println("* Three-Address Conversion Result: *"); System.err.println("**********************************************"); System.err.println(post_cc.toSource(0)); } // Gather constraints for optimizing object layouts PhysicalLayoutConstraintGathering plcg = new PhysicalLayoutConstraintGathering(opts, m, ffi); post_cc.accept(plcg); // TODO: Eventually feed this to the IRVTablePass as a source of layout information // Decorate SJS IR with vtables. IRVTablePass irvt = new IRVTablePass(opts, m, ffi); post_cc.accept(irvt); if (opts.fieldOptimizations()) { System.err.println("WARNING: Running experimental field access optimizations!"); post_cc = (com.samsung.sjs.backend.asts.ir.Script) (new FieldAccessOptimizer(post_cc, opts, m, irvt.getVtablesByFieldMap()).visitScript(post_cc)); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* Field Access Optimization Result: *"); System.err.println("**********************************************"); System.err.println(post_cc.toSource(0)); } } IRCBackend ir2c = new IRCBackend(post_cc, opts, m, ffi, env, modsys); CompilationUnit c_via_ir = ir2c.compile(); if (opts.debug()) { System.err.println("**********************************************"); System.err.println("* C via IR Result: *"); System.err.println("**********************************************"); for (com.samsung.sjs.backend.asts.c.Statement s : c_via_ir) { System.err.println(s.toSource(0)); } } c_via_ir.writeToDisk(opts.getOutputCName()); }
From source file:org.opencb.opencga.storage.hadoop.variant.AbstractHadoopVariantStoragePipeline.java
@Override public URI preLoad(URI input, URI output) throws StorageEngineException { boolean loadArch = options.getBoolean(HADOOP_LOAD_ARCHIVE); boolean loadVar = options.getBoolean(HADOOP_LOAD_VARIANT); if (!loadArch && !loadVar) { loadArch = true;/* www . j av a 2s . c om*/ loadVar = true; options.put(HADOOP_LOAD_ARCHIVE, loadArch); options.put(HADOOP_LOAD_VARIANT, loadVar); } if (loadArch) { super.preLoad(input, output); if (needLoadFromHdfs() && !input.getScheme().equals("hdfs")) { if (!StringUtils.isEmpty(options.getString(OPENCGA_STORAGE_HADOOP_INTERMEDIATE_HDFS_DIRECTORY))) { output = URI.create(options.getString(OPENCGA_STORAGE_HADOOP_INTERMEDIATE_HDFS_DIRECTORY)); } if (output.getScheme() != null && !output.getScheme().equals("hdfs")) { throw new StorageEngineException("Output must be in HDFS"); } try { long startTime = System.currentTimeMillis(); // Configuration conf = getHadoopConfiguration(options); FileSystem fs = FileSystem.get(conf); org.apache.hadoop.fs.Path variantsOutputPath = new org.apache.hadoop.fs.Path( output.resolve(Paths.get(input.getPath()).getFileName().toString())); logger.info("Copy from {} to {}", new org.apache.hadoop.fs.Path(input).toUri(), variantsOutputPath.toUri()); fs.copyFromLocalFile(false, new org.apache.hadoop.fs.Path(input), variantsOutputPath); logger.info("Copied to hdfs in {}s", (System.currentTimeMillis() - startTime) / 1000.0); startTime = System.currentTimeMillis(); URI fileInput = URI.create(VariantReaderUtils.getMetaFromTransformedFile(input.toString())); org.apache.hadoop.fs.Path fileOutputPath = new org.apache.hadoop.fs.Path( output.resolve(Paths.get(fileInput.getPath()).getFileName().toString())); logger.info("Copy from {} to {}", new org.apache.hadoop.fs.Path(fileInput).toUri(), fileOutputPath.toUri()); fs.copyFromLocalFile(false, new org.apache.hadoop.fs.Path(fileInput), fileOutputPath); logger.info("Copied to hdfs in {}s", (System.currentTimeMillis() - startTime) / 1000.0); input = variantsOutputPath.toUri(); } catch (IOException e) { e.printStackTrace(); } } } try { ArchiveDriver.createArchiveTableIfNeeded(dbAdaptor.getGenomeHelper(), archiveTableCredentials.getTable(), dbAdaptor.getConnection()); } catch (IOException e) { throw new StorageHadoopException("Issue creating table " + archiveTableCredentials.getTable(), e); } try { VariantTableDriver.createVariantTableIfNeeded(dbAdaptor.getGenomeHelper(), variantsTableCredentials.getTable(), dbAdaptor.getConnection()); } catch (IOException e) { throw new StorageHadoopException("Issue creating table " + variantsTableCredentials.getTable(), e); } if (loadVar) { preMerge(input); } return input; }
From source file:com.esri.gpt.control.rest.ManageDocumentServlet.java
private boolean saveXml2Package(String xml, String uuid) throws IOException { uuid = UuidUtil.removeCurlies(uuid); //xml file/* w w w.ja va 2 s.com*/ String folder = Constant.UPLOAD_FOLDER; File temp = new File(folder + File.separator + uuid + File.separator + Constant.XML_OUTPUT_FILE_NAME); InputStream in = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); //InputStream in = doc.newInputStream(); Path a = temp.toPath(); Files.copy(in, a, java.nio.file.StandardCopyOption.REPLACE_EXISTING); //copy xml file into zip file Map<String, String> env = new HashMap<>(); env.put("create", "true"); Path path = null; path = Paths.get(folder + File.separator + uuid + File.separator + Constant.XML_OUTPUT_ZIP_NAME); URI uri = URI.create("jar:" + path.toUri()); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { Files.copy(Paths.get(folder + File.separator + uuid + File.separator + Constant.XML_OUTPUT_FILE_NAME), fs.getPath(Constant.XML_OUTPUT_FILE_NAME), StandardCopyOption.REPLACE_EXISTING); } return true; }
From source file:org.opencb.opencga.storage.core.manager.variant.operations.StorageOperation.java
protected List<File> copyResults(Path tmpOutdirPath, long catalogPathOutDir, String sessionId) throws CatalogException, IOException { File outDir = catalogManager.getFile(catalogPathOutDir, new QueryOptions(), sessionId).first(); FileScanner fileScanner = new FileScanner(catalogManager); // CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(tmpOutdirPath.toUri()); List<File> files; try {//ww w . j ava 2 s . c o m logger.info("Scanning files from {} to move to {}", tmpOutdirPath, outDir.getUri()); // Avoid copy the job.status file! Predicate<URI> fileStatusFilter = uri -> !uri.getPath().endsWith(JOB_STATUS_FILE) && !uri.getPath().endsWith(OUT_LOG_EXTENSION) && !uri.getPath().endsWith(ERR_LOG_EXTENSION); files = fileScanner.scan(outDir, tmpOutdirPath.toUri(), FileScanner.FileScannerPolicy.DELETE, true, false, fileStatusFilter, -1, sessionId); // TODO: Check whether we want to store the logs as well. At this point, we are also storing them. // Do not execute checksum for log files! They may not be closed yet fileStatusFilter = uri -> uri.getPath().endsWith(OUT_LOG_EXTENSION) || uri.getPath().endsWith(ERR_LOG_EXTENSION); files.addAll(fileScanner.scan(outDir, tmpOutdirPath.toUri(), FileScanner.FileScannerPolicy.DELETE, false, false, fileStatusFilter, -1, sessionId)); } catch (IOException e) { logger.warn("IOException when scanning temporal directory. Error: {}", e.getMessage()); throw e; } catch (CatalogException e) { logger.warn("CatalogException when scanning temporal directory. Error: {}", e.getMessage()); throw e; } return files; }