public static FileSystem openZip(Path in) throws IOException { for (FileSystemProvider p : FileSystemProvider.installedProviders()) { String s = p.getScheme(); if ("jar".equals(s) || "zip".equalsIgnoreCase(s)) { return p.newFileSystem(in, new HashMap<String, Object>()); } } throw new IOException("cant find zipfs support"); }
@Override public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException { FileSystemProvider realProvider = path.getFileSystem().provider(); return realProvider.newFileSystem(path, env); }
private static FileSystem createZip(Path output) throws IOException { Map<String, Object> env = new HashMap<>(); env.put("create", "true"); Files.deleteIfExists(output); Path parent = output.getParent(); if (parent != null && !Files.exists(parent)) { Files.createDirectories(parent); } for (FileSystemProvider p : FileSystemProvider.installedProviders()) { String s = p.getScheme(); if ("jar".equals(s) || "zip".equalsIgnoreCase(s)) { return p.newFileSystem(output, env); } } throw new IOException("cant find zipfs support"); }
public static FileSystem createZip(Path output) throws IOException { Map<String, Object> env = new HashMap<>(); env.put("create", "true"); Files.deleteIfExists(output); createParentDirectories(output); for (FileSystemProvider p : FileSystemProvider.installedProviders()) { String s = p.getScheme(); if ("jar".equals(s) || "zip".equalsIgnoreCase(s)) { return p.newFileSystem(output, env); } } throw new IOException("cant find zipfs support"); }
@Test public void second() throws Exception { TempDirectory tempDirectory = new TempDirectory("test"); try { Path jarPath = tempDirectory.create("some-jar").resolve("some.jar"); try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jarPath.toFile()))) { out.putNextEntry(new JarEntry("README.txt")); out.write("hi!".getBytes()); } FileSystemProvider jarFSP = FileSystemProvider.installedProviders().stream() .filter(p -> p.getScheme().equals("jar")).findFirst().get(); Path fakeJarFile = Paths.get(jarPath.toUri()); // if Thread.interrupted() was true, this would fail in AbstractInterruptibleChannel: jarFSP.newFileSystem(fakeJarFile, new HashMap<>()); } finally { tempDirectory.destroy(); } fail("failed for the right reason"); } }
@Override public FileSystem newFileSystem(final Path path, final Map<String, ?> env) throws IOException { return delegate.newFileSystem(path, env); }
@Override public FileSystem newFileSystem(final URI uri, final Map<String, ?> env) throws IOException { return delegate.newFileSystem(uri, env); }
@Override public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException { FileSystemProvider realProvider = path.getFileSystem().provider(); return realProvider.newFileSystem(path, env); }
for (FileSystemProvider provider : FileSystemProvider.installedProviders()) { if ("jar".equals(provider.getScheme())) return provider.newFileSystem((new File(Start.class .getProtectionDomain().getCodeSource().getLocation().toURI())) .toPath(), new HashMap<String, Object>()); }
@Override public FileSystem newFileSystem(final URI uri, final Map<String, ?> env) throws IOException { return new WrappedFileSystem<>(wrappedPathType, wrapped().newFileSystem(uri, env)); }
@Test public void testWrongUriAtProviderNewFails() throws IOException { assertThatThrownBy( () -> FS.provider().newFileSystem( URI.create( FS.provider().getScheme() + "N:" ), Collections.EMPTY_MAP ) ). isInstanceOf( IllegalArgumentException.class ); }
@Override public FileSystem newFileSystem(final Path path, final Map<String, ?> env) throws IOException {return wrapped().newFileSystem(unwrap(path), env);}
@Test public void testNewFileSystemOfExistingThrows() throws IOException { assertThatThrownBy( () -> FS.provider().newFileSystem( toURI( FS ), getEnv() ) ). isInstanceOf( FileSystemAlreadyExistsException.class ); }
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException { this.archivePath = archivePath; if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) { Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue); FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider(); Assert.checkNonNull(jarFSProvider, "should have been caught before!"); this.fileSystem = jarFSProvider.newFileSystem(archivePath, env); } else { this.fileSystem = FileSystems.newFileSystem(archivePath, null); } packages = new HashMap<>(); for (Path root : fileSystem.getRootDirectories()) { Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { if (isValid(dir.getFileName())) { packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir); return FileVisitResult.CONTINUE; } else { return FileVisitResult.SKIP_SUBTREE; } } }); } }
public AbstractSourceInstance(Properties properties) { this.properties = properties; List<FileSystemProvider> list = JimfsFileSystemProvider.installedProviders(); try { URI uri = new URI("jimfs", "vefa", null, null); ImmutableMap<String, ?> env = ImmutableMap.of("config", Configuration.unix()); for (FileSystemProvider provider : list) if (provider instanceof JimfsFileSystemProvider) fileSystem = provider.newFileSystem(uri, env); if (fileSystem == null) fileSystem = new JimfsFileSystemProvider().newFileSystem(uri, env); } catch (Exception e) { throw new RuntimeException("Unable to create VEFA Validator instance", e); } }
public static FileSystem zipFileSystem( URI fileJarURI ) { final Map<String, Object> env = Maps.map( "create", ( Object ) "true" ); FileSystemProvider provider = loadFileSystemProvider("jar"); requireNonNull( provider, "Zip file provider not found" ); FileSystem fs = null; try { fs = provider.getFileSystem( fileJarURI ); } catch ( Exception ex ) { if ( provider != null ) { try { fs = provider.newFileSystem( fileJarURI, env ); } catch ( IOException ex2 ) { Exceptions.handle( FileSystem.class, sputs( "unable to load", fileJarURI, "as zip file system" ), ex2 ); } } } requireNonNull( provider, "Zip file system was not found" ); return fs; }
public static FileSystem zipFileSystem( URI fileJarURI ) { final Map<String, Object> env = Maps.map( "create", ( Object ) "true" ); FileSystemProvider provider = loadFileSystemProvider("jar"); requireNonNull( provider, "Zip file provider not found" ); FileSystem fs = null; try { fs = provider.getFileSystem( fileJarURI ); } catch ( Exception ex ) { if ( provider != null ) { try { fs = provider.newFileSystem( fileJarURI, env ); } catch ( IOException ex2 ) { Exceptions.handle( FileSystem.class, sputs( "unable to load", fileJarURI, "as zip file system" ), ex2 ); } } } requireNonNull( provider, "Zip file system was not found" ); return fs; }
public static FileSystem zipFileSystem( URI fileJarURI ) { final Map<String, Object> env = Maps.map( "create", ( Object ) "true" ); FileSystemProvider provider = loadFileSystemProvider("jar"); Exceptions.requireNonNull(provider, "Zip file provider not found"); FileSystem fs = null; try { fs = provider.getFileSystem( fileJarURI ); } catch ( Exception ex ) { if ( provider != null ) { try { fs = provider.newFileSystem( fileJarURI, env ); } catch ( IOException ex2 ) { Exceptions.handle( FileSystem.class, Str.sputs("unable to load", fileJarURI, "as zip file system"), ex2 ); } } } Exceptions.requireNonNull(provider, "Zip file system was not found"); return fs; }
public static FileSystem zipFileSystem( URI fileJarURI ) { final Map<String, Object> env = Maps.map( "create", ( Object ) "true" ); FileSystemProvider provider = loadFileSystemProvider("jar"); Exceptions.requireNonNull(provider, "Zip file provider not found"); FileSystem fs = null; try { fs = provider.getFileSystem( fileJarURI ); } catch ( Exception ex ) { if ( provider != null ) { try { fs = provider.newFileSystem( fileJarURI, env ); } catch ( IOException ex2 ) { Exceptions.handle( FileSystem.class, Str.sputs("unable to load", fileJarURI, "as zip file system"), ex2 ); } } } Exceptions.requireNonNull(provider, "Zip file system was not found"); return fs; }
public static FileSystem zipFileSystem( URI fileJarURI ) { final Map<String, Object> env = Maps.map( "create", ( Object ) "true" ); FileSystemProvider provider = loadFileSystemProvider("jar"); requireNonNull( provider, "Zip file provider not found" ); FileSystem fs = null; try { fs = provider.getFileSystem( fileJarURI ); } catch ( Exception ex ) { if ( provider != null ) { try { fs = provider.newFileSystem( fileJarURI, env ); } catch ( IOException ex2 ) { Exceptions.handle( FileSystem.class, sputs( "unable to load", fileJarURI, "as zip file system" ), ex2 ); } } } requireNonNull( provider, "Zip file system was not found" ); return fs; }