List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:io.github.collaboratory.LauncherCWL.java
/** * * @param workingDir where to save stderr and stdout * @param execute a pair holding the unformatted stderr and stderr * @param stdout formatted stdout for outpuit * @param stderr formatted stderr for output * @param cwltool help text explaining name of integration *//* w ww . j a va 2 s . co m*/ public static void outputIntegrationOutput(String workingDir, ImmutablePair<String, String> execute, String stdout, String stderr, String cwltool) { System.out.println(cwltool + " stdout:\n" + stdout); System.out.println(cwltool + " stderr:\n" + stderr); try { final Path path = Paths.get(workingDir + File.separator + cwltool + ".stdout.txt"); FileUtils.writeStringToFile(path.toFile(), execute.getLeft(), StandardCharsets.UTF_8, false); System.out.println("Saving copy of " + cwltool + " stdout to: " + path.toAbsolutePath().toString()); final Path txt2 = Paths.get(workingDir + File.separator + cwltool + ".stderr.txt"); FileUtils.writeStringToFile(txt2.toFile(), execute.getRight(), StandardCharsets.UTF_8, false); System.out.println("Saving copy of " + cwltool + " stderr to: " + txt2.toAbsolutePath().toString()); } catch (IOException e) { throw new RuntimeException("unable to save " + cwltool + " output", e); } }
From source file:jduagui.Controller.java
public static void getExtensions(String startPath, Map<String, Extension> exts) throws IOException { final AtomicReference<String> extension = new AtomicReference<>(""); final File f = new File(startPath); final String str = ""; Path path = Paths.get(startPath); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override//ww w . ja v a2 s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { storageCache.put(file.toAbsolutePath().toString(), attrs.size()); extension.set(FilenameUtils.getExtension(file.toAbsolutePath().toString())); if (extension.get().equals(str)) { if (exts.containsKey(noExt)) { exts.get(noExt).countIncrement(); exts.get(noExt).increaseSize(attrs.size()); } else { exts.put(noExt, new Extension(new AtomicLong(1), new AtomicLong(attrs.size()))); } } else { if (exts.containsKey(extension.get())) { exts.get(extension.get()).countIncrement(); exts.get(extension.get()).increaseSize(attrs.size()); } else { exts.put(extension.get(), new Extension(new AtomicLong(1), new AtomicLong(attrs.size()))); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); }
From source file:com.cloudbees.clickstack.util.Files2.java
/** * @param srcDir//from w ww.j av a 2 s. c o m * @return * @throws RuntimeIOException * @throws IllegalStateException More or less than 1 child dir found */ @Nonnull public static Path findUniqueChildDirectory(@Nonnull Path srcDir) throws RuntimeIOException, IllegalStateException { Preconditions.checkArgument(Files.isDirectory(srcDir), "Source %s is not a directory", srcDir.toAbsolutePath()); try (DirectoryStream<Path> paths = Files.newDirectoryStream(srcDir)) { try { return Iterables.getOnlyElement(paths); } catch (NoSuchElementException e) { throw new IllegalStateException( "No child directory found in : " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath()); } catch (IllegalArgumentException e) { throw new IllegalStateException("More than 1 child directory found in path: " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath() + " -> " + paths); } } catch (IOException e) { throw new RuntimeIOException("Exception finding unique child directory in " + srcDir); } }
From source file:com.cloudbees.clickstack.util.Files2.java
/** * @param srcDir/*from w ww .j a va 2 s .c o m*/ * @param pattern * @return * @throws RuntimeIOException * @throws IllegalStateException More or less than 1 child dir found */ @Nonnull public static Path findUniqueDirectoryBeginningWith(@Nonnull Path srcDir, @Nonnull final String pattern) throws RuntimeIOException, IllegalStateException { Preconditions.checkArgument(Files.isDirectory(srcDir), "Source %s is not a directory", srcDir.toAbsolutePath()); DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { String fileName = entry.getFileName().toString(); if (pattern == null) { return true; } else if (fileName.startsWith(pattern)) { return true; } else { return false; } } }; try (DirectoryStream<Path> paths = Files.newDirectoryStream(srcDir, filter)) { try { return Iterables.getOnlyElement(paths); } catch (NoSuchElementException e) { throw new IllegalStateException("Directory beginning with '" + pattern + "' not found in path: " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath()); } catch (IllegalArgumentException e) { throw new IllegalStateException( "More than 1 directory beginning with '" + pattern + "' found in path: " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath() + " -> " + paths); } } catch (IOException e) { throw new RuntimeIOException( "Exception finding unique child directory beginning with " + filter + "in " + srcDir); } }
From source file:org.neo4j.ogm.auth.AuthenticationTest.java
@BeforeClass public static void setUp() throws Exception { Path authStore = Files.createTempFile("neo4j", "credentials"); authStore.toFile().deleteOnExit();/* www. j a v a2 s .c o m*/ try (Writer authStoreWriter = new FileWriter(authStore.toFile())) { IOUtils.write( "neo4j:SHA-256,03C9C54BF6EEF1FF3DFEB75403401AA0EBA97860CAC187D6452A1FCF4C63353A,819BDB957119F8DFFF65604C92980A91:", authStoreWriter); } neoPort = TestUtils.getAvailablePort(); try { ServerControls controls = TestServerBuilders.newInProcessBuilder() .withConfig("dbms.security.auth_enabled", "true") .withConfig("org.neo4j.server.webserver.port", String.valueOf(neoPort)) .withConfig("dbms.security.auth_store.location", authStore.toAbsolutePath().toString()) .newServer(); initialise(controls); } catch (Exception e) { throw new RuntimeException("Error starting in-process server", e); } }
From source file:com.cloudbees.clickstack.util.Files2.java
/** * Find a file matching {@code $artifactId*$type} in the given {@code srcDir}. * * @param srcDir/*from w w w . jav a 2 s. com*/ * @param artifactId * @param type * @return * @throws IllegalStateException More or less than 1 matching artifact found * @throws RuntimeIOException */ @Nonnull public static Path findArtifact(@Nonnull Path srcDir, @Nonnull final String artifactId, @Nonnull final String type) throws RuntimeIOException, IllegalStateException { Preconditions.checkArgument(Files.isDirectory(srcDir), "Source %s is not a directory", srcDir.toAbsolutePath()); DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { String fileName = entry.getFileName().toString(); if (fileName.startsWith(artifactId) && fileName.endsWith("." + type)) { return true; } else { return false; } } }; try (DirectoryStream<Path> paths = Files.newDirectoryStream(srcDir, filter)) { try { return Iterables.getOnlyElement(paths); } catch (NoSuchElementException e) { throw new IllegalStateException("Artifact '" + artifactId + ":" + type + "' not found in path: " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath()); } catch (IllegalArgumentException e) { throw new IllegalStateException( "More than 1 version of artifact '" + artifactId + ":" + type + "' found in path: " + srcDir + ", absolutePath: " + srcDir.toAbsolutePath() + " -> " + paths); } } catch (IOException e) { throw new RuntimeIOException("Exception finding artifact " + artifactId + "@" + type + " in " + srcDir); } }
From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java
private static void initializeGitRepository() throws ServletException { XacmlAdminUI.repositoryPath = Paths .get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY)); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try {/*from ww w. j a v a 2 s . c o m*/ XacmlAdminUI.repository = builder.setGitDir(XacmlAdminUI.repositoryPath.toFile()).readEnvironment() .findGitDir().setBare().build(); if (Files.notExists(XacmlAdminUI.repositoryPath) || Files.notExists(Paths.get(XacmlAdminUI.repositoryPath.toString(), "HEAD"))) { // // Create it if it doesn't exist. As a bare repository // logger.info("Creating bare git repository: " + XacmlAdminUI.repositoryPath.toString()); XacmlAdminUI.repository.create(); // // Add the magic file so remote works. // Path daemon = Paths.get(XacmlAdminUI.repositoryPath.toString(), "git-daemon-export-ok"); Files.createFile(daemon); } } catch (IOException e) { logger.error("Failed to build repository: " + repository, e); throw new ServletException(e.getMessage(), e.getCause()); } // // Make sure the workspace directory is created // Path workspace = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE)); workspace = workspace.toAbsolutePath(); if (Files.notExists(workspace)) { try { Files.createDirectory(workspace); } catch (IOException e) { logger.error("Failed to build workspace: " + workspace, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Create the user workspace directory // workspace = Paths.get(workspace.toString(), "pe"); if (Files.notExists(workspace)) { try { Files.createDirectory(workspace); } catch (IOException e) { logger.error("Failed to create directory: " + workspace, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Get the path to where the repository is going to be // Path gitPath = Paths.get(workspace.toString(), XacmlAdminUI.repositoryPath.getFileName().toString()); if (Files.notExists(gitPath)) { try { Files.createDirectory(gitPath); } catch (IOException e) { logger.error("Failed to create directory: " + gitPath, e); throw new ServletException(e.getMessage(), e.getCause()); } } // // Initialize the domain structure // String base = null; String domain = XacmlAdminUI.getDomain(); if (domain != null) { for (String part : Splitter.on(':').trimResults().split(domain)) { if (base == null) { base = part; } Path subdir = Paths.get(gitPath.toString(), part); if (Files.notExists(subdir)) { try { Files.createDirectory(subdir); Files.createFile(Paths.get(subdir.toString(), ".svnignore")); } catch (IOException e) { logger.error("Failed to create: " + subdir, e); throw new ServletException(e.getMessage(), e.getCause()); } } } } else { try { Files.createFile(Paths.get(workspace.toString(), ".svnignore")); base = ".svnignore"; } catch (IOException e) { logger.error("Failed to create file", e); throw new ServletException(e.getMessage(), e.getCause()); } } try { // // These are the sequence of commands that must be done initially to // finish setting up the remote bare repository. // Git git = Git.init().setDirectory(gitPath.toFile()).setBare(false).call(); git.add().addFilepattern(base).call(); git.commit().setMessage("Initialize Bare Repository").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", XacmlAdminUI.repositoryPath.toAbsolutePath().toString()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); git.push().setRemote("origin").add("master").call(); /* * This will not work unless git.push().setRemote("origin").add("master").call(); * is called first. Otherwise it throws an exception. However, if the push() is * called then calling this function seems to add nothing. * git.branchCreate().setName("master") .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/master").setForce(true).call(); */ } catch (GitAPIException | IOException e) { logger.error(e); throw new ServletException(e.getMessage(), e.getCause()); } }
From source file:com.yevster.spdxtra.Write.java
/** * Reads RDF from inputFilePath into a provided dataset. NOTE: This behavior * is not tested with pre-populated datasets. * * @param inputFilePath//from ww w . j a v a 2 s . c om * @param dataset */ public static void rdfIntoDataset(Path inputFilePath, Dataset dataset) { Validate.notNull(inputFilePath); if (Files.notExists(inputFilePath) && Files.isRegularFile(inputFilePath)) throw new IllegalArgumentException( "File " + inputFilePath.toAbsolutePath().toString() + " does not exist"); final InputStream is; try { is = Files.newInputStream(inputFilePath); } catch (IOException ioe) { throw new RuntimeException("Unable to read file " + inputFilePath.toAbsolutePath().toString(), ioe); } try (DatasetAutoAbortTransaction transaction = DatasetAutoAbortTransaction.begin(dataset, ReadWrite.WRITE)) { dataset.getDefaultModel().read(is, null); transaction.commit(); } }
From source file:com.yevster.spdxtra.Write.java
/** * Reads inputFilePath and populates a new RDF data store at * targetDirectoryPath with its contents. * * @param inputFilePath//from w w w . j a v a 2 s .c o m * Must be a valid path to an RDF file. * @param newDatasetPath * The path to which to persist the RDF triple store with SPDX * data. * @return */ public static Dataset rdfIntoNewDataset(Path inputFilePath, Path newDatasetPath) { Validate.notNull(newDatasetPath); if (Files.notExists(newDatasetPath) || !Files.isDirectory(newDatasetPath)) { throw new IllegalArgumentException( "Invalid dataset path: " + newDatasetPath.toAbsolutePath().toString()); } Read.logger.debug("Creating new TDB in " + newDatasetPath.toAbsolutePath().toString()); Dataset dataset = TDBFactory.createDataset(newDatasetPath.toString()); dataset.getDefaultModel().getGraph().getPrefixMapping().setNsPrefix("spdx", SpdxUris.SPDX_TERMS); dataset.getDefaultModel().getGraph().getPrefixMapping().setNsPrefix("doap", SpdxUris.DOAP_NAMESPACE); Write.rdfIntoDataset(inputFilePath, dataset); return dataset; }
From source file:com.att.aro.core.util.Util.java
/** * <pre>/*from w ww. j av a 2 s.co m*/ * makes a folder in the targetLibFolder location. * Mac {home}/AROLibrary * Win * * if it fails it will create AROLibrary the current application execution folder * * @param filename * @param currentRelativePath * @param targetLibFolder * @return */ public static String makeLibFolder(String filename, File libFolder) { String targetLibFolder = libFolder.toPath().toString(); Path currentRelativePath = Paths.get(""); try { Files.createDirectories(libFolder.toPath()); } catch (IOException ioe1) { // if no write access rights to the path folder then extract the lib to a default local folder targetLibFolder = currentRelativePath.toAbsolutePath().toString() + File.separator + "AROLibrary"; try { Files.createDirectories(libFolder.toPath()); } catch (IOException ioe2) { return null; } } return targetLibFolder; }