下面列出了怎么用java.nio.file.attribute.FileAttributeView的API类实例代码及写法,或者点击链接到github查看源代码。
@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) {
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);
}
@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)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path file,
Class<V> type,
LinkOption... options)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Test
public void getFileAttributeView() {
final Path path = mock(Path.class);
final Class<FileAttributeView> type = FileAttributeView.class;
provider.getFileAttributeView(path, type);
verify(delegate).getFileAttributeView(path, type);
}
@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)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Override
public boolean supportsFileAttributeView(
Class<? extends FileAttributeView> type) {
if (type == BasicFileAttributeView.class) {
return this.system.supportedFileAttributeViews().contains("basic");
}
if (type == PosixFileAttributeView.class) {
return this.system.supportedFileAttributeViews().contains("posix");
}
// FIXME Implements all FileAttributeView checks
return false;
}
@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);
}
@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)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Override
public <V extends FileAttributeView> V getFileAttributeView(Class<V> type) {
V fileAttributeView = baseStream.getFileAttributeView(type);
if (fileAttributeView != null) {
return fileAttributeView;
}
if (type == MCRMD5AttributeView.class) {
BasicFileAttributeView baseView = baseStream.getFileAttributeView(BasicFileAttributeView.class);
return (V) new MD5FileAttributeViewImpl(baseView, (v) -> dir);
}
return null;
}
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
Path localRelativePath = toLocalPath(path);
if (type == MCRMD5AttributeView.class) {
BasicFileAttributeView baseView = baseStream.getFileAttributeView(localRelativePath,
BasicFileAttributeView.class, options);
return (V) new MD5FileAttributeViewImpl(baseView, (v) -> resolve(path));
}
return baseStream.getFileAttributeView(localRelativePath, type, options);
}
@Test
public void getFileAttributeViewFromFile_shouldBeNotNull() throws IOException {
initRepository();
writeToCache("/file.txt");
commitToMaster();
initGitFileSystem();
assertNotNull(Files.getFileAttributeView(gfs.getPath("/file.txt"), FileAttributeView.class));
}
@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();
}
/**
* Returns a file attribute view of a given type.
* This method works in exactly the manner specified by the {@link Files#getFileAttributeView(Path, Class, LinkOption...)} method.
* <p>
* This provider supports {@link BasicFileAttributeView}, {@link FileOwnerAttributeView} and {@link PosixFileAttributeView}.
* All other classes will result in a {@code null} return value.
* <p>
* Note: if the type is {@link BasicFileAttributeView} or a sub type, the last access time and creation time must be {@code null} when calling
* {@link BasicFileAttributeView#setTimes(FileTime, FileTime, FileTime)}, otherwise an exception will be thrown.
* When setting the owner or group for the path, the name must be the UID/GID of the owner/group.
*/
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
Objects.requireNonNull(type);
if (type == BasicFileAttributeView.class) {
return type.cast(new AttributeView("basic", toSFTPPath(path))); //$NON-NLS-1$
}
if (type == FileOwnerAttributeView.class) {
return type.cast(new AttributeView("owner", toSFTPPath(path))); //$NON-NLS-1$
}
if (type == PosixFileAttributeView.class) {
return type.cast(new AttributeView("posix", toSFTPPath(path))); //$NON-NLS-1$
}
return null;
}
@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)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return
type.isAssignableFrom(GfsFileAttributeView.Basic.class)
|| type.isAssignableFrom(GfsFileAttributeView.Posix.class)
|| type.isAssignableFrom(GfsFileAttributeView.Git.class);
}
@SuppressWarnings("unchecked")
<V extends FileAttributeView> V getView(HadoopPath path, Class<V> type) {
if (type == null)
throw new NullPointerException();
if (type == BasicFileAttributeView.class)
return (V)new HadoopBasicFileAttributeView(path, false);
if (type == HadoopBasicFileAttributeView.class)
return (V)new HadoopBasicFileAttributeView(path, true);
if (type == FileOwnerAttributeView.class)
return (V)new HadoopPosixFileAttributeView(path, false);
if (type == PosixFileAttributeView.class)
return (V)new HadoopPosixFileAttributeView(path, true);
return null;
}
@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)
{
return Files.getFileAttributeView(unwrap(file), type, options);
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return
type.isAssignableFrom(GfsFileAttributeView.Basic.class)
|| type.isAssignableFrom(GfsFileAttributeView.Posix.class)
|| type.isAssignableFrom(GfsFileAttributeView.Git.class);
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return (type == BasicFileAttributeView.class ||
type == ZipFileAttributeView.class);
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return (type == BasicFileAttributeView.class ||
type == ZipFileAttributeView.class);
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return (type == BasicFileAttributeView.class ||
type == ZipFileAttributeView.class);
}