final FsPath pp; if (null != ps) { men = new FsEntryName( uri.path(splitter.getMemberName()).getUri(), NULL); pp = scan(ps); } else { men = new FsEntryName( uri.path(path).query(memberQuery).getUri(), CANONICALIZE); if (men.isRoot() || (ppu = pp.toUri()).isOpaque() || !ppu.isAbsolute()) { mp = pp.resolve(men); } else { mp = new FsPath(new FsMountPoint(ppu), men); final FsScheme s = detector.getScheme(men.toString()); if (null != s) mp = new FsPath(new FsMountPoint(s, mp), ROOT);
@Override public boolean isReadable(FsEntryName name) throws IOException { Path file = target.resolve(name.getPath()); return Files.isReadable(file); }
/** * Returns the parent of the given file system path. * * @param path a file system path. * @return The parent file system path. * @throws URISyntaxException */ static @Nullable FsPath parent(FsPath path) throws URISyntaxException { FsMountPoint mp = path.getMountPoint(); FsEntryName en = path.getEntryName(); if (en.isRoot()) { if (null == mp) return null; path = mp.getPath(); if (null != path) return parent(path); URI mpu = mp.toUri(); URI pu = mpu.resolve(DOT_DOT_URI); if (mpu.getRawPath().length() <= pu.getRawPath().length()) return null; return new FsPath(pu); } else { URI pu = en.toUri().resolve(DOT_URI); en = new FsEntryName(pu, CANONICALIZE); return new FsPath(mp, en); } } }
@Override public void unlink(final FsEntryName name, BitField<FsOutputOption> options) throws IOException { try { delegate.unlink(name, options); } catch (final ControlFlowException ex) { // If the exception is caused by a key exception, then throw this // cause instead in order to avoid treating the target archive file // like a false positive and routing this operation to the parent // file system. // This prevents the application from inadvertently deleting an // encrypted ZIP file just because the user cancelled key prompting. final IOException keyEx = findKeyException(ex); if (null != keyEx) throw keyEx; throw ex; } if (name.isRoot()) getKeyManager().removeKeyProvider( driver.resourceUri(getModel(), name.toString())); }
@Test public void testConstructorWithValidUri() { for (final String[] params : new String[][] { // { $parent, $member, $result }, { "foo%3Abar", "baz", "foo%3Abar/baz" }, { "foo", "bar%3Abaz", "foo/bar%3Abaz" }, { "foo", "", "foo", }, { "", "", "", }, { "föö", "?bär", "föö?bär" }, { "föö?bär", "", "föö" }, { "föö?bär", "?täscht", "föö?täscht" }, { "föö", "", "föö" }, { "", "föö", "föö" }, { "föö", "bär", "föö/bär" }, }) { final FsEntryName parent = FsEntryName.create(URI.create(params[0])); final FsEntryName member = FsEntryName.create(URI.create(params[1])); final FsEntryName result = new FsEntryName(parent, member); assertThat(result.toUri(), equalTo(URI.create(params[2]))); assertThat(FsEntryName.create(result.toUri()), equalTo(result)); } }
/** * Returns {@code true} if and only if this {@code TPath} addresses an * archive file. * Whether or not this is true solely depends on the * {@link TArchiveDetector} which was used to construct this {@code TPath} * - no file system tests are performed by this method! * * @return {@code true} if and only if this {@code TPath} addresses an * archive file. * @see #isEntry */ public boolean isArchive() { final FsPath address = getAddress(); final boolean root = address.getEntryName().isRoot(); final FsMountPoint parent = address.getMountPoint().getParent(); return root && null != parent; }
if (null == cen) continue; final FsEntryName entryName = new FsEntryName( new UriBuilder().path(cen).getUri()); assertEquals(cen, entryName.getPath()); assertEquals(cen, fileSystem.getEntry(entryName).getName());
file.getParentFile().getPath(), separatorChar) && !enclEntryName.toString().isEmpty(); return true;
FsEntryName.create(uri); fail(param); } catch (IllegalArgumentException ex) { new FsEntryName(uri); fail(param); } catch (URISyntaxException ex) {
/** * Initialize this file object by scanning its path for archive * files, using the given {@code ancestor} file (i.e. a direct or * indirect parent file) if any. * {@code file} and {@code detector} must already be initialized! * Must not be called to re-initialize this object! */ private void scan(final @CheckForNull TFile ancestor) { final String path = super.getPath(); assert ancestor == null || path.startsWith(ancestor.getPath()); assert file.getPath().equals(path); assert null != detector; final StringBuilder enclEntryNameBuf = new StringBuilder(path.length()); scan(ancestor, detector, 0, path, enclEntryNameBuf, new Splitter(separatorChar, false)); try { enclEntryName = 0 >= enclEntryNameBuf.length() ? null : new FsEntryName( new UriBuilder().path(enclEntryNameBuf.toString()).getUri(), CANONICALIZE); } catch (URISyntaxException ex) { throw new AssertionError(ex); } }
@Test public void testCanonicalization() { for (final String[] params : new String[][] { // { $uri, $expected }, { "föö/", "föö" }, { "/föö", "föö" }, { "/föö/", "föö" }, { "/C:/", "C%3A" }, { "C%3A/", "C%3A" }, }) { final URI uri = URI.create(params[0]); final URI expected = URI.create(params[1]); final FsEntryName name = FsEntryName.create(uri, CANONICALIZE); final URI result = name.toUri(); assertThat(result, equalTo(expected)); } }
{ "", }, }) { final FsEntryName original = FsEntryName.create(URI.create(params[0]));
@Override public boolean isReadable(FsEntryName name) throws IOException { File file = new File(target, name.getPath()); return file.canRead(); }
/** * Returns {@code true} if and only if this {@code TPath} addresses an * entry located within an archive file. * Whether or not this is true solely depends on the * {@link TArchiveDetector} which was used to construct this {@code TPath} * - no file system tests are performed by this method! * * @return {@code true} if and only if this {@code TPath} addresses an * entry located within an archive file. * @see #isArchive */ public boolean isEntry() { final FsPath address = getAddress(); final boolean root = address.getEntryName().isRoot(); final FsMountPoint parent = address.getMountPoint().getParent(); return !root ? null != parent : null != parent && null != parent.getParent(); }
this.innerArchive = this.enclArchive = innerArchive; try { this.enclEntryName = new FsEntryName( new UriBuilder() .path(
@Test public void testResolve() { for (final String[] params : new String[][] { { "foo:bar:/baz?plonk!/", "", "baz", "foo:bar:/baz?plonk!/" }, { "foo:bar:/bäz?bööm!/", "bäng?plönk", "bäz/bäng?plönk", "foo:bar:/bäz?bööm!/bäng?plönk" }, { "foo:bar:/baz!/", "bang?boom", "baz/bang?boom", "foo:bar:/baz!/bang?boom" }, { "foo:bar:/baz!/", "bang", "baz/bang", "foo:bar:/baz!/bang" }, { "foo:bar:/baz!/", "", "baz", "foo:bar:/baz!/" }, { "foo:bar:/baz?plonk!/", "bang?boom", "baz/bang?boom", "foo:bar:/baz?plonk!/bang?boom" }, { "foo:bar:/baz?plonk!/", "bang", "baz/bang", "foo:bar:/baz?plonk!/bang" }, { "foo:/bar/", "baz?bang", null, "foo:/bar/baz?bang" }, { "foo:/bar/", "baz", null, "foo:/bar/baz" }, { "foo:/bar/", "", null, "foo:/bar/" }, { "foo:/bar/", "baz", null, "foo:/bar/baz" }, }) { final FsMountPoint mountPoint = FsMountPoint.create(URI.create(params[0])); final FsEntryName entryName = FsEntryName.create(URI.create(params[1])); final FsEntryName parentEntryName = null == params[2] ? null : FsEntryName.create(URI.create(params[2])); final FsPath path = FsPath.create(URI.create(params[3])); if (null != parentEntryName) assertThat(mountPoint.getPath().resolve(entryName).getEntryName(), equalTo(parentEntryName)); assertThat(mountPoint.resolve(entryName), equalTo(path)); assertThat(mountPoint.resolve(entryName).toUri().isAbsolute(), is(true)); } }
@Override public void unlink(FsEntryName name, BitField<FsOutputOption> options) throws IOException { Path file = target.resolve(name.getPath()); delete(file); }