List of usage examples for java.nio.file Path toString
String toString();
From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java
private static void generateTestCaseReport(SlangTestCaseRunReportGeneratorService reportGeneratorService, IRunTestResults runTestsResults, String testCaseReportLocation) throws IOException { if (StringUtils.isNotBlank(testCaseReportLocation)) { Path reportDirectoryPath = get(testCaseReportLocation); if (!exists(reportDirectoryPath)) { createDirectories(reportDirectoryPath); }/*w w w .j a v a 2 s . c om*/ reportGeneratorService.generateReport(runTestsResults, reportDirectoryPath.toString()); } }
From source file:edu.cwru.jpdg.Javac.java
/** * Compiles the java.//from w w w.j a va2s . co m */ public static List<String> javac(String basepath, String name, String s) { Path dir = Paths.get(cwd).resolve(basepath); if (Files.notExists(dir)) { create_dir(dir); } Path java = dir.resolve(name + ".java"); Path build = dir.resolve("build"); if (!Files.notExists(build)) { try { FileUtils.deleteDirectory(build.toFile()); } catch (IOException e) { throw new RuntimeException("Couldn't rm -r build dir"); } } create_dir(build); byte[] bytes = s.getBytes(); try { Files.write(java, bytes); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } try { Process p = Runtime.getRuntime() .exec(new String[] { "javac", "-d", build.toString(), java.toString() }); String line; BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); List<String> stdout_lines = new ArrayList<String>(); line = stdout.readLine(); while (line != null) { stdout_lines.add(line); line = stdout.readLine(); } BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); List<String> stderr_lines = new ArrayList<String>(); line = stderr.readLine(); while (line != null) { stderr_lines.add(line); line = stderr.readLine(); } if (p.waitFor() != 0) { System.err.println(StringUtils.join(stdout_lines, "\n")); System.err.println("-------------------------------------"); System.err.println(StringUtils.join(stderr_lines, "\n")); throw new RuntimeException("javac failed"); } } catch (InterruptedException e) { throw new RuntimeException(e.getMessage()); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return abs_paths(find_classes(build.toString())); }
From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java
/** * Saves the file to disk along with corresponding expiration date file. * @param fileName the name of the file to save * @param content the content of the file * @param expirationDate the file expiration date * @throws Exception if an error occurs//from ww w. ja va2 s .c om */ public static final void save(Path fileName, byte[] content, ConfigurationPartMetadata expirationDate) throws Exception { if (fileName == null) { return; } Path parent = fileName.getParent(); if (parent != null) { Files.createDirectories(parent); } log.info("Saving content to file {}", fileName); // save the content to disk AtomicSave.execute(fileName.toString(), "conf", content, StandardCopyOption.ATOMIC_MOVE); // save the content metadata date to disk saveMetadata(fileName, expirationDate); }
From source file:de.teamgrit.grit.preprocess.fetch.SvnFetcher.java
/** * Updates the directory path for remote svn repos. * * @param location/* w ww. j a v a2 s . c o m*/ * the adress of the repo * @param oldPath * the current path * @return an updated path */ private static Path updateDirectoryPath(String location, Path oldPath) { Path targetDirectory = Paths.get(oldPath.toAbsolutePath().toString()); // check whether the svn repo is given via a url or is given via a path if (!location.startsWith("file://")) { // We need to get the name of the checked out folder / repo. int occurences = StringUtils.countMatches(location, "/"); int index = StringUtils.ordinalIndexOf(location, "/", occurences); String temp = location.substring(index + 1); // stitch the last part of the hyperlink to the targetDirectory to // receive the structure targetDirectory = Paths.get(targetDirectory.toString(), temp); } else { targetDirectory = targetDirectory.resolve(Paths.get(location).getFileName()); } return targetDirectory; }
From source file:Test.java
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (file.toString().endsWith(".java")) { System.out.println(file.getFileName()); }/*from w w w . j av a2 s . c o m*/ return FileVisitResult.CONTINUE; }
From source file:org.hawkular.apm.api.services.ConfigurationLoader.java
/** * This method loads the configuration from the supplied URI. * * @param uri The URI//from w ww . j a v a 2s . c om * @param type The type, or null if default (jvm) * @return The configuration */ protected static CollectorConfiguration loadConfig(String uri, String type) { final CollectorConfiguration config = new CollectorConfiguration(); if (type == null) { type = DEFAULT_TYPE; } uri += java.io.File.separator + type; File f = new File(uri); if (!f.isAbsolute()) { if (f.exists()) { uri = f.getAbsolutePath(); } else if (System.getProperties().containsKey("jboss.server.config.dir")) { uri = System.getProperty("jboss.server.config.dir") + java.io.File.separatorChar + uri; } else { try { URL url = Thread.currentThread().getContextClassLoader().getResource(uri); if (url != null) { uri = url.getPath(); } else { log.severe("Failed to get absolute path for uri '" + uri + "'"); } } catch (Exception e) { log.log(Level.SEVERE, "Failed to get absolute path for uri '" + uri + "'", e); uri = null; } } } if (uri != null) { String[] uriParts = uri.split(Matcher.quoteReplacement(File.separator)); int startIndex = 0; // Remove any file prefix if (uriParts[0].equals("file:")) { startIndex++; } try { Path path = getPath(startIndex, uriParts); Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.toString().endsWith(".json")) { String json = new String(Files.readAllBytes(path)); CollectorConfiguration childConfig = mapper.readValue(json, CollectorConfiguration.class); if (childConfig != null) { config.merge(childConfig, false); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (Throwable e) { log.log(Level.SEVERE, "Failed to load configuration", e); } } return config; }
From source file:org.apache.openaz.xacml.pdp.test.TestBase.java
public static boolean isJSON(Path file) { return file.toString().endsWith(".json"); }
From source file:org.apache.openaz.xacml.pdp.test.TestBase.java
public static boolean isXML(Path file) { return file.toString().endsWith(".xml"); }
From source file:com.spectralogic.ds3cli.certification.Certification_Test.java
private static boolean testBulkPutAndBulkGetPerformance(final String testDescription, final Integer numFiles, final Long fileSize) throws Exception { final String bucketName = "test_bulk_performance_" + testDescription; boolean success = false; try {/*w w w. j ava 2 s . c om*/ // Start BULK_PUT OUT.insertLog("Create bucket."); final String createBucketCmd = "--http -c put_bucket -b " + bucketName; final CommandResponse createBucketResponse = Util.command(client, createBucketCmd); OUT.insertCommand(createBucketCmd, createBucketResponse.getMessage()); assertThat(createBucketResponse.getReturnCode(), is(0)); OUT.insertLog("List bucket."); final String listBucketCmd = "--http -c get_bucket -b " + bucketName; final CommandResponse getBucketResponse = Util.command(client, listBucketCmd); OUT.insertCommand(listBucketCmd, getBucketResponse.getMessage()); assertThat(getBucketResponse.getReturnCode(), is(0)); // Create temp files for BULK_PUT OUT.insertLog("Creating "); final Path bulkPutLocalTempDir = CertificationUtil.createTempFiles(bucketName, numFiles, fileSize); OUT.insertLog("Bulk PUT from bucket " + bucketName); final long startPutTime = getCurrentTime(); final String putBulkCmd = "--http -c put_bulk -b " + bucketName + " -d " + bulkPutLocalTempDir.toString(); final CommandResponse putBulkResponse = Util.command(client, putBulkCmd); OUT.insertCommand(putBulkCmd, putBulkResponse.getMessage()); final long endPutTime = getCurrentTime(); assertThat(putBulkResponse.getReturnCode(), is(0)); OUT.insertPerformanceMetrics(startPutTime, endPutTime, numFiles * fileSize, true); final CommandResponse getBucketResponseAfterBulkPut = Util.command(client, listBucketCmd); OUT.insertCommand(listBucketCmd, getBucketResponseAfterBulkPut.getMessage()); assertThat(getBucketResponseAfterBulkPut.getReturnCode(), is(0)); // Free up disk space FileUtils.forceDelete(bulkPutLocalTempDir.toFile()); // Start BULK_GET from the same bucket that we just did the BULK_PUT to, with a new local directory final Path bulkGetLocalTempDir = Files.createTempDirectory(bucketName); final long startGetTime = getCurrentTime(); OUT.insertLog("Bulk GET from bucket " + bucketName); final String getBulkCmd = "--http -c get_bulk -b " + bucketName + " -d " + bulkGetLocalTempDir.toString() + " -nt 3"; final CommandResponse getBulkResponse = Util.command(client, getBulkCmd); OUT.insertCommand(getBulkCmd, getBucketResponse.getMessage()); final long endGetTime = getCurrentTime(); OUT.insertPerformanceMetrics(startGetTime, endGetTime, numFiles * fileSize, true); assertThat(getBulkResponse.getReturnCode(), is(0)); success = true; // Free up disk space FileUtils.forceDelete(bulkGetLocalTempDir.toFile()); } finally { Util.deleteBucket(client, bucketName); } return success; }
From source file:misc.FileHandler.java
/** * Normalizes the given folder name, so that it can be stored in the * database./* w w w .j a v a2 s . c o m*/ * * @param folderName * the folder name to normalize. May be <code>null</code>. * @return the normalized folder name. */ public static Path normalizeFolder(Path folderName) { if (folderName != null) { Path normalized = folderName.normalize(); return ("".equals(normalized.toString().trim())) ? ROOT_PATH : normalized; } else { return ROOT_PATH; } }