use of java.nio.file.FileSystem in project beam by apache.
the class ApexYarnLauncherTest method testCreateJar.
@Test
public void testCreateJar() throws Exception {
File baseDir = new File("./target/testCreateJar");
File srcDir = new File(baseDir, "src");
String file1 = "file1";
FileUtils.forceMkdir(srcDir);
FileUtils.write(new File(srcDir, file1), "file1");
File jarFile = new File(baseDir, "test.jar");
ApexYarnLauncher.createJar(srcDir, jarFile);
Assert.assertTrue("exists: " + jarFile, jarFile.exists());
URI uri = URI.create("jar:" + jarFile.toURI());
final Map<String, ?> env = Collections.singletonMap("create", "true");
try (final FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
Assert.assertTrue("manifest", Files.isRegularFile(zipfs.getPath(JarFile.MANIFEST_NAME)));
Assert.assertTrue("file1", Files.isRegularFile(zipfs.getPath(file1)));
}
}
use of java.nio.file.FileSystem in project ratpack by ratpack.
the class JarFileEphemeralBaseDir method getJarPath.
private static Path getJarPath(File jar) {
URI uri = URI.create("jar:" + jar.toURI().toString());
Map<String, String> env = new HashMap<>();
env.put("create", "true");
FileSystem fileSystem;
try {
fileSystem = FileSystems.newFileSystem(uri, env);
} catch (IOException e) {
throw uncheck(e);
}
return fileSystem.getPath("/");
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemTest method testDeleteEmptyFolder.
@Test
public void testDeleteEmptyFolder() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
List<Path> paths = new ArrayList<>();
paths.add(fs.getPath("dir/angel"));
paths.add(fs.getPath("dir/dir2/another_angel"));
paths.add(fs.getPath("atroot"));
for (Path path : paths) {
Files.write(path, ALONE.getBytes(UTF_8));
}
// we can delete non-existent folders, because they are not represented on disk anyways.
Files.delete(fs.getPath("ghost/"));
Files.delete(fs.getPath("dir/ghost/"));
Files.delete(fs.getPath("dir/dir2/ghost/"));
// likewise, deleteIfExists works.
Files.deleteIfExists(fs.getPath("ghost/"));
Files.deleteIfExists(fs.getPath("dir/ghost/"));
Files.deleteIfExists(fs.getPath("dir/dir2/ghost/"));
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemTest method testMatcher.
@Test
public void testMatcher() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
String pattern1 = "glob:*.java";
PathMatcher javaFileMatcher = fs.getPathMatcher(pattern1);
assertMatches(fs, javaFileMatcher, "a.java", true);
assertMatches(fs, javaFileMatcher, "a.text", false);
assertMatches(fs, javaFileMatcher, "folder/c.java", true);
assertMatches(fs, javaFileMatcher, "d", false);
String pattern2 = "glob:*.{java,text}";
PathMatcher javaAndTextFileMatcher = fs.getPathMatcher(pattern2);
assertMatches(fs, javaAndTextFileMatcher, "a.java", true);
assertMatches(fs, javaAndTextFileMatcher, "a.text", true);
assertMatches(fs, javaAndTextFileMatcher, "folder/c.java", true);
assertMatches(fs, javaAndTextFileMatcher, "d", false);
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemTest method testDeleteFullFolder.
@Test
public void testDeleteFullFolder() throws IOException {
thrown.expect(CloudStoragePseudoDirectoryException.class);
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
Files.write(fs.getPath("dir/angel"), ALONE.getBytes(UTF_8));
// we cannot delete existing folders if they contain something
Files.delete(fs.getPath("dir/"));
}
}
Aggregations