/** * 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); }
/** * Constructs a new mock controller. * * @param model The file system model. * @param parent The parent file system controller. * @param config The mocking configuration. */ public MockController( final FsModel model, final @CheckForNull FsController<?> parent, final @CheckForNull TestConfig config) { assert null == model.getParent() ? null == parent : model.getParent().equals(parent.getModel()); this.model = model; this.parent = parent; this.config = null != config ? config : TestConfig.get(); }
@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 MockController newController(final FsModel model) { final FsModel pm = model.getParent(); final FsController<?> pc = null == pm ? null : newController(pm); return new TestController(model, pc); }
FsModel model = newModel(mountPoint, parent); assertThat(model.getMountPoint(), sameInstance(mountPoint)); assertThat(model.getParent(), sameInstance(parent)); assertThat(model.getMountPoint().getPath().resolve(entryName).getEntryName(), equalTo(parentEntryName)); assertThat(model.getMountPoint().resolve(entryName), equalTo(path)); assertThat(model.isMounted(), is(false));
@Override public void setUp() throws IOException { super.setUp(); // Order is important here! final TestConfig config = getTestConfig(); config.setDataSize(getMaxArchiveLength()); config.setIOPoolProvider(null); // reset parent = newController(model.getParent()); }
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()); }
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); }
FsMountPoint getMountPoint() { return getController().getModel().getMountPoint(); }
/** * Returns a mount point for the given (virtual) directory {@code tree}. * If {@code tree} refers to a (prospective) archive file, then its mount * point gets returned. * Otherwise, the path of the file object is used to create a new mount * point. * Note that making up an artificial mount point like this will only work * with the {@link FsFilteringManager}! * * @param tree a file or directory in the (virtual) file system space. * @return A mount point for the given (virtual) directory tree. */ static FsMountPoint mountPoint(final TFile tree) { if (tree.isArchive()) { return tree.getController().getModel().getMountPoint(); // fast path //return tree.toFsPath().getMountPoint(); // slow path } try { return new FsMountPoint(new URI(tree.getFile().toURI() + "/"), CANONICALIZE); } catch (final URISyntaxException ex) { throw new AssertionError(ex); } }
@Override public InputShop<MockArchiveDriverEntry> newInputShop( final FsModel model, final InputSocket<?> input) throws IOException { final FsMountPoint mp = model.getMountPoint(); input.getLocalTarget(); // don't care for the result final MockArchiveDriverEntryContainer c = containers.get(mp); if (null == c) throw new FileNotFoundException(mp.toString()); return c.newInputShop(); }
private static FsModel newArchiveModel() { final FsModel parent = newNonArchiveModel(); return new FsTestModel( FsMountPoint.create(URI.create( "scheme:" + parent.getMountPoint() + name + "!/")), parent); }
@Override public OutputShop<MockArchiveDriverEntry> newOutputShop( FsModel model, OutputSocket<?> output, InputShop<MockArchiveDriverEntry> source) throws IOException { final FsMountPoint mp = model.getMountPoint(); output.getLocalTarget(); // don't care for the result final MockArchiveDriverEntryContainer n = MockArchiveDriverEntryContainer.create(config); MockArchiveDriverEntryContainer o = containers.get(mp); if (null == o) o = containers.putIfAbsent(mp, n); return (null != o ? o : n).newOutputShop(); }
: new FsPath( enclArchive .getController() .getModel() .getMountPoint(), enclEntryName)); } catch (URISyntaxException ex) {
assertThat(filter.getSize(), is(params[2].length)); for (final FsController<?> controller : filter) assertTrue(set.contains(controller.getModel().getMountPoint()));
final FsMountPoint mountPoint = FsMountPoint.create(URI.create(param)); assertThat(i.next().getModel().getMountPoint(), equalTo(mountPoint));
@Override public FsEntry getEntry(final FsEntryName name) throws IOException { try { return delegate.getEntry(name); } catch (final ControlFlowException ex) { if (!name.isRoot() || null == findKeyException(ex)) throw ex; Entry entry = getParent().getEntry( getModel() .getMountPoint() .getPath() .resolve(name) .getEntryName()); // We're not holding any locks, so it's possible that someone else // has concurrently modified the parent file system. if (null == entry) return null; // The entry is inaccessible for some reason. // This may be because the cipher key is not available. // Now mask the entry as a special file. while (entry instanceof FsCovariantEntry<?>) entry = ((FsCovariantEntry<?>) entry).getEntry(); final FsCovariantEntry<FsArchiveEntry> special = new FsCovariantEntry<FsArchiveEntry>(ROOT_PATH); special.put(SPECIAL, driver.newEntry(ROOT_PATH, SPECIAL, entry)); return special; } }