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 File: JimfsPath.java    From jimfs with 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 #2
Source File: JimfsPath.java    From jimfs with 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 #3
Source File: JimfsSecureDirectoryStream.java    From jimfs with 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 #4
Source File: BuckUnixPath.java    From buck with 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 #5
Source File: HadoopFileSystem.java    From dremio-oss with 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 #6
Source File: JimfsSecureDirectoryStream.java    From jimfs with 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 #7
Source File: JimfsFileSystemProvider.java    From jimfs with 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 #8
Source File: UnixSshPath.java    From jsch-nio with 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 #9
Source File: HadoopFileSystemProvider.java    From jsr203-hadoop with 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 #10
Source File: HadoopPath.java    From jsr203-hadoop with 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 #11
Source File: EncryptedFileSystem.java    From encfs4j with 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 #12
Source File: GfsUriUtils.java    From ParallelGit with 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 #13
Source File: WatchableFile.java    From RxJavaFileUtils with 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 #14
Source File: EncryptedFileSystem.java    From encfs4j with 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 #15
Source File: GfsUriUtils.java    From ParallelGit with 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 #16
Source File: WatchablePath.java    From directory-watcher with 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 #17
Source File: NodeAgentContextImpl.java    From vespa with 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 #18
Source File: DremioHadoopFileSystemWrapper.java    From dremio-oss with 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 #19
Source File: DremioHadoopFileSystemWrapper.java    From dremio-oss with 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 #20
Source File: MCRPath.java    From mycore with 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 #21
Source File: MCRFileSystemUtils.java    From mycore with 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 #22
Source File: MCRFileSystemUtils.java    From mycore with 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 #23
Source File: FilterPath.java    From lucene-solr with 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 #24
Source File: SFTPFileSystemProvider.java    From sftp-fs with 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 #25
Source File: SFTPFileSystemProvider.java    From sftp-fs with 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 #26
Source File: FilterFileSystemProvider.java    From lucene-solr with 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 #27
Source File: JimfsPath.java    From jimfs with Apache License 2.0 4 votes vote down vote up
@Override
public JimfsPath relativize(Path other) {
  JimfsPath otherPath = checkPath(other);
  if (otherPath == null) {
    throw new ProviderMismatchException(other.toString());
  }

  checkArgument(
      Objects.equals(root, otherPath.root), "Paths have different roots: %s, %s", this, other);

  if (equals(other)) {
    return pathService.emptyPath();
  }

  if (isEmptyPath()) {
    return otherPath;
  }

  ImmutableList<Name> otherNames = otherPath.names;
  int sharedSubsequenceLength = 0;
  for (int i = 0; i < Math.min(getNameCount(), otherNames.size()); i++) {
    if (names.get(i).equals(otherNames.get(i))) {
      sharedSubsequenceLength++;
    } else {
      break;
    }
  }

  int extraNamesInThis = Math.max(0, getNameCount() - sharedSubsequenceLength);

  ImmutableList<Name> extraNamesInOther =
      (otherNames.size() <= sharedSubsequenceLength)
          ? ImmutableList.<Name>of()
          : otherNames.subList(sharedSubsequenceLength, otherNames.size());

  List<Name> parts = new ArrayList<>(extraNamesInThis + extraNamesInOther.size());

  // add .. for each extra name in this path
  parts.addAll(Collections.nCopies(extraNamesInThis, Name.PARENT));
  // add each extra name in the other path
  parts.addAll(extraNamesInOther);

  return pathService.createRelativePath(parts);
}
 
Example #28
Source File: GfsUriUtils.java    From ParallelGit with 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 #29
Source File: UnixSshPath.java    From jsch-nio with MIT License 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public UnixSshPath relativize( Path other ) {
    if ( other == null ) {
        throw new NullPointerException();
    }
    if ( !(other instanceof UnixSshPath) ) {
        throw new ProviderMismatchException();
    }

    UnixSshPath unixOther = (UnixSshPath) other;
    if ( isAbsolute() && !unixOther.isAbsolute() ) {
        throw new IllegalArgumentException( "this and other must have same isAbsolute" );
    }

    if ( getNameCount() == 0 ) {
        return unixOther;
    }

    Path relative = null;
    Path remainingOther = null;
    Iterator<Path> otherIterator = unixOther.iterator();
    for ( Path part : this ) {
        if ( relative != null ) {
            relative = relative.resolve( ".." );
            continue;
        }

        if ( otherIterator.hasNext() ) {
            Path otherPart = otherIterator.next();
            if ( !part.equals( otherPart ) ) {
                remainingOther = otherPart;
                while ( otherIterator.hasNext() ) {
                    remainingOther = remainingOther.resolve(
                            otherIterator.next() );
                }
                relative = new UnixSshPath( getFileSystem(), ".." );
            }
        }
        else {
            relative = new UnixSshPath( getFileSystem(), ".." );
        }
    }

    if ( relative == null ) {
        while ( otherIterator.hasNext() ) {
            if ( remainingOther == null ) {
                remainingOther = new UnixSshPath( getFileSystem(), "" );
            }
            else {
                remainingOther = remainingOther.resolve(
                        otherIterator.next() );
            }
        }
        return remainingOther == null
                ? new UnixSshPath( getFileSystem(), "" )
                : (UnixSshPath) remainingOther;
    }
    return remainingOther == null
            ? (UnixSshPath) relative
            : (UnixSshPath) relative.resolve( remainingOther );
}
 
Example #30
Source File: GfsUriUtilsTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
@Test(expected = ProviderMismatchException.class)
public void checkSchemeTest() {
  GfsUriUtils.checkScheme(URI.create("/somepath"));
}