List of usage examples for java.io File toPath
public Path toPath()
From source file:com.parallax.server.blocklyprop.servlets.HelpSearchServlet.java
private IndexSearcher initialize() { if (indexSearcher != null) { return indexSearcher; }/*from ww w .ja va 2 s . c o m*/ try { File luceneIndexLocation = new File(new File(System.getProperty("user.home")), configuration.getString("help.lucene", DEFAULT_LUCENE_DIRECTORY)); directory = FSDirectory.open(luceneIndexLocation.toPath()); indexReader = DirectoryReader.open(directory); indexSearcher = new IndexSearcher(indexReader); return indexSearcher; } catch (IOException ex) { return null; } }
From source file:de.dentrassi.rpm.builder.YumMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { this.logger = new Logger(getLog()); try {/* w w w .j a v a2 s . c o m*/ final Builder builder = new RepositoryCreator.Builder(); builder.setTarget(new FileSystemSpoolOutTarget(this.outputDirectory.toPath())); if (!this.skipSigning) { final PGPPrivateKey privateKey = SigningHelper.loadKey(this.signature, this.logger); if (privateKey != null) { final int digestAlgorithm = HashAlgorithm.from(this.signature.getHashAlgorithm()).getValue(); builder.setSigning(output -> new SigningStream(output, privateKey, digestAlgorithm, false, "RPM builder Mojo - de.dentrassi.maven:rpm")); } } final RepositoryCreator creator = builder.build(); this.packagesPath = new File(this.outputDirectory, "packages"); Files.createDirectories(this.packagesPath.toPath()); final Collection<Path> paths = Lists.newArrayList(); if (!this.skipDependencies) { final Set<Artifact> deps = this.project.getArtifacts(); if (deps != null) { paths.addAll(deps.stream()// .filter(d -> d.getType().equalsIgnoreCase("rpm"))// .map(d -> d.getFile().toPath())// .collect(Collectors.toList())); } } else { this.logger.debug("Skipped RPM artifacts from maven dependencies"); } if (this.files != null) { paths.addAll(this.files.stream().map(f -> f.toPath()).collect(Collectors.toList())); } if (this.directories != null) { for (final File dir : this.directories) { Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().toLowerCase().endsWith(".rpm")) { paths.add(file); } return FileVisitResult.CONTINUE; } }); } } addPackageList(creator, paths); } catch (final IOException e) { throw new MojoExecutionException("Failed to write repository", e); } }
From source file:net.krotscheck.util.ResourceUtilTest.java
/** * Assert that we can read a resource as a string. * * @throws Exception Should not be thrown. *//*from w w w .ja va 2s. c o m*/ @Test public void testGetResourceAsString() throws Exception { String name = "/valid-resource-file.txt"; String content = ResourceUtil.getResourceAsString(name); Assert.assertEquals("valid resource content", content); String invalidName = "/invalid-resource-file.txt"; String invalidContent = ResourceUtil.getResourceAsString(invalidName); Assert.assertEquals("", invalidContent); // Make the file write only File resource = ResourceUtil.getFileForResource(name); Set<PosixFilePermission> oldPerms = Files.getPosixFilePermissions(resource.toPath()); Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.OTHERS_EXECUTE); // Write only... Files.setPosixFilePermissions(resource.toPath(), perms); String writeOnlyName = "/valid-resource-file.txt"; String writeOnlyContent = ResourceUtil.getResourceAsString(writeOnlyName); Assert.assertEquals("", writeOnlyContent); Files.setPosixFilePermissions(resource.toPath(), oldPerms); }
From source file:net.krotscheck.util.ResourceUtilTest.java
/** * Assert that we can read a resource as a stream. * * @throws Exception Should not be thrown. */// w w w.j a v a2s . c o m @Test public void testGetResourceAsStream() throws Exception { String name = "/valid-resource-file.txt"; InputStream stream = ResourceUtil.getResourceAsStream(name); Assert.assertTrue(stream.available() > 0); String invalidName = "/invalid-resource-file.txt"; InputStream invalidContent = ResourceUtil.getResourceAsStream(invalidName); Assert.assertTrue(invalidContent instanceof NullInputStream); Assert.assertTrue(invalidContent.available() == 0); // Make the file write only File resource = ResourceUtil.getFileForResource(name); Set<PosixFilePermission> oldPerms = Files.getPosixFilePermissions(resource.toPath()); Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.OTHERS_EXECUTE); // Write only... Files.setPosixFilePermissions(resource.toPath(), perms); String writeOnlyName = "/valid-resource-file.txt"; InputStream writeOnlyContent = ResourceUtil.getResourceAsStream(writeOnlyName); Assert.assertTrue(writeOnlyContent instanceof NullInputStream); Assert.assertTrue(writeOnlyContent.available() == 0); Files.setPosixFilePermissions(resource.toPath(), oldPerms); }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test public void testDirectoryOnlyMatchingNamePatterns() throws IOException { final File directory = new File( "./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryOnlyMatchingNamePatterns"); deleteDirectory(directory);//w w w. jav a 2 s . c o m Files.createDirectory(directory.toPath()); Files.write(directory.toPath().resolve("foo.json"), "[\"one\"]".getBytes(Charsets.UTF_8)); Files.write(directory.toPath().resolve("bar.txt"), "[\"two\"]".getBytes(Charsets.UTF_8)); final JsonNodeDirectorySource source = new JsonNodeDirectorySource.Builder().setDirectory(directory) .addFileNamePattern(Pattern.compile(".*\\.json")).build(); Assert.assertTrue(source.getJsonNode().isPresent()); Assert.assertTrue(source.getJsonNode().get().isArray()); final ArrayNode arrayNode = (ArrayNode) source.getJsonNode().get(); Assert.assertEquals(1, arrayNode.size()); Assert.assertTrue(arrayNodeContains(arrayNode, "one")); }
From source file:com.thoughtworks.go.agent.common.util.JarUtilTest.java
@Test public void shouldExtractJars() throws Exception { File sourceFile = new File(PATH_WITH_HASHES + "test-agent.jar"); File outputTmpDir = temporaryFolder.newFolder(); Set<File> files = new HashSet<>(JarUtil.extractFilesInLibDirAndReturnFiles(sourceFile, jarEntry -> jarEntry.getName().endsWith(".class"), outputTmpDir)); Set<File> actualFiles = Files.list(outputTmpDir.toPath()).map(Path::toFile).collect(Collectors.toSet()); assertEquals(files, actualFiles);/*ww w . ja va2 s . co m*/ assertEquals(files.size(), 2); Set<String> fileNames = files.stream().map(File::getName).collect(Collectors.toSet()); assertEquals(fileNames, new HashSet<>(Arrays.asList("ArgPrintingMain.class", "HelloWorldStreamWriter.class"))); }
From source file:com.hurence.logisland.processor.DetectOutliersTest.java
@Test @Ignore("too long") public void testDetection() throws IOException { final TestRunner testRunner = TestRunners.newTestRunner(new DetectOutliers()); testRunner.setProperty(DetectOutliers.ROTATION_POLICY_TYPE, "by_amount"); testRunner.setProperty(DetectOutliers.ROTATION_POLICY_AMOUNT, "100"); testRunner.setProperty(DetectOutliers.ROTATION_POLICY_UNIT, "points"); testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_TYPE, "by_amount"); testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_AMOUNT, "10"); testRunner.setProperty(DetectOutliers.CHUNKING_POLICY_UNIT, "points"); testRunner.setProperty(DetectOutliers.GLOBAL_STATISTICS_MIN, "-100000"); testRunner.setProperty(DetectOutliers.MIN_AMOUNT_TO_PREDICT, "100"); testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_NORMAL, "3.5"); testRunner.setProperty(DetectOutliers.ZSCORE_CUTOFFS_MODERATE, "5"); testRunner.setProperty(DetectOutliers.RECORD_VALUE_FIELD, "value"); testRunner.setProperty(DetectOutliers.RECORD_TIME_FIELD, "timestamp"); testRunner.assertValid();//from w w w. jav a 2s . c o m File f = new File(RESOURCES_DIRECTORY); Pair<Integer, Integer>[] results = new Pair[] { new Pair(4032, 124), new Pair(4032, 8), new Pair(4032, 315), new Pair(4032, 0), new Pair(4032, 29), new Pair(4032, 2442), new Pair(4032, 314), new Pair(4032, 296) }; int count = 0; for (File file : FileUtils.listFiles(f, new SuffixFileFilter(".csv"), TrueFileFilter.INSTANCE)) { if (count >= results.length) break; BufferedReader reader = Files.newBufferedReader(file.toPath(), ENCODING); List<Record> records = TimeSeriesCsvLoader.load(reader, true, inputDateFormat); Assert.assertTrue(!records.isEmpty()); testRunner.clearQueues(); testRunner.enqueue(records.toArray(new Record[records.size()])); testRunner.run(); testRunner.assertAllInputRecordsProcessed(); System.out.println("records.size() = " + records.size()); System.out.println("testRunner.getOutputRecords().size() = " + testRunner.getOutputRecords().size()); testRunner.assertOutputRecordsCount(results[count].getSecond()); count++; } }
From source file:controller.FileWatcher.java
@Override public void onFileCreate(File arg0) { String log = "File is created " + arg0.getAbsolutePath() + "\n"; System.out.println(log);// www. java 2s .c o m jTextArea1.append(log); if (!Files.isSymbolicLink(arg0.toPath())) { String fileName = ServerUtil.convertPath(arg0.getAbsolutePath(), MyDropboxSwing.urls); FileCreate fileCreate = new FileCreate(fileName, Constants.IS_FILE); lstCommit.add(fileCreate); } }
From source file:ru.codemine.ccms.service.SettingsService.java
/** * ? ?? //from w w w . j a v a2 s. c om * @return */ public String getStorageRootPath() { File test = new File(storageRootPath); if (!test.isDirectory()) { try { Files.createDirectory(test.toPath()); } catch (IOException ex) { log.error( "? ? ? ? ! : " + storageRootPath + ", : " + ex.getMessage()); } } return storageRootPath; }
From source file:ru.codemine.ccms.service.SettingsService.java
public String getStorageTasksPath() { File test = new File(storageTasksPath); if (!test.isDirectory()) { try {//from ww w . jav a 2s . c o m Files.createDirectory(test.toPath()); } catch (IOException ex) { log.error( "? ? ? ? ! : " + storageTasksPath + ", : " + ex.getMessage()); } } return storageTasksPath; }