java.nio.file.ProviderMismatchException Java Examples

The following examples show how to use java.nio.file.ProviderMismatchException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: buck   Author: facebook   File: BuckUnixPath.java    License: Apache License 2.0 6 votes vote down vote up
private BuckUnixPath toUnixPath(Path obj) {
  if (obj == null) {
    throw new NullPointerException();
  }

  if (obj instanceof BuckUnixPath) {
    return (BuckUnixPath) obj;
  }

  FileSystem otherFs = obj.getFileSystem();
  if (!fs.equals(otherFs) && !fs.getDefaultFileSystem().equals(otherFs)) {
    throw new ProviderMismatchException(
        "Unable to convert Path to BuckUnixPath because file systems do not match");
  }
  return BuckUnixPath.of(fs, obj.toString());
}
 
Example #2
Source Project: jimfs   Author: google   File: JimfsSecureDirectoryStream.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source Project: jimfs   Author: google   File: JimfsPath.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source Project: jimfs   Author: google   File: JimfsPath.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source Project: directory-watcher   Author: gmethvin   File: WatchablePath.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #6
Source Project: dremio-oss   Author: dremio   File: HadoopFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FileBlockLocation> getFileBlockLocations(FileAttributes file, long start, long len) throws IOException {
  if (!(file instanceof FileStatusWrapper)) {
    throw new ProviderMismatchException();
  }
  final FileStatus status = ((FileStatusWrapper) file).getFileStatus();
  try (WaitRecorder recorder = OperatorStats.getWaitRecorder(operatorStats)) {
    return toFileBlockLocations(() -> underlyingFs.getFileBlockLocations(status, start, len));
  } catch (FSError e) {
    throw propagateFSError(e);
  }
}
 
Example #7
Source Project: dremio-oss   Author: dremio   File: DremioHadoopFileSystemWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FileBlockLocation> getFileBlockLocations(FileAttributes file, long start, long len) throws IOException {
  if (!(file instanceof HadoopFileStatusWrapper)) {
    throw new ProviderMismatchException();
  }
  final FileStatus status = ((HadoopFileStatusWrapper) file).getFileStatus();
  try (WaitRecorder recorder = OperatorStats.getWaitRecorder(operatorStats)) {
    return toFileBlockLocations(() -> underlyingFs.getFileBlockLocations(status, start, len));
  } catch(FSError e) {
    throw propagateFSError(e);
  }
}
 
Example #8
Source Project: dremio-oss   Author: dremio   File: DremioHadoopFileSystemWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FileBlockLocation> getFileBlockLocations(FileAttributes file, long start, long len) throws IOException {
  if (!(file instanceof HadoopFileStatusWrapper)) {
    throw new ProviderMismatchException();
  }
  final FileStatus status = ((HadoopFileStatusWrapper) file).getFileStatus();
  try (WaitRecorder recorder = OperatorStats.getWaitRecorder(operatorStats)) {
    return toFileBlockLocations(() -> underlyingFs.getFileBlockLocations(status, start, len));
  } catch(FSError e) {
    throw propagateFSError(e);
  }
}
 
Example #9
Source Project: mycore   Author: MyCoRe-Org   File: MCRPath.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #10
Source Project: mycore   Author: MyCoRe-Org   File: MCRFileSystemUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #11
Source Project: mycore   Author: MyCoRe-Org   File: MCRFileSystemUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #12
Source Project: lucene-solr   Author: apache   File: FilterPath.java    License: Apache License 2.0 5 votes vote down vote up
/** Override this to customize the unboxing of Path
 *  from various operations
 */
protected Path toDelegate(Path path) {
  if (path instanceof FilterPath) {
    FilterPath fp = (FilterPath) path;
    if (fp.fileSystem != fileSystem) {
      throw new ProviderMismatchException("mismatch, expected: " + fileSystem.provider().getClass() + ", got: " + fp.fileSystem.provider().getClass());
    }
    return fp.delegate;
  } else {
    throw new ProviderMismatchException("mismatch, expected: FilterPath, got: " + path.getClass());
  }
}
 
Example #13
Source Project: lucene-solr   Author: apache   File: FilterFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
protected Path toDelegate(Path path) {
  if (path instanceof FilterPath) {
    FilterPath fp = (FilterPath) path;
    if (fp.fileSystem != fileSystem) {
      throw new ProviderMismatchException("mismatch, expected: " + fileSystem.provider().getClass() + ", got: " + fp.fileSystem.provider().getClass());
    }
    return fp.delegate;
  } else {
    throw new ProviderMismatchException("mismatch, expected: FilterPath, got: " + path.getClass());
  }
}
 
Example #14
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static SFTPPath toSFTPPath(Path path) {
    Objects.requireNonNull(path);
    if (path instanceof SFTPPath) {
        return (SFTPPath) path;
    }
    throw new ProviderMismatchException();
}
 
Example #15
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Send a keep-alive signal for an SFTP file system.
 *
 * @param fs The SFTP file system to send a keep-alive signal for.
 * @throws ProviderMismatchException If the given file system is not an SFTP file system (not created by an {@code SFTPFileSystemProvider}).
 * @throws IOException If an I/O error occurred.
 */
public static void keepAlive(FileSystem fs) throws IOException {
    if (fs instanceof SFTPFileSystem) {
        ((SFTPFileSystem) fs).keepAlive();
        return;
    }
    throw new ProviderMismatchException();
}
 
Example #16
Source Project: vespa   Author: vespa-engine   File: NodeAgentContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
private Path requireValidPath(Path path) {
    Objects.requireNonNull(path);

    Objects.requireNonNull(fileSystem); // to allow this method to be used in constructor.
    if (!path.getFileSystem().provider().equals(fileSystem.provider())) {
        throw new ProviderMismatchException("Expected file system provider " + fileSystem.provider() +
                " but " + path + " had " + path.getFileSystem().provider());
    }

    return path;
}
 
Example #17
Source Project: ParallelGit   Author: beijunyi   File: GfsUriUtils.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source Project: encfs4j   Author: usrflo   File: EncryptedFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
static Path dismantle(Path mantle) {
	if (mantle == null)
		throw new NullPointerException();
	if (!(mantle instanceof EncryptedFileSystemPath))
		throw new ProviderMismatchException();
	return ((EncryptedFileSystemPath) mantle).subFSPath;
}
 
Example #19
Source Project: RxJavaFileUtils   Author: ReactiveX   File: WatchableFile.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source Project: ParallelGit   Author: beijunyi   File: GfsUriUtils.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #21
Source Project: encfs4j   Author: usrflo   File: EncryptedFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
static Path dismantle(Path mantle) {
	if (mantle == null)
		throw new NullPointerException();
	if (!(mantle instanceof EncryptedFileSystemPath))
		throw new ProviderMismatchException();
	return ((EncryptedFileSystemPath) mantle).subFSPath;
}
 
Example #22
Source Project: jsr203-hadoop   Author: damiencarol   File: HadoopPath.java    License: Apache License 2.0 5 votes vote down vote up
private HadoopPath checkPath(Path pathToCheck) {
  if (pathToCheck == null) {
    throw new NullPointerException();
  }
  if (!(pathToCheck instanceof HadoopPath)) {
    throw new ProviderMismatchException();
  }
  return (HadoopPath) pathToCheck;
}
 
Example #23
Source Project: jsr203-hadoop   Author: damiencarol   File: HadoopFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static final HadoopPath toHadoopPath(Path path) {
  if (path == null) {
    throw new NullPointerException();
  }
  if (!(path instanceof HadoopPath)) {
    throw new ProviderMismatchException();
  }
  return (HadoopPath) path;
}
 
Example #24
Source Project: jsch-nio   Author: lucastheisen   File: UnixSshPath.java    License: MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public WatchKey register( WatchService watcher, Kind<?>[] events, Modifier... modifiers ) throws IOException {
    if ( watcher == null ) {
        throw new NullPointerException();
    }
    if ( !(watcher instanceof UnixSshFileSystemWatchService) ) {
        throw new ProviderMismatchException();
    }
    if ( !getFileSystem().provider().readAttributes( this, BasicFileAttributes.class ).isDirectory() ) {
        throw new NotDirectoryException( this.toString() );
    }
    getFileSystem().provider().checkAccess( this, AccessMode.READ );
    return ((UnixSshFileSystemWatchService) watcher).register( this, events, modifiers );
}
 
Example #25
Source Project: jimfs   Author: google   File: JimfsFileSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
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");
}
 
Example #26
Source Project: jimfs   Author: google   File: JimfsSecureDirectoryStream.java    License: Apache License 2.0 5 votes vote down vote up
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");
}
 
Example #27
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystemProviderTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testKeepAliveWithNonFTPFileSystem() {
    @SuppressWarnings("resource")
    FileSystem defaultFileSystem = FileSystems.getDefault();
    assertThrows(ProviderMismatchException.class, () -> SFTPFileSystemProvider.keepAlive(defaultFileSystem));
}
 
Example #28
Source Project: sftp-fs   Author: robtimus   File: SFTPFileSystemProviderTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testKeepAliveWithNullFTPFileSystem() {
    assertThrows(ProviderMismatchException.class, () -> SFTPFileSystemProvider.keepAlive(null));
}
 
Example #29
Source Project: ParallelGit   Author: beijunyi   File: GfsUriUtils.java    License: Apache License 2.0 4 votes vote down vote up
static void checkScheme(URI uri) throws ProviderMismatchException {
  if(!GitFileSystemProvider.GFS.equalsIgnoreCase(uri.getScheme()))
    throw new ProviderMismatchException(uri.getScheme());
}
 
Example #30
Source Project: ParallelGit   Author: beijunyi   File: GfsUriUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public static String getSession(URI uri) throws ProviderMismatchException {
  checkScheme(uri);
  return parseQuery(uri.getQuery(), Collections.singleton(SID_KEY)).get(SID_KEY);
}