@Override public void move(Path srcPath, SecureDirectoryStream<Path> targetDir, Path targetPath) throws IOException { checkOpen(); JimfsPath checkedSrcPath = checkPath(srcPath); JimfsPath checkedTargetPath = checkPath(targetPath); if (!(targetDir instanceof JimfsSecureDirectoryStream)) { throw new ProviderMismatchException( "targetDir isn't a secure directory stream associated with this file system"); } JimfsSecureDirectoryStream checkedTargetDir = (JimfsSecureDirectoryStream) targetDir; view.copy( checkedSrcPath, checkedTargetDir.view, checkedTargetPath, ImmutableSet.<CopyOption>of(), true); }
@Override public JimfsPath resolve(Path other) { JimfsPath otherPath = checkPath(other); if (otherPath == null) { throw new ProviderMismatchException(other.toString()); } if (isEmptyPath() || otherPath.isAbsolute()) { return otherPath; } if (otherPath.isEmptyPath()) { return this; } return pathService.createPath( root, ImmutableList.<Name>builder() .addAll(names) .addAll(otherPath.names) .build()); }
@Override public JimfsPath resolveSibling(Path other) { JimfsPath otherPath = checkPath(other); if (otherPath == null) { throw new ProviderMismatchException(other.toString()); } if (otherPath.isAbsolute()) { return otherPath; } JimfsPath parent = getParent(); if (parent == null) { return otherPath; } return parent.resolve(other); }
@Override protected LocalPath toCachePath( Path path ) { Objects.requireNonNull( path ); if( !(path instanceof LocalPath) ) { throw new ProviderMismatchException(); } return (LocalPath) path.toAbsolutePath(); }
private P checkPath( Path path ) { if( path == null ) { throw new NullPointerException(); } if( !(path instanceof AbstractPath) ) { throw new ProviderMismatchException(); } return (P) path; }
@Override protected CachePath toCachePath( Path path ) { Objects.requireNonNull( path ); if( !(path instanceof CachePath) ) { throw new ProviderMismatchException(); } return (CachePath) path.toAbsolutePath(); }
protected MemoryPath toPath( Path path ) { Objects.requireNonNull( path ); if( !(path instanceof MemoryPath) ) { throw new ProviderMismatchException(); } return (MemoryPath) path.toAbsolutePath(); }
public static MCRPath toMCRPath(final Path other) { if (other == null) { throw new NullPointerException(); } if (!(other instanceof MCRPath)) { throw new ProviderMismatchException("other is not an instance of MCRPath: " + other.getClass()); } return (MCRPath) other; }
static MCRPath checkPathAbsolute(Path path) { MCRPath mcrPath = MCRPath.toMCRPath(path); if (!(Objects.requireNonNull(mcrPath.getFileSystem(), "'path' requires a associated filesystem.") .provider() instanceof MCRFileSystemProvider)) { throw new ProviderMismatchException("Path does not match to this provider: " + path); } if (!mcrPath.isAbsolute()) { throw new InvalidPathException(mcrPath.toString(), "'path' must be absolute."); } return mcrPath; }
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) { throw new NullPointerException(); } if (!(watcher instanceof AbstractWatchService)) { throw new ProviderMismatchException(); } return ((AbstractWatchService) watcher).register(this, Arrays.asList(events)); }
@Nonnull public static String getFile(URI uri) throws ProviderMismatchException { checkScheme(uri); String fragment = uri.getFragment(); if(fragment == null) fragment = ""; if(!fragment.startsWith("/")) fragment = "/" + fragment; if(fragment.length() > 1 && fragment.endsWith("/")) fragment = fragment.substring(0, fragment.length() - 1); return fragment; }
static Path dismantle(Path mantle) { if (mantle == null) throw new NullPointerException(); if (!(mantle instanceof EncryptedFileSystemPath)) throw new ProviderMismatchException(); return ((EncryptedFileSystemPath) mantle).subFSPath; }
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof AbstractWatchService)) throw new ProviderMismatchException(); return ((AbstractWatchService) watcher).register(this, events, modifiers); }
private EphemeralFsPath toEfsPath(Path other) { if(other == null) { throw new NullPointerException(); } try { return (EphemeralFsPath) other; } catch(ClassCastException e) { throw new ProviderMismatchException(); } }
static final TarPath toTarPath(Path path) { if (path == null) { throw new NullPointerException(); } if (!(path instanceof TarPath)) { throw new ProviderMismatchException(); } return (TarPath) path; }
private static TarPath checkPath(Path path) { if (path == null) { throw new NullPointerException(); } if (!(path instanceof TarPath)) { throw new ProviderMismatchException(); } return (TarPath) path; }
private HadoopPath checkPath(Path pathToCheck) { if (pathToCheck == null) { throw new NullPointerException(); } if (!(pathToCheck instanceof HadoopPath)) { throw new ProviderMismatchException(); } return (HadoopPath) pathToCheck; }
private static final HadoopPath toHadoopPath(Path path) { if (path == null) { throw new NullPointerException(); } if (!(path instanceof HadoopPath)) { throw new ProviderMismatchException(); } return (HadoopPath) path; }
static final DxPath toDxPath(Path path) { if (path == null) { throw new NullPointerException(); } if (!(path instanceof DxPath)) { throw new ProviderMismatchException(); } return (DxPath)path; }
private static JimfsPath checkPath(Path path) { if (path instanceof JimfsPath) { return (JimfsPath) path; } throw new ProviderMismatchException( "path " + path + " is not associated with a Jimfs file system"); }
static void checkScheme(URI uri) throws ProviderMismatchException { if(!GitFileSystemProvider.GFS.equalsIgnoreCase(uri.getScheme())) throw new ProviderMismatchException(uri.getScheme()); }
@Nullable public static String getSession(URI uri) throws ProviderMismatchException { checkScheme(uri); return parseQuery(uri.getQuery(), Collections.singleton(SID_KEY)).get(SID_KEY); }
@Test(expected = ProviderMismatchException.class) public void checkSchemeTest() { GfsUriUtils.checkScheme(URI.create("/somepath")); }
@Test @Category( { HardLink.class, Writable.class } ) public void testHardLinkToOtherProviderThrows() throws IOException { assertThatThrownBy( () -> Files.createLink( link(), otherProviderFileA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { SecondFileSystem.class } ) public void testRelativize() { assertThatThrownBy( () -> absAB().relativize( otherFSAbsA() )).isInstanceOf( ProviderMismatchException.class ); }
@Test public void testNewByteChannelOtherProvider() throws IOException { assertThatThrownBy( () -> FS.provider().newByteChannel( otherProviderAbsA(), Collections.<OpenOption> emptySet() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test public void testGetBasicFileAttributeViewProvider() throws IOException { assertThatThrownBy( () -> FS.provider().getFileAttributeView( otherProviderAbsA(), BasicFileAttributeView.class ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { Writable.class } ) public void testCreateDirectoryOtherProvider() throws IOException { assertThatThrownBy( () -> FS.provider().createDirectory( otherProviderAbsA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( FileChannelT.class ) public void testNewFileChannelOtherProvider() throws IOException { assertThatThrownBy( () -> FS.provider().newFileChannel( otherProviderAbsA(), Collections.<OpenOption> emptySet() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test public void testCheckAccessOtherProvider() throws IOException { assertThatThrownBy( () -> FS.provider().checkAccess( otherProviderAbsA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { Copy.class, Writable.class } ) public void testCopyOtherProviderFrom() throws IOException { assertThatThrownBy( () -> FS.provider().copy( otherProviderAbsA(), absTA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { Copy.class, Writable.class } ) public void testCopyOtherProviderTo() throws IOException { assertThatThrownBy( () -> FS.provider().copy( fileTA(), otherProviderAbsA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { Move.class, Writable.class } ) public void testMoveOtherProviderFrom() throws IOException { assertThatThrownBy( () -> FS.provider().move( otherProviderAbsA(), absTA() ) ).isInstanceOf( ProviderMismatchException.class ); }
@Test @Category( { Copy.class, Writable.class } ) public void testMoveOtherProviderTo() throws IOException { assertThatThrownBy( () -> FS.provider().move( fileTAB(), otherProviderAbsA() ) ).isInstanceOf( ProviderMismatchException.class ); }