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 = Paths.get(uri); }
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); }
@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(); }
/** * 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); } } }
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())); 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()));