本文整理了Java中java.nio.file.FileSystems.getFileSystem()
方法的一些代码示例,展示了FileSystems.getFileSystem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileSystems.getFileSystem()
方法的具体详情如下:
包路径:java.nio.file.FileSystems
类名称:FileSystems
方法名:getFileSystem
暂无
代码示例来源:origin: Graylog2/graylog2-server
@Override
public FileSystem load(@Nonnull URI key) throws Exception {
try {
return FileSystems.getFileSystem(key);
} catch (FileSystemNotFoundException e) {
try {
return FileSystems.newFileSystem(key, Collections.emptyMap());
} catch (FileSystemAlreadyExistsException f) {
return FileSystems.getFileSystem(key);
}
}
}
});
代码示例来源:origin: pmd/pmd
private static FileSystem getFileSystem(URI uri) throws IOException {
try {
return FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
return FileSystems.newFileSystem(uri, Collections.<String, String>emptyMap());
}
}
代码示例来源:origin: spring-projects/spring-batch
private void initFileSystem(URI uri) throws IOException {
try {
FileSystems.getFileSystem(uri);
}
catch (FileSystemNotFoundException e) {
FileSystems.newFileSystem(uri, Collections.emptyMap());
}
catch (IllegalArgumentException e) {
FileSystems.getDefault();
}
}
代码示例来源:origin: googleapis/google-cloud-java
public static void main(String... args) throws IOException {
FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"));
byte[] data = "hello world".getBytes(StandardCharsets.UTF_8);
Path path = fs.getPath("/object");
Files.write(path, data);
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
}
}
代码示例来源:origin: googleapis/google-cloud-java
private static void checkGcs() {
FileSystem fs = FileSystems.getFileSystem(URI.create("gs://domain-registry-alpha"));
System.out.println("Success! We can instantiate a gs:// filesystem.");
System.out.println("isOpen: " + fs.isOpen());
System.out.println("isReadOnly: " + fs.isReadOnly());
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
try {
try {
fileSystem = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), classLoader);
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testResolve_willWorkWithRecursiveCopy() throws IOException {
// See: http://stackoverflow.com/a/10068306
try (FileSystem fsSource = FileSystems.getFileSystem(URI.create("gs://hello"));
FileSystem fsTarget = FileSystems.getFileSystem(URI.create("gs://cat"))) {
Path targetPath = fsTarget.getPath("/some/folder/");
Path relSrcPath = fsSource.getPath("file.txt");
assertThat((Object) targetPath.resolve(relSrcPath))
.isEqualTo(fsTarget.getPath("/some/folder/file.txt"));
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRelativize_willWorkWithRecursiveCopy() throws IOException {
// See: http://stackoverflow.com/a/10068306
try (FileSystem fsSource = FileSystems.getFileSystem(URI.create("gs://hello"));
FileSystem fsTarget = FileSystems.getFileSystem(URI.create("gs://cat"))) {
Path targetPath = fsTarget.getPath("/some/folder/");
Path sourcePath = fsSource.getPath("/sloth/");
Path file = fsSource.getPath("/sloth/file.txt");
assertThat((Object) targetPath.resolve(sourcePath.relativize(file)))
.isEqualTo(fsTarget.getPath("/some/folder/file.txt"));
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testExists_false() throws IOException {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
assertThat(Files.exists(fs.getPath("/angel"))).isFalse();
}
}
代码示例来源:origin: kaaproject/kaa
protected String readSchemaFileAsString(String filePath) throws IOException {
try {
URI uri = this.getClass().getClassLoader().getResource(filePath).toURI();
String[] array = uri.toString().split("!");
Path path;
if (array.length > 1) {
LOG.info("Creating fs for {}", array[0]);
FileSystem fs;
try {
fs = FileSystems.newFileSystem(URI.create(array[0]), new HashMap<String, String>());
} catch (FileSystemAlreadyExistsException e) {
fs = FileSystems.getFileSystem(URI.create(array[0]));
}
path = fs.getPath(array[1]);
} else {
path = Paths.get(uri);
}
return new String(Files.readAllBytes(path));
} catch (URISyntaxException e) {
LOG.error("Can't generate configs {}", e);
}
return null;
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testIsDirectory() throws Exception {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://doodle"))) {
assertThat(Files.isDirectory(fs.getPath(""))).isTrue();
assertThat(Files.isDirectory(fs.getPath("/"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("./"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("cat/.."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("hello/cat/.."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("cat/../"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("hello/cat/../"))).isTrue();
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testEquals() throws IOException {
try (FileSystem bucket1 = CloudStorageFileSystem.forBucket("bucket");
FileSystem bucket2 = FileSystems.getFileSystem(URI.create("gs://bucket"));
FileSystem doge1 = CloudStorageFileSystem.forBucket("doge");
FileSystem doge2 = FileSystems.getFileSystem(URI.create("gs://doge"))) {
new EqualsTester()
.addEqualityGroup(bucket1, bucket2)
.addEqualityGroup(doge1, doge2)
.testEquals();
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testNullness() throws Exception {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://blood"))) {
NullPointerTester tester = new NullPointerTester();
tester.ignore(CloudStorageFileSystemProvider.class.getMethod("equals", Object.class));
tester.setDefault(URI.class, URI.create("gs://blood"));
tester.setDefault(Path.class, fs.getPath("and/one"));
tester.setDefault(OpenOption.class, CREATE);
tester.setDefault(CopyOption.class, COPY_ATTRIBUTES);
tester.testAllPublicStaticMethods(CloudStorageFileSystemProvider.class);
tester.testAllPublicInstanceMethods(new CloudStorageFileSystemProvider());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testNullness() throws IOException, NoSuchMethodException, SecurityException {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
NullPointerTester tester =
new NullPointerTester()
.ignore(CloudStorageFileSystem.class.getMethod("equals", Object.class))
.setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT)
.setDefault(StorageOptions.class, LocalStorageHelper.getOptions());
tester.testAllPublicStaticMethods(CloudStorageFileSystem.class);
tester.testAllPublicInstanceMethods(fs);
}
}
代码示例来源:origin: pf4j/pf4j
private static FileSystem getFileSystem(URI uri) throws IOException {
try {
return FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
return FileSystems.newFileSystem(uri, Collections.<String, String>emptyMap());
}
}
代码示例来源:origin: opensourceBIM/BIMserver
public FileSystem getOrCreateFileSystem(URI uri) throws IOException {
FileSystem fileSystem = null;
try {
fileSystem = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
fileSystem = FileSystems.newFileSystem(uri, env, null);
LOGGER.debug("Created VFS for " + uri);
}
return fileSystem;
}
代码示例来源:origin: schemaspy/schemaspy
private void ensureFileSystemExists(URL url) throws URISyntaxException, IOException {
try {
FileSystems.getFileSystem(url.toURI());
} catch (FileSystemNotFoundException notFound) {
FileSystems.newFileSystem(url.toURI(), Collections.singletonMap("create","false"));
}
}
}
代码示例来源:origin: winder/Universal-G-Code-Sender
try {
fileSystem = FileSystems.getFileSystem(location);
} catch (FileSystemNotFoundException e) {
代码示例来源:origin: boonproject/boon
private static void eachLine( String location, URI uri, EachLine eachLine ) throws Exception {
try {
FileSystem fileSystem = FileSystems.getFileSystem( uri );
Path fsPath = fileSystem.getPath( location );
BufferedReader buf = Files.newBufferedReader( fsPath, DEFAULT_CHARSET );
eachLine( buf, eachLine );
} catch ( ProviderNotFoundException ex ) {
eachLine( uri.toURL().openStream(), eachLine );
}
}
代码示例来源:origin: boonproject/boon
private static void eachLine( String location, URI uri, EachLine eachLine ) throws Exception {
try {
FileSystem fileSystem = FileSystems.getFileSystem( uri );
Path fsPath = fileSystem.getPath( location );
BufferedReader buf = Files.newBufferedReader( fsPath, DEFAULT_CHARSET );
eachLine( buf, eachLine );
} catch ( ProviderNotFoundException ex ) {
eachLine( uri.toURL().openStream(), eachLine );
}
}
内容来源于网络,如有侵权,请联系作者删除!