@SuppressWarnings("unchecked") @Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(path); if (type == null) { throw new NullPointerException(); } //must support BasicFileAttributeView if (type == BasicFileAttributeView.class) { return (V) new BasicFileAttributeViewImpl(mcrPath); } if (type == MCRMD5AttributeView.class) { return (V) new MD5FileAttributeViewImpl(mcrPath); } return null; }
@SuppressWarnings("unchecked") @Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { if (path != null) { MCRPath file = checkRelativePath(path); if (file.getNameCount() != 1) { throw new InvalidPathException(path.toString(), "'path' must have one name component."); } } checkClosed(); if (type == null) { throw new NullPointerException(); } //must support BasicFileAttributeView if (type == BasicFileAttributeView.class) { return (V) new BasicFileAttributeViewImpl(this, path); } if (type == MCRMD5AttributeView.class) { return (V) new MD5FileAttributeViewImpl(this, path); } return null; }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { BundleFileSystem fs = (BundleFileSystem) path.getFileSystem(); if (path.toAbsolutePath().equals(fs.getRootDirectory())) { // Bug in ZipFS, it will fall over as there is no entry for / // // Instead we'll just give a view of the source (e.g. the zipfile // itself). // Modifying its times is a bit futile since they are likely to be // overriden when closing, but this avoids a NullPointerException // in Files.setTimes(). return Files.getFileAttributeView(fs.getSource(), type, options); } return origProvider(path).getFileAttributeView(fs.unwrap(path), type, options); }
private Set<String> getSupportedFileAttributes(FileStore fs) { Set<String> attrs = new HashSet<String>(); if (fs.supportsFileAttributeView(AclFileAttributeView.class)) { attrs.add("acl"); } if (fs.supportsFileAttributeView(BasicFileAttributeView.class)) { attrs.add("basic"); } if (fs.supportsFileAttributeView(FileOwnerAttributeView.class)) { attrs.add("owner"); } if (fs.supportsFileAttributeView(UserDefinedFileAttributeView.class)) { attrs.add("user"); } if (fs.supportsFileAttributeView(DosFileAttributeView.class)) { attrs.add("dos"); } if (fs.supportsFileAttributeView(PosixFileAttributeView.class)) { attrs.add("posix"); } if (fs.supportsFileAttributeView(FileAttributeView.class)) { attrs.add("file"); } return attrs; }
public boolean supportsFileAttributeView( Class<? extends FileAttributeView> type) { String name = "notFound"; if(type == BasicFileAttributeView.class) { name = "basic"; } else if(type == DosFileAttributeView.class) { name = "dos"; } else if(type == PosixFileAttributeView.class) { name = "posix"; } else if(type == FileOwnerAttributeView.class) { name = "owner"; } return attributeSets.containsKey(name); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { final EphemeralFsPath efsPath = cast(path); synchronized(efsPath.fs.fsLock) { return efsPath.fs.getFileAttributeView( new EphemeralFsPathProvider() { @Override public EphemeralFsPath get() { return translate(efsPath); } }, type, closeChecker, options); } }
public <V extends FileAttributeView> Optional<V> getFileAttributeView( EightyPath path, final Class<V> type, LinkOption... options ) { if( !isViewSupported( type ) ) { return Optional.empty(); } if( !existsEx( path, options ) ) { return Optional.of( getFileAttributeViewDummy( path, type ) ); } EightyPath real = toRealPathEx( path, options ); EightyFileSystem eightyFileSystem = path._getFileSystem(); EightyFS efs = eightyFileSystem.get80(); V fav = getSymLinkSensitiveFileAttributeView( type, real, efs ); handleReadOnlyFileSystems( eightyFileSystem, fav ); return Optional.of( fav ); }
@Override public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options) { checkOpen(); final JimfsPath checkedPath = checkPath(path); final ImmutableSet<LinkOption> optionsSet = Options.getLinkOptions(options); return view.getFileAttributeView( new FileLookup() { @Override public File lookup() throws IOException { checkOpen(); // per the spec, must check that the stream is open for each view operation return view .lookUpWithLock(checkedPath, optionsSet) .requireExists(checkedPath) .file(); } }, type); }
@Test public void testView() throws IOException { AclFileAttributeView view = provider.view( fileLookup(), ImmutableMap.<String, FileAttributeView>of( "owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS))); assertNotNull(view); assertThat(view.name()).isEqualTo("acl"); assertThat(view.getAcl()).isEqualTo(defaultAcl); view.setAcl(ImmutableList.<AclEntry>of()); view.setOwner(FOO); assertThat(view.getAcl()).isEqualTo(ImmutableList.<AclEntry>of()); assertThat(view.getOwner()).isEqualTo(FOO); assertThat(file.getAttribute("acl", "acl")).isEqualTo(ImmutableList.<AclEntry>of()); }
@Override @Nullable public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options) { return promote(path).getFileAttributeView(type, options); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path file, Class<V> type, LinkOption... options) { return Files.getFileAttributeView(unwrap(file), type, options); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path file, Class<V> type, LinkOption... options) { Path delegate = theFileSystem.unwrap(file); return defaultProvider.getFileAttributeView(delegate, type, options); }
/** * Can return a {@link CloudFileAttributesView} * @param type {@link CloudFileAttributesView} or {@link BasicFileAttributeView} */ @Override public <V extends FileAttributeView> V getFileAttributeView(BlobStoreContext blobStoreContext, Class<V> type, CloudPath cloudPath) { if (CloudFileAttributesView.class.equals(type) || BasicFileAttributeView.class.equals(type)) { return type.cast(new CloudFileAttributesView(blobStoreContext, cloudPath)); } return null; }
@Override @SuppressWarnings( "unchecked" ) public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options ) { if( type.isAssignableFrom( BasicFileAttributeView.class ) ) { P p = toCachePath( path ); return (V) p.getFileSystem().getFileSystemIO().getAttributeView( p.getResolvedPath() ); } throw new UnsupportedOperationException(); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { throw new UnsupportedOperationException(); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { // TODO Auto-generated method stub throw new UnsupportedOperationException(); }
@Override public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { return type.isAssignableFrom(GfsFileAttributeView.Basic.class) || type.isAssignableFrom(GfsFileAttributeView.Posix.class) || type.isAssignableFrom(GfsFileAttributeView.Git.class); }
@Test public void getFileAttributeViewFromFile_shouldBeNotNull() throws IOException { initRepository(); writeToCache("/file.txt"); commitToMaster(); initGitFileSystem(); assertNotNull(Files.getFileAttributeView(gfs.getPath("/file.txt"), FileAttributeView.class)); }
/** {@inheritDoc} */ @Override public < V extends FileAttributeView > V getFileAttributeView(Path path, Class< V > type, LinkOption... options) { path = ((TestPath) path).unwrap(); try { checkIfRemoved(path); } catch (NoSuchFileException e) { return null; } return provider.getFileAttributeView(path, type, options); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Class<V> type) { synchronized(myPath.fs.fsLock) { return myPath.fs.getFileAttributeView( new EphemeralFsPathProvider() { @Override public EphemeralFsPath get() { return myDirectory.getPathToRoot(); } }, type, closeChecker); } }
public <V extends FileAttributeView> V getFileAttributeView( EphemeralFsPathProvider pathProvider, Class<V> type, CloseChecker closeChecker, LinkOption... options) { return getFileAttributesViewBuilder( pathProvider, closeChecker, options).build(type); }
public <V extends FileAttributeView> V build(Class<V> type) { if (type == BasicFileAttributeView.class) { return (V) new EphemeralFsBasicFileAttributesView(); } else if (type == PosixFileAttributeView.class) { return (V) new EphemeralFsPosixFileAttributesView(); } else if (type == DosFileAttributeView.class) { return (V) new EphemeralFsDosFileAttributesView(); } else if (type == FileOwnerAttributeView.class) { return (V) new EphemeralFsFileOwnerAttributeView(); } else { throw new UnsupportedOperationException("type:" + type + " is not supported"); } }
@Override public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) { EphemeralFsPath efsPath = toEfsPath(path); return efsPath.fs.getFileAttributeView( new EphemeralFsPathProvider.ConstefsPathProvider(efsPath), type, CloseChecker.ALWAYS_OPEN, options); }
@SuppressWarnings("unchecked") static <V extends FileAttributeView> V get(TarPath path, Class<V> type) { if (type == null) { throw new NullPointerException(); } if (type == BasicFileAttributeView.class) { return (V) new TarFileAttributeView(path, false); } if (type == TarFileAttributeView.class) { return (V) new TarFileAttributeView(path, true); } return null; }
@Override public @Nullable <V extends FileAttributeView> V getFileAttributeView( @Nullable Path pathArg, @Nullable final Class<V> type, @Nullable LinkOption... options ) { EightyPath path = checkProvider( pathArg ); AttributeProvider attributeProvider = path._getFileSystem().getAttributeProvider(); return attributeProvider.getFileAttributeView( path, _n1( type ), _nargs( options ) ).orElse( null ); }
@Override public Object read( FileAttributeView view, String attiName ) { checkViewType( view ); return reads.getOrThrow( attiName, new IllegalArgumentException( "attribute " + attiName + " not in view " + getViewName() ) ). apply( viewType.cast( view )); }
@Override public void set( FileAttributeView view, String name, Object value ) { checkViewType( view ); writes.getOrThrow( name, new IllegalArgumentException( "no such attribute " + name ) ). accept( viewType.cast( view ), value ); }
private <V extends FileAttributeView> void handleReadOnlyFileSystems( EightyFileSystem eightyFileSystem, V fav ) { if( eightyFileSystem.isReadOnly() ) { if( !( fav instanceof ReadonlySettable ) ) { throw new UnsupportedOperationException( "the attribute view need to implement ReadonlySettable in order to make Readonly Filesystems work" ); } ( (ReadonlySettable) ( fav ) ).setReadonly(); } }
private <V extends FileAttributeView> V getSymLinkSensitiveFileAttributeView( Class<V> type, EightyPath real, EightyFS efs ) { Optional<EightySymLink> sym = real._getFileSystem().getSymLink( real ); if( sym.isPresent() ) { return addIsLinkIfPossible( type, efs.getFileAttributeView( sym.get().getHost(), type ) ); } // not a link return efs.getFileAttributeView( real, type ); }
/** * if the the FAV is actually a BasicFileAttributeView then there is an isLink method * if this is not already set and FAV implements LinkInfoSettable use it to add this link info */ @SuppressWarnings( "PMD.CollapsibleIfStatements" ) private <V extends FileAttributeView> V addIsLinkIfPossible( Class<V> type, V fav ) { if( BasicFileAttributeView.class.isAssignableFrom( type ) ) { if( (! v( () -> BasicFileAttributeView.class.cast( fav ).readAttributes()).isSymbolicLink() )) { if( !( fav instanceof LinkInfoSettable ) ) { throw new UnsupportedOperationException( "the attribute view need to implement LinkInfoSettable in order to make SymLinks work" ); } ( (LinkInfoSettable) ( fav ) ).setLink(); } } return fav; }
private <V extends FileAttributeView> V getFileAttributeViewDummy( Path path, final Class<V> type ) { return RuntimeProxy.of( type, name -> { if( name.equals( "name" ) ) { return "FileAttributeProxy"; } throw new NoSuchFileException( path.toString() ); } ); }
public <A extends BasicFileAttributes> A readAttributes( EightyPath path, final Class<A> type, LinkOption... options ) throws IOException { if( !isReadSupported( type ) ) { throw new UnsupportedOperationException( type + " not a supported FileAttributes class" ); } if( !existsEx( path, options ) ) { throw new NoSuchFileException( path + " does not exist" ); } RWAttributes att = fromRead.get( type ).orElseThrow( () -> new UnsupportedOperationException( type + " not a supported FileAttributes class" ) ); FileAttributeView fav = getFileAttributeView( path, att.getViewType(), options ).orElseThrow( () -> new UnsupportedOperationException( type + " not a supported FileAttributes class" ) ); return att.getReadAttributes( type, fav ); }
public Object read( FileAttributeView view, String attiName ) { checkViewType( view ); return reads.getOrThrow( attiName, new IllegalArgumentException( "attribute " + attiName + " not in view " + getViewName() ) ) .apply( v( () -> readType.cast( viewType.cast( view ).readAttributes() ) ) ); }