assert null != enclEntryName; return new FsPath( new FsMountPoint( scheme, new FsPath( new FsMountPoint(enclArchive.toURI(), CANONICALIZE), enclEntryName)), ROOT); } else { return new FsPath( new FsMountPoint(scheme, new FsPath(file)), ROOT); assert null != enclEntryName; return new FsPath( new FsMountPoint(enclArchive.toURI(), CANONICALIZE), enclEntryName); } else {
}) { final URI uri = URI.create(param); final FsMountPoint mountPoint = FsMountPoint.create(uri); assertThat(mountPoint.toUri(), sameInstance(uri)); assertThat(mountPoint.getPath(), nullValue()); assertThat(mountPoint.toString(), equalTo(mountPoint.toUri().toString())); assertThat(mountPoint, equalTo(FsMountPoint.create(mountPoint.toUri()))); assertThat(mountPoint.hashCode(), equalTo(FsMountPoint.create(mountPoint.toUri()).hashCode())); { "foo:bar:/baz!/", "foo", "bar:/baz" }, }) { final FsMountPoint mountPoint = FsMountPoint.create(URI.create(params[0]), FsUriModifier.CANONICALIZE); final FsScheme scheme = FsScheme.create(params[1]); final FsPath path = FsPath.create(URI.create(params[2])); assertThat(mountPoint.getScheme(), equalTo(scheme)); assertThat(mountPoint.getPath(), equalTo(path)); assertThat(mountPoint.toString(), equalTo(mountPoint.toUri().toString())); assertThat(FsMountPoint.create(mountPoint.toUri()), equalTo(mountPoint)); assertThat(FsMountPoint.create(URI.create(mountPoint.toUri().getScheme() + ":" + mountPoint.getPath() + "!/")), equalTo(mountPoint)); assertThat(FsMountPoint.create(mountPoint.getScheme(), mountPoint.getPath()), equalTo(mountPoint)); assertThat(FsMountPoint.create(mountPoint.toUri()), equalTo(mountPoint)); assertThat(FsMountPoint.create(mountPoint.toUri()).hashCode(), equalTo(mountPoint.hashCode())); assertThat(FsMountPoint.create(mountPoint.resolve(ROOT).toUri()), equalTo(mountPoint));
@SuppressWarnings("LeakingThisInConstructor") private TFile( final FsMountPoint mountPoint, final TArchiveDetector detector) { super(mountPoint.toHierarchicalUri()); this.file = new File(super.getPath()); this.detector = detector; final FsPath mpp = mountPoint.getPath(); if (null == mpp) { assert !mountPoint.toUri().isOpaque(); this.enclArchive = null; this.enclEntryName = null; this.innerArchive = null; } else { assert mountPoint.toUri().isOpaque(); if (mpp.toUri().isOpaque()) { this.enclArchive = new TFile(mpp.getMountPoint(), detector); this.enclEntryName = mpp.getEntryName(); } else { this.enclArchive = null; this.enclEntryName = null; } this.innerArchive = this; this.controller = getController(mountPoint); } assert invariants(); }
if (null != enclArchive) { assert null != enclEntryName; return new FsMountPoint( scheme, new FsPath( new FsMountPoint(enclArchive.toURI(), CANONICALIZE), enclEntryName)).toUri(); } else { return new FsMountPoint(scheme, new FsPath(file)).toUri(); new FsMountPoint(enclArchive.toURI(), CANONICALIZE), enclEntryName).toUri(); } else {
/** * 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); } } }
@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)); } }
public void testConstructorWithInvalidUri() throws URISyntaxException { try { FsMountPoint.create((URI) null); fail(); } catch (NullPointerException expected) { new FsMountPoint((URI) null); fail(); } catch (NullPointerException expected) { FsMountPoint.create((URI) null, NULL); fail(); } catch (NullPointerException expected) { new FsMountPoint((URI) null, NULL); fail(); } catch (NullPointerException expected) { FsMountPoint.create((URI) null, CANONICALIZE); fail(); } catch (NullPointerException expected) { new FsMountPoint((URI) null, CANONICALIZE); fail(); } catch (NullPointerException expected) { FsMountPoint.create((FsScheme) null, null); fail(); } catch (NullPointerException expected) {
@Test public void testHierarchicalize() { for (final String[] params : new String[][] { { "foo:bar:baz:/x/bö%20m?plö%20k!/bä%20g?zö%20k!/", "baz:/x/bö%20m/bä%20g?zö%20k" }, { "foo:bar:baz:/x/bööm?plönk!/bäng?zönk!/", "baz:/x/bööm/bäng?zönk" }, { "foo:bar:baz:/boom?plonk!/bang?zonk!/", "baz:/boom/bang?zonk" }, { "foo:bar:baz:/boom!/bang!/", "baz:/boom/bang" }, { "foo:bar:/baz?boom!/", "bar:/baz?boom" }, { "foo:bar:/baz!/", "bar:/baz" }, { "foo:/bar/", "foo:/bar/" }, }) { final FsMountPoint mp = FsMountPoint.create(URI.create(params[0])); final URI hmp = mp.toHierarchicalUri(); final FsPath p = FsPath.create(URI.create(params[0])); final URI hp = p.toHierarchicalUri(); assertThat(hmp, equalTo(URI.create(params[1]))); assertThat(hmp, equalTo(hp)); } } }
final FsPath mpp = mp.getPath(); final FsEntryName en;
@Test @SuppressWarnings("ResultOfObjectAllocationIgnored") public void testConstructorWithMountPoint() { for (final String[] params : new String[][] { { "foo:/bar/" }, }) { final FsMountPoint mountPoint = FsMountPoint.create(URI.create(params[0])); final FsModel model = newModel(mountPoint, null); assertThat(model.getMountPoint(), sameInstance(mountPoint)); assertThat(model.getMountPoint().getPath(), nullValue()); assertThat(model.getParent(), nullValue()); assertThat(model.isMounted(), is(false)); } }
private static FsModel newNonArchiveModel() { return new FsTestModel( FsMountPoint.create(URI.create("file:/")), null); }
/** * A template method which derives the URI which represents the mount point * of the given file system model as the base resource URI for looking up * {@link KeyProvider}s. * <p> * The implementation in the class {@link ZipDriver} returns the * expression {@code model.getMountPoint().toHierarchicalUri()} * in order to improve the readability of the URI in comparison to the * expression {@code model.getMountPoint().toUri()}. * * @param model the file system model. * @return The URI which represents the file system model's mount point. * @see <a href="http://java.net/jira/browse/TRUEZIP-72">#TRUEZIP-72</a> */ public URI mountPointUri(FsModel model) { return model.getMountPoint().toHierarchicalUri(); }
FileController(final FsModel model) { super(model); if (null != model.getParent()) throw new IllegalArgumentException(); URI uri = model.getMountPoint().toUri(); if ('\\' == separatorChar && null != uri.getRawAuthority()) { try { // Postfix: Move Windows UNC host from authority to path // component because the File class can't deal with this. // Note that the authority parameter must not be null and that // you cannot use the UriBuilder class - using either of these // would result in the authority property of the new URI object // being equal to the original value again. // Note that the use of the buggy URI constructor is authorized // for this case! // See http://java.net/jira/browse/TRUEZIP-288 . uri = new URI( uri.getScheme(), "", TWO_SEPARATORS + uri.getAuthority() + uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException ex) { throw new AssertionError(ex); } } this.target = new File(uri); }
/** * 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(); }
@Override int hashCode(TPath p) { final Integer hashCode = p.hashCode; if (null != hashCode) return hashCode; int result = 17; result = 37 * result + p.getAddress().getMountPoint().hashCode(); result = 37 * result + p.toString().toLowerCase(Locale.getDefault()).hashCode(); return p.hashCode = result; } } // WindowsTPathComparator
private @Nullable FsScheme getScheme() { if (this != innerArchive) return null; final FsController<?> controller = this.controller; if (null != controller) return controller.getModel().getMountPoint().getScheme(); return detector.getScheme(file.getPath()); }
{ "foo:/bar/", "foo:/baz/" }, }) { final FsMountPoint mountPoint = FsMountPoint.create(URI.create(params[0])); final FsMountPoint parentMountPoint = FsMountPoint.create(URI.create(params[1])); final FsModel parent = newModel(parentMountPoint, null); try { final FsMountPoint mountPoint = FsMountPoint.create(URI.create(params[0])); final FsMountPoint parentMountPoint = FsMountPoint.create(URI.create(params[1])); final FsEntryName entryName = FsEntryName.create(URI.create(params[2])); final FsEntryName parentEntryName = FsEntryName.create(URI.create(params[3])); assertThat(model.getMountPoint().getPath().resolve(entryName).getEntryName(), equalTo(parentEntryName)); assertThat(model.getMountPoint().resolve(entryName), equalTo(path)); assertThat(model.isMounted(), is(false));
@Test public void testSpaces() { for (final String[] params : new String[][] { { "foo:bar:baz:/%20!/%20/%20!/%20/%20", " ", " / ", " / ", }, { "foo:bar:baz:/%20a%20!/%20b%20!/%20c%20", " a ", " b ", " c ", }, }) { FsPath path = FsPath.create(URI.create(params[0])); for (int i = params.length; 0 < --i; ) { assertThat(path.getEntryName().getPath(), equalTo(params[i])); path = path.getMountPoint().getPath(); } } }
private static FsModel newArchiveModel() { final FsModel parent = newNonArchiveModel(); return new FsTestModel( FsMountPoint.create(URI.create( "scheme:" + parent.getMountPoint() + name + "!/")), parent); }