private boolean invariants() { assert null != getUri(); assert null == getUri().getRawFragment(); assert (null != getMountPoint()) == getUri().isAbsolute(); assert null != getNodeName(); if (getUri().isOpaque()) { assert getUri().getRawSchemeSpecificPart().contains(FsMountPoint.SEPARATOR); /*try { assert getUri().equals(new URI(getMountPoint().getUri().getScheme(), getMountPoint().getUri().getSchemeSpecificPart() + toDecodedUri(getNodeName()), null)); } catch (URISyntaxException ex) { throw new AssertionError(ex); }*/ } else if (getUri().isAbsolute()) { assert getUri().normalize() == getUri(); assert getUri().equals(getMountPoint().getUri().resolve(getNodeName().getUri())); } else { assert getUri().normalize() == getUri(); assert getNodeName().getUri() == getUri(); } return true; }
/** * Resolves the given node name against this mount point. * * @param name a node name relative to this mount point. * @return A new path with an absolute URI. */ public FsNodePath resolve(FsNodeName name) { return new FsNodePath(this, name); }
private TFileSystemProvider(final String scheme, final URI root) { assert null != scheme; this.scheme = scheme; this.root = FsNodePath.create(root); }
/** * Returns the nullable parent of the given file system node path. * * @param path a file system node path. * @return The parent file system node path or null if {@code path} does * not name a parent. * @throws URISyntaxException */ static @Nullable FsNodePath parent(FsNodePath path) throws URISyntaxException { FsMountPoint mp = path.getMountPoint(); FsNodeName en = path.getNodeName(); if (en.isRoot()) { if (null == mp) return null; path = mp.getPath(); if (null != path) return parent(path); URI mpu = mp.getUri(); URI pu = mpu.resolve(DOT_DOT_URI); if (mpu.getRawPath().length() <= pu.getRawPath().length()) return null; return new FsNodePath(pu); } else { URI pu = en.getUri().resolve(DOT_URI); en = new FsNodeName(pu, CANONICALIZE); return new FsNodePath(mp, en); } } }
throw new QuotedUriSyntaxException(uri, "Doesn't end with mount point separator \"" + SEPARATOR + '"'); path = new FsNodePath(new URI(ssp.substring(0, i)), modifier); final URI pu = path.getUri(); if (!pu.isAbsolute()) throw new QuotedUriSyntaxException(uri, "Path not absolute"); if (0 == path.getNodeName().getPath().length()) throw new QuotedUriSyntaxException(uri, "Empty URI path of node name of node path"); if (NULL != modifier) {
private boolean invariants() { assert null != getUri(); assert getUri().isAbsolute(); assert null == getUri().getRawQuery(); assert null == getUri().getRawFragment(); if (getUri().isOpaque()) { assert getUri().getRawSchemeSpecificPart().endsWith(SEPARATOR); final FsNodePath path = getPath(); assert null != path; assert path.getUri().isAbsolute(); assert null == path.getUri().getRawFragment(); assert 0 != path.getNodeName().getUri().getRawPath().length(); } else { assert getUri().normalize() == getUri(); assert getUri().getRawPath().endsWith(FsNodeName.SEPARATOR); assert null == getPath(); } return true; }
/** * 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 FsNodePath nodePath = getNodePath(); final boolean root = nodePath.getNodeName().isRoot(); final FsMountPoint parent = nodePath.getMountPoint().getParent(); return root && null != parent; }
@Override public void checkAccess( final BitField<FsAccessOption> options, final FsNodeName name, final BitField<Access> types) throws IOException { try { controller.checkAccess(options, name, types); } catch (final ControlFlowException ex) { if (!name.isRoot() || null == findKeyException(ex)) throw ex; getParent().checkAccess( options, getModel() .getMountPoint() .getPath() .resolve(name) .getNodeName(), types); } }
private FsNodePath resolve(final String path) throws URISyntaxException { splitter.split(path); final String pp = splitter.getParentPath(); final FsNodeName nn; final FsNodePath np; if (null != pp) { nn = new FsNodeName( builder.path(splitter.getMemberName()).getUri(), NULL); np = resolve(pp); } else { nn = new FsNodeName( builder.path(path).query(memberQuery).getUri(), CANONICALIZE); np = root; } URI npu; FsNodePath rnp; if (nn.isRoot() || (npu = np.getUri()).isOpaque() || !npu.isAbsolute()) { rnp = np.resolve(nn); } else { final String npup = npu.getPath(); if (!npup.endsWith(SEPARATOR)) npu = new UriBuilder(npu).path(npup + SEPARATOR_CHAR).getUri(); rnp = new FsNodePath(new FsMountPoint(npu), nn); } final FsScheme s = detector.scheme(nn.toString()); if (null != s) rnp = new FsNodePath(new FsMountPoint(s, rnp), ROOT); return rnp; }
return new FsMountPoint( scheme, new FsNodePath( new FsMountPoint(enclArchive.toURI(), CANONICALIZE), nodeName)).getUri(); } else { return new FsMountPoint(scheme, new FsNodePath(file)).getUri(); return new FsNodePath( new FsMountPoint(enclArchive.toURI(), CANONICALIZE), nodeName).getUri(); } else { return file.toURI();
@Override public FsNodeName getNodeName() { return getNodePath().getNodeName(); }
/** * Returns the parent component, that is the mount point of the parent file * system, * or {@code null} iff this mount point's {@link #getUri URI} doesn't name * a parent mount point, that is if and only if it's hierarchical. * * @return The nullable parent component. */ public @Nullable FsMountPoint getParent() { assert null == path || null != path.getMountPoint(); return null == path ? null : path.getMountPoint(); }
try { uri = fix(check(uri).normalize()); if (uri.isAbsolute()) return new FsNodePath(uri, CANONICALIZE); String path = uri.getPath(); for ( int max; final URI baseUri = base.toHierarchicalUri().resolve(SEPARATOR_URI); final String authority = uri.getAuthority(); final String rootPath = null != authority || path.startsWith(SEPARATOR) ? path.substring(0, ppl) : baseUri.getPath() + path.substring(0, ppl); root = new FsNodePath( new UriBuilder() .scheme(baseUri.getScheme())
HttpNode( final HttpController controller, final FsNodeName name) { assert null != controller; this.controller = controller; this.name = name.toString(); this.uri = controller.resolve(name).getUri(); }
/** * Returns a URI which is recursively transformed from the URI of this * mount point so that it's absolute and hierarchical. * If this mount point is already in absolute and hierarchical form, its * URI gets returned. * <p> * For example, the mount point URIs {@code zip:file:/archive!/} and * {@code tar:file:/archive!/} would both produce the hierarchical URI * {@code file:/archive}. * * @return A URI which is recursively transformed from the URI of this * mount point so that it's absolute and hierarchical. */ public URI toHierarchicalUri() { final URI hierarchical = this.hierarchical; return null != hierarchical ? hierarchical : (this.hierarchical = uri.isOpaque() ? path.toHierarchicalUri() : uri); }
/** * Returns an input socket for the given file. * * @param file the file to read. * @param options the options for accessing the file. * @return An input socket for the given file. */ static InputSocket<?> input( final BitField<FsAccessOption> options, final File file) { if (file instanceof TFile) { final TFile tfile= (TFile) file; final TFile archive = tfile.getInnerArchive(); if (null != archive) return archive .getController() .input(options, tfile.getNodeName()); } final FsNodePath path = new FsNodePath(file); return TConfig .current() .getManager() .controller(detector(file), path.getMountPoint()) .input(options, path.getNodeName()); }
/** * Constructs a new opaque mount point by composing its URI from the given * scheme and path. * * @param scheme the non-{@code null} {@link #getScheme() scheme}. * @param path the non-{@code null} {@link #getPath() path}. * @throws URISyntaxException if the composed mount point URI would not * conform to the syntax constraints for mount points. */ public FsMountPoint(final FsScheme scheme, final FsNodePath path) throws URISyntaxException { final URI pu = path.getUri(); if (!pu.isAbsolute()) throw new QuotedUriSyntaxException(pu, "Path not absolute"); final String penup = path.getNodeName().getUri().getPath(); if (0 == penup.length()) throw new QuotedUriSyntaxException(pu, "Empty node name"); this.uri = new UriBuilder(true) .scheme(scheme.toString()) .path(pu.getScheme() + ':' + pu.getRawSchemeSpecificPart() + SEPARATOR) .toUri(); this.scheme = scheme; this.path = path; assert invariants(); }
/** * 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 FsNodePath nodePath = getNodePath(); final boolean root = nodePath.getNodeName().isRoot(); final FsMountPoint parent = nodePath.getMountPoint().getParent(); return !root ? null != parent : null != parent && null != parent.getParent(); }
.getMountPoint() .getPath() .resolve(name) .getNodeName());
if (null != pmp) { mp = pmp; en = mmp.getPath().getNodeName(); } else { mp = mmp;