Java Examples for java.nio.file.ProviderMismatchException
The following java examples will help you to understand the usage of java.nio.file.ProviderMismatchException. These source code samples are taken from different open source projects.
Example 1
| Project: ParallelGit-master File: GfsUriUtils.java View source code |
@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 2
| Project: jimfs-master File: JimfsPath.java View source code |
@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
| Project: lucene-solr-master File: FilterPath.java View source code |
/** 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 4
| Project: nio-fs-provider-master File: WebdavFileSystemProvider.java View source code |
@SuppressWarnings("unchecked")
@Override
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException {
WebdavFileSystem wfs = (WebdavFileSystem) path.getFileSystem();
List<DavResource> resources = wfs.getSardine().list(path.toUri().toString());
if (resources.size() != 1) {
throw new IllegalArgumentException();
}
final DavResource res = resources.get(0);
if (!type.isAssignableFrom(WebdavFileAttributes.class)) {
throw new ProviderMismatchException();
}
return (A) new WebdavFileAttributes(res);
}Example 5
| Project: jdk7u-jdk-master File: WindowsAclFileAttributeView.java View source code |
@Override
public void setOwner(UserPrincipal obj) throws IOException {
if (obj == null)
throw new NullPointerException("'owner' is null");
if (!(obj instanceof WindowsUserPrincipals.User))
throw new ProviderMismatchException();
WindowsUserPrincipals.User owner = (WindowsUserPrincipals.User) obj;
// permission check
checkAccess(file, false, true);
// SetFileSecurity does not follow links so when following links we
// need the final target
String path = WindowsLinkSupport.getFinalPath(file, followLinks);
// ConvertStringSidToSid allocates memory for SID so must invoke
// LocalFree to free it when we are done
long pOwner = 0L;
try {
pOwner = ConvertStringSidToSid(owner.sidString());
} catch (WindowsException x) {
throw new IOException("Failed to get SID for " + owner.getName() + ": " + x.errorString());
}
// owner information and update the file.
try {
NativeBuffer buffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR);
try {
InitializeSecurityDescriptor(buffer.address());
SetSecurityDescriptorOwner(buffer.address(), pOwner);
// may need SeRestorePrivilege to set the owner
WindowsSecurity.Privilege priv = WindowsSecurity.enablePrivilege("SeRestorePrivilege");
try {
SetFileSecurity(path, OWNER_SECURITY_INFORMATION, buffer.address());
} finally {
priv.drop();
}
} catch (WindowsException x) {
x.rethrowAsIOException(file);
} finally {
buffer.release();
}
} finally {
LocalFree(pOwner);
}
}Example 6
| Project: openjdk-master File: WindowsAclFileAttributeView.java View source code |
@Override
public void setOwner(UserPrincipal obj) throws IOException {
if (obj == null)
throw new NullPointerException("'owner' is null");
if (!(obj instanceof WindowsUserPrincipals.User))
throw new ProviderMismatchException();
WindowsUserPrincipals.User owner = (WindowsUserPrincipals.User) obj;
// permission check
checkAccess(file, false, true);
// SetFileSecurity does not follow links so when following links we
// need the final target
String path = WindowsLinkSupport.getFinalPath(file, followLinks);
// ConvertStringSidToSid allocates memory for SID so must invoke
// LocalFree to free it when we are done
long pOwner = 0L;
try {
pOwner = ConvertStringSidToSid(owner.sidString());
} catch (WindowsException x) {
throw new IOException("Failed to get SID for " + owner.getName() + ": " + x.errorString());
}
// owner information and update the file.
try {
NativeBuffer buffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR);
try {
InitializeSecurityDescriptor(buffer.address());
SetSecurityDescriptorOwner(buffer.address(), pOwner);
// may need SeRestorePrivilege to set the owner
WindowsSecurity.Privilege priv = WindowsSecurity.enablePrivilege("SeRestorePrivilege");
try {
SetFileSecurity(path, OWNER_SECURITY_INFORMATION, buffer.address());
} finally {
priv.drop();
}
} catch (WindowsException x) {
x.rethrowAsIOException(file);
} finally {
buffer.release();
}
} finally {
LocalFree(pOwner);
}
}Example 7
| Project: Giraffe-master File: BaseFileSystemProvider.java View source code |
public final P checkPath(Path p) {
if (p == null) {
throw new NullPointerException("path cannot be null");
} else if (!pathClass.isInstance(p)) {
String type = p.getClass().getName();
throw new ProviderMismatchException("incompatible with path of type " + type);
} else {
return pathClass.cast(p);
}
}Example 8
| Project: mina-sshd-master File: SftpFileSystemProvider.java View source code |
@Override
public void copy(Path source, Path target, CopyOption... options) throws IOException {
SftpPath src = toSftpPath(source);
SftpPath dst = toSftpPath(target);
if (src.getFileSystem() != dst.getFileSystem()) {
throw new ProviderMismatchException("Mismatched file system providers for " + src + " vs. " + dst);
}
checkAccess(src);
boolean replaceExisting = false;
boolean copyAttributes = false;
boolean noFollowLinks = false;
for (CopyOption opt : options) {
replaceExisting |= opt == StandardCopyOption.REPLACE_EXISTING;
copyAttributes |= opt == StandardCopyOption.COPY_ATTRIBUTES;
noFollowLinks |= opt == LinkOption.NOFOLLOW_LINKS;
}
LinkOption[] linkOptions = IoUtils.getLinkOptions(!noFollowLinks);
// attributes of source file
BasicFileAttributes attrs = readAttributes(source, BasicFileAttributes.class, linkOptions);
if (attrs.isSymbolicLink()) {
throw new IOException("Copying of symbolic links not supported");
}
// delete target if it exists and REPLACE_EXISTING is specified
Boolean status = IoUtils.checkFileExists(target, linkOptions);
if (status == null) {
throw new AccessDeniedException("Existence cannot be determined for copy target: " + target);
}
if (log.isDebugEnabled()) {
log.debug("copy({})[{}] {} => {}", src.getFileSystem(), Arrays.asList(options), src, dst);
}
if (replaceExisting) {
deleteIfExists(target);
} else {
if (status) {
throw new FileAlreadyExistsException(target.toString());
}
}
// create directory or copy file
if (attrs.isDirectory()) {
createDirectory(target);
} else {
try (InputStream in = newInputStream(source);
OutputStream os = newOutputStream(target)) {
IoUtils.copy(in, os);
}
}
// copy basic attributes to target
if (copyAttributes) {
BasicFileAttributeView view = getFileAttributeView(target, BasicFileAttributeView.class, linkOptions);
try {
view.setTimes(attrs.lastModifiedTime(), attrs.lastAccessTime(), attrs.creationTime());
} catch (Throwable x) {
try {
delete(target);
} catch (Throwable suppressed) {
x.addSuppressed(suppressed);
}
throw x;
}
}
}Example 9
| Project: gestalt-master File: ModulePath.java View source code |
@Override
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException {
if (watcher instanceof ModuleWatchService) {
ModuleWatchService moduleWatcher = (ModuleWatchService) watcher;
return moduleWatcher.register(this, events, modifiers);
} else {
throw new ProviderMismatchException("WatchService belongs to a different file system");
}
}Example 10
| Project: openjdk8-jdk-master File: WindowsAclFileAttributeView.java View source code |
@Override
public void setOwner(UserPrincipal obj) throws IOException {
if (obj == null)
throw new NullPointerException("'owner' is null");
if (!(obj instanceof WindowsUserPrincipals.User))
throw new ProviderMismatchException();
WindowsUserPrincipals.User owner = (WindowsUserPrincipals.User) obj;
// permission check
checkAccess(file, false, true);
// SetFileSecurity does not follow links so when following links we
// need the final target
String path = WindowsLinkSupport.getFinalPath(file, followLinks);
// ConvertStringSidToSid allocates memory for SID so must invoke
// LocalFree to free it when we are done
long pOwner = 0L;
try {
pOwner = ConvertStringSidToSid(owner.sidString());
} catch (WindowsException x) {
throw new IOException("Failed to get SID for " + owner.getName() + ": " + x.errorString());
}
// owner information and update the file.
try {
NativeBuffer buffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR);
try {
InitializeSecurityDescriptor(buffer.address());
SetSecurityDescriptorOwner(buffer.address(), pOwner);
// may need SeRestorePrivilege to set the owner
WindowsSecurity.Privilege priv = WindowsSecurity.enablePrivilege("SeRestorePrivilege");
try {
SetFileSecurity(path, OWNER_SECURITY_INFORMATION, buffer.address());
} finally {
priv.drop();
}
} catch (WindowsException x) {
x.rethrowAsIOException(file);
} finally {
buffer.release();
}
} finally {
LocalFree(pOwner);
}
}Example 11
| Project: RxJavaFileUtils-master File: WatchableFile.java View source code |
@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 12
| Project: fabric8-master File: FabricProfileFileSystemProvider.java View source code |
@Override
public InputStream newInputStream(Path path, OpenOption... options) throws IOException {
if (!(path instanceof FabricProfilePath)) {
throw new ProviderMismatchException();
}
return ((FabricProfilePath) path).getFileSystem().newInputStream(path, options);
}Example 13
| Project: structr-master File: StructrFilesystemProvider.java View source code |
// ----- protected methods -----
private StructrPath checkPath(final Path obj) {
if (obj == null) {
throw new NullPointerException();
}
if (!(obj instanceof StructrPath)) {
throw new ProviderMismatchException();
}
return (StructrPath) obj;
}Example 14
| Project: memoryfilesystem-master File: AbstractPath.java View source code |
private void assertSameFileSystem(Path other) {
if (!this.isSameFileSystem(other)) {
throw new ProviderMismatchException();
}
}Example 15
| Project: jsr203-hadoop-master File: HadoopFileSystemProvider.java View source code |
// Checks that the given file is a HadoopPath
private static final HadoopPath toHadoopPath(Path path) {
if (path == null) {
throw new NullPointerException();
}
if (!(path instanceof HadoopPath)) {
throw new ProviderMismatchException();
}
return (HadoopPath) path;
}Example 16
| Project: NearInfinity-master File: DlcFileSystemProvider.java View source code |
// Checks that the given file is a UnixPath
static final DlcPath toDlcPath(Path path) {
if (path == null) {
throw new NullPointerException();
}
if (!(path instanceof DlcPath)) {
throw new ProviderMismatchException();
}
return (DlcPath) path;
}Example 17
| Project: fswrap-master File: WrappedFileSystemProvider.java View source code |
protected Path toOriginalPath(Path other) {
if (other == null) {
return null;
}
if (other instanceof WrappedPath) {
WrappedPath wrappedPath = (WrappedPath) other;
return wrappedPath.originalPath;
} else {
throw new ProviderMismatchException("Wrong Path type " + other.getClass());
}
}Example 18
| Project: jdk7-dxfs-master File: DxFileSystemProvider.java View source code |
// Checks that the given file is a UnixPath
static final DxPath toDxPath(Path path) {
if (path == null) {
throw new NullPointerException();
}
if (!(path instanceof DxPath)) {
throw new ProviderMismatchException();
}
return (DxPath) path;
}