本文整理汇总了Java中java.nio.file.attribute.BasicFileAttributeView类的典型用法代码示例。如果您正苦于以下问题:Java BasicFileAttributeView类的具体用法?Java BasicFileAttributeView怎么用?Java BasicFileAttributeView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicFileAttributeView类属于java.nio.file.attribute包,在下文中一共展示了BasicFileAttributeView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueAt
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return templates[rowIndex].getName();
} else if (columnIndex == 1) {
return templates[rowIndex].getVersion();
} else if (columnIndex == 2) {
return templates[rowIndex].getShortDescription();
} else if (columnIndex == 3) {
Path temPath = Paths.get(templates[rowIndex].getFile().getAbsolutePath());
try {
BasicFileAttributes view = Files.getFileAttributeView(temPath, BasicFileAttributeView.class).readAttributes();
FileTime creationTime = view.creationTime();
DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
String cTime = df.format(creationTime.toMillis());
return cTime;
} catch (IOException e) {
return "--";
}
} else {
return null;
}
}
示例2: getFileAttributeView
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@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;
}
示例3: getFileAttributeView
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@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;
}
示例4: postVisitDirectory
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException {
try {
if (copyOptionsSet.contains(COPY_ATTRIBUTES)) {
/*
* Copy file times. Inspired by
* java.nio.file.CopyMoveHelper.copyToForeignTarget()
*/
BasicFileAttributes attrs = readAttributes(dir,
BasicFileAttributes.class, linkOptions);
BasicFileAttributeView view = getFileAttributeView(
toDestination(dir), BasicFileAttributeView.class,
linkOptions);
view.setTimes(attrs.lastModifiedTime(), attrs.lastAccessTime(),
attrs.creationTime());
}
return CONTINUE;
} catch (IOException ex) {
return visitFileFailed(dir, ex);
}
}
示例5: setTimes
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void setTimes(IgfsPath path, long modificationTime, long accessTime) throws IgniteException {
Path p = fileForPath(path).toPath();
if (!Files.exists(p))
throw new IgfsPathNotFoundException("Failed to set times (path not found): " + path);
try {
Files.getFileAttributeView(p, BasicFileAttributeView.class)
.setTimes(
(modificationTime >= 0) ? FileTime.from(modificationTime, TimeUnit.MILLISECONDS) : null,
(accessTime >= 0) ? FileTime.from(accessTime, TimeUnit.MILLISECONDS) : null,
null);
}
catch (IOException e) {
throw new IgniteException("Failed to set times for path: " + path, e);
}
}
示例6: basicAttributes
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
/**
* Get POSIX attributes for file.
*
* @param file File.
* @return BasicFileAttributes.
*/
@Nullable public static BasicFileAttributes basicAttributes(File file) {
BasicFileAttributes attrs = null;
try {
BasicFileAttributeView view = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);
if (view != null)
attrs = view.readAttributes();
}
catch (IOException e) {
throw new IgfsException("Failed to read basic file attributes: " + file.getAbsolutePath(), e);
}
return attrs;
}
示例7: getSupportedFileAttributes
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
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;
}
示例8: supportsFileAttributeView
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
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);
}
示例9: testSetLastModifiedTimeAfterMove
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Test
public void testSetLastModifiedTimeAfterMove() throws Exception {
Path path = root.resolve("test");
Files.createFile(path);
BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class);
Path movedTo = root.resolve("test2");
Files.move(path, movedTo);
long newModified = roundToSeconds(System.currentTimeMillis()) - 10000;
try {
view.setTimes(FileTime.fromMillis(newModified), null, null);
fail();
} catch (NoSuchFileException e) {
//pass
}
}
示例10: testGetAttributesThenMoveFile
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Test
public void testGetAttributesThenMoveFile() throws Exception {
long start = System.currentTimeMillis();
Path parent = root.resolve("test");
Files.createFile(parent);
BasicFileAttributeView attributes = Files.getFileAttributeView(parent, BasicFileAttributeView.class);
assertTrue(attributes.readAttributes().creationTime().toMillis() > start - 6000);
Files.move(parent, parent.resolveSibling("test2"));
try
{
attributes.readAttributes();
fail();
} catch(NoSuchFileException e) {
//pass
}
}
示例11: getLastModified
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Override
public long getLastModified(final Object templateSource) {
Path templateAsPath = (Path) templateSource;
BasicFileAttributeView basicView = Files.getFileAttributeView(templateAsPath,
BasicFileAttributeView.class);
// This attribute view is perhaps not available in this system
if (basicView != null) {
BasicFileAttributes basic;
try {
basic = basicView.readAttributes();
} catch (IOException e) {
return -1;
}
return basic.lastModifiedTime().toMillis();
} else {
return -1;
}
}
示例12: newDirectoryStream
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Override
public
@Nullable
DirectoryStream<Path> newDirectoryStream( @Nullable Path dirArg, @Nullable DirectoryStream.Filter<? super Path> filter ) throws IOException {
EightyPath nnDir = checkProvider( dirArg );
EightyPath dir = toRealPath( nnDir );
if( !Files.exists( dir ) ) {
throw new NoSuchFileException( "dir " + dir + " does not exist" );
}
// todo set time now or after close ?
FileTime now = FileTime.from( Clock.systemUTC().instant() );
if( !dir._getFileSystem().isReadOnly() ) {
Files.getFileAttributeView( dirArg, BasicFileAttributeView.class ).setTimes( null, now, null );
}
// todo: test for throw
return dir._getFileSystem().addClosable( new EightyDirectoryStream(
dirArg,
dir._getFileSystem().get80().newDirectoryStream( dir ),
_n1( filter ) ) );
}
示例13: createDirectory
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Override
public void createDirectory( @Nullable Path dirArg, @Nullable FileAttribute<?>... attrs ) throws IOException {
EightyFS eighty = checkProviderAndGet80( dirArg );
EightyPath dir = toRealPathEx( (EightyPath) _n0( dirArg ), NOFOLLOW_LINKS );
if( existsEx( dir, NOFOLLOW_LINKS ) ) {
throw new FileAlreadyExistsException( dir.toString() );
}
// an absolute path (toRealPath) that does not exist has a parent
EightyPath parent = childGetParent( dir );
if( !Files.isDirectory( parent ) ) {
throw new NoSuchFileException( parent.toString() );
}
throwIfPathIsNotAccessible( dir );
eighty.createDirectory( dir, _nargs( attrs ) );
FileTime now = FileTime.from( Clock.systemUTC().instant() );
Files.getFileAttributeView( parent, BasicFileAttributeView.class ).setTimes( now, now, null );
parent._getFileSystem().signal( dir, StandardWatchEventKinds.ENTRY_CREATE );
}
示例14: addBasic
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
public RWAttributesBuilder addBasic() {
attributes( "basic", BasicFileAttributeView.class, BasicFileAttributes.class ).
attribute( LAST_MODIFIED_TIME_NAME,
BasicFileAttributes::lastModifiedTime,
u( ( ( view, val ) -> view.setTimes( (FileTime) val, null, null ) ) ) ).
attribute( LAST_ACCESS_TIME_NAME,
BasicFileAttributes::lastAccessTime,
u( ( view, val ) -> view.setTimes( null, (FileTime) val, null ) ) ).
attribute( SIZE_NAME, BasicFileAttributes::size ).
attribute( CREATION_TIME_NAME, BasicFileAttributes::creationTime,
u( ( view, val ) -> view.setTimes( null, null, (FileTime) val ) ) ).
attribute( FILE_KEY_NAME, BasicFileAttributes::fileKey ).
attribute( IS_DIRECTORY_NAME, BasicFileAttributes::isDirectory ).
attribute( IS_REGULAR_FILE_NAME, BasicFileAttributes::isRegularFile ).
attribute( IS_OTHER_NAME, BasicFileAttributes::isOther ).
attribute( IS_SYMBOLIC_LINK_NAME, BasicFileAttributes::isSymbolicLink )
;
return this;
}
示例15: testFileStore
import java.nio.file.attribute.BasicFileAttributeView; //导入依赖的package包/类
@Test
public void testFileStore() throws URISyntaxException, IOException {
URI uri = clusterUri.resolve("/tmp/testFileStore");
Path path = Paths.get(uri);
if (Files.exists(path))
Files.delete(path);
assertFalse(Files.exists(path));
Files.createFile(path);
assertTrue(Files.exists(path));
FileStore st = Files.getFileStore(path);
assertNotNull(st);
Assert.assertNotNull(st.name());
Assert.assertNotNull(st.type());
Assert.assertFalse(st.isReadOnly());
Assert.assertNotEquals(0, st.getTotalSpace());
Assert.assertNotEquals(0, st.getUnallocatedSpace());
Assert.assertNotEquals(0, st.getUsableSpace());
Assert
.assertTrue(st.supportsFileAttributeView(BasicFileAttributeView.class));
Assert.assertTrue(st.supportsFileAttributeView("basic"));
st.getAttribute("test");
}