Java 类java.nio.file.attribute.DosFileAttributeView 实例源码
项目:tinyMediaManager
文件:FSTest.java
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;
}
项目:ephemeralfs
文件:AttributeLookup.java
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);
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@Test
public void testSetGetSystem() throws Exception {
for(Path path : Arrays.asList(
Files.createDirectory(root.resolve("dir")),
Files.createFile(root.resolve("file")))) {
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isSystem());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setSystem(true);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isSystem());
}
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@IgnoreIf(FsType.WINDOWS)
@Test
public void testSetGetArchiveUnix() throws Exception {
for(Path path : Arrays.asList(
Files.createDirectory(root.resolve("dir")),
Files.createFile(root.resolve("file")))) {
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isArchive());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setArchive(true);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isArchive());
}
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@Test
public void testSetGetReadOnly() throws Exception {
for(Path path : Arrays.asList(
Files.createDirectory(root.resolve("dir")),
Files.createFile(root.resolve("file")))) {
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isReadOnly());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
try {
view.setReadOnly(true);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isReadOnly());
} finally {
view.setReadOnly(false);
}
}
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@Test
public void testSetGetHidden() throws Exception {
for(Path path : Arrays.asList(
Files.createDirectory(root.resolve("dir")),
Files.createFile(root.resolve("file")))) {
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isHidden());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setHidden(true);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isHidden());
}
}
项目:ant
文件:SetPermissions.java
private void tryDos(Path p, boolean failIfDosIsNotSupported) {
log("Falling back to DosFileAttributeView");
boolean readOnly = !isWritable();
DosFileAttributeView view = Files.getFileAttributeView(p, DosFileAttributeView.class);
if (view != null) {
try {
view.setReadOnly(readOnly);
} catch (IOException ioe) {
maybeThrowException(ioe, "Failed to set permissions on '%s' due to %s",
p, ioe.getMessage());
} catch (SecurityException uoe) {
maybeThrowException(null,
"the SecurityManager denies role accessUserInformation or write access for SecurityManager.checkWrite for resource '%s'",
p);
}
} else {
String msg = String.format(
"the associated path '%s' does not support the DosFileAttributeView",
p);
if (failIfDosIsNotSupported) {
throw new BuildException(msg);
}
log("Warning: " + msg, Project.MSG_ERR);
}
}
项目:EclipseCommander
文件:PathUtils.java
/**
* @param path
* @return
*/
public static String getDosAttributesString(Path path) {
DosFileAttributeView basicView = Files.getFileAttributeView(path, DosFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS);
StringBuilder attrs = new StringBuilder();
try {
// + all basic attributes
DosFileAttributes dosAttrs = basicView.readAttributes();
attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$
attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$
attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$
attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$
}
catch (IOException e) {
log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$
}
return attrs.toString();
}
项目:jsr203-hadoop
文件:TestFileStore.java
/**
* Test: File and FileStore attributes
*/
@Test
public void testFileStoreAttributes() 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 store1 = Files.getFileStore(path);
assertNotNull(store1);
assertTrue(store1.supportsFileAttributeView("basic"));
assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("posix") == store1
.supportsFileAttributeView(PosixFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("dos") == store1
.supportsFileAttributeView(DosFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("acl") == store1
.supportsFileAttributeView(AclFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("user") == store1
.supportsFileAttributeView(UserDefinedFileAttributeView.class));
}
项目:bazel
文件:ScopedTemporaryDirectory.java
private void makeWritable(Path file) throws IOException {
FileStore fileStore = Files.getFileStore(file);
if (IS_WINDOWS && fileStore.supportsFileAttributeView(DosFileAttributeView.class)) {
DosFileAttributeView dosAttribs =
Files.getFileAttributeView(file, DosFileAttributeView.class);
if (dosAttribs != null) {
dosAttribs.setReadOnly(false);
}
} else if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
PosixFileAttributeView posixAttribs =
Files.getFileAttributeView(file, PosixFileAttributeView.class);
if (posixAttribs != null) {
posixAttribs.setPermissions(EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE));
}
}
}
项目:pgcodekeeper
文件:FileUtils.java
public static void removeReadOnly(Path path) throws IOException {
DosFileAttributeView att = Files.getFileAttributeView(path, DosFileAttributeView.class);
if (att != null) {
att.setReadOnly(false);
}
Files.delete(path);
}
项目:fim
文件:DosFilePermissions.java
public static void setPermissions(Context context, Path file, String permissions) {
DosFileAttributeView fileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class);
try {
fileAttributeView.setArchive(permissions.contains("A"));
fileAttributeView.setHidden(permissions.contains("H"));
fileAttributeView.setReadOnly(permissions.contains("R"));
fileAttributeView.setSystem(permissions.contains("S"));
} catch (IOException ex) {
Logger.error("Error setting permissions for '" + file + "'", ex, context.isDisplayStackTrace());
}
}
项目:ephemeralfs
文件:FileAttributesViewBuilder.java
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");
}
}
项目:ephemeralfs
文件:EphemeralFsFileSystemProvider.java
private Class<? extends BasicFileAttributeView> viewClassFor(
Class<? extends BasicFileAttributes> attributeClass) {
if (attributeClass == BasicFileAttributes.class) {
return BasicFileAttributeView.class;
} else if (attributeClass == PosixFileAttributes.class) {
return PosixFileAttributeView.class;
} else if (attributeClass == DosFileAttributes.class) {
return DosFileAttributeView.class;
} else {
throw new IllegalArgumentException("unrecognized view class:"
+ attributeClass);
}
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@IgnoreIf(FsType.WINDOWS)
@Test
public void testReadOnlyCanStillWriteNotWindows() throws Exception {
Path path = Files.createFile(root.resolve("file"));
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setReadOnly(true);
Files.write(path, new byte[] {1});
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testReadOnlyCanStillWriteWindowsDir() throws Exception {
Path path = Files.createDirectory(root.resolve("dir"));
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setReadOnly(true);
try {
Files.delete(path);
fail();
} catch(AccessDeniedException e) {
//pass
}
Files.move(path, root.resolve("moveTo"));
}
项目:ephemeralfs
文件:AttributesTest.java
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testSupportsFileStoreWin() throws Exception {
for(FileStore fs : root.getFileSystem().getFileStores()) {
assertTrue(fs.supportsFileAttributeView(BasicFileAttributeView.class));
assertFalse(fs.supportsFileAttributeView(PosixFileAttributeView.class));
assertTrue(fs.supportsFileAttributeView(DosFileAttributeView.class));
assertTrue(fs.supportsFileAttributeView("basic"));
assertTrue(fs.supportsFileAttributeView("dos"));
}
}
项目:eightyfs
文件:EightyProvider.java
@Override
public boolean isHidden( @Nullable Path path ) throws IOException {
EightyPath ep = checkProvider( path );
AttributeProvider attributeProvider = ep._getFileSystem().getAttributeProvider();
if( attributeProvider.isViewSupported( DosFileAttributeView.class ) ) {
return _nn( readAttributes( path, DosFileAttributes.class ) ).isHidden();
}
@Nullable EightyPath fname = ep.getFileName();
return fname != null && fname.toString().startsWith( "." );
}
项目:eightyfs
文件:RWAttributesBuilder.java
public RWAttributesBuilder addDos() {
attributes( "dos", DosFileAttributeView.class, DosFileAttributes.class ).
attribute( "hidden", DosFileAttributes::isHidden,
BiConsumerE.u( ( v, b ) -> v.setHidden( (Boolean) b ) ) ).
attribute( "readonly", DosFileAttributes::isReadOnly ).
attribute( "system", DosFileAttributes::isSystem ).
attribute( "archive", DosFileAttributes::isArchive );
return this;
}
项目:niotest
文件:Tests17Windows.java
@Test
@Category( { Windows.class, DosAttributesT.class, Writable.class } )
public void testWindowsIsHidden() throws IOException {
assertThat( Files.isHidden( fileTA() ) ).isFalse();
Files.getFileAttributeView( absTA(), DosFileAttributeView.class ).setHidden( true );
assertThat( Files.isHidden( fileTA() ) ).isTrue();
Files.setAttribute( absTA(), "dos:hidden", false );
assertThat( Files.isHidden( fileTA() ) ).isFalse();
}
项目:niotest
文件:WindowsBuilder.java
public WindowsBuilder( FSDescription descr, T t ) {
super( descr, t );
descr.removeTopic( Unix.class );
PathLimits pathLimits = new PathLimits( OS.WINDOWS );
PathSpec pathSpec = new PathSpecWindows();
descr.props.put( Tests10PathWithContent.ONE_CHAR_COUNT, pathLimits.getBigChar() );
descr.props.put( Tests10PathWithContent.MAX_FILENAME_LENGTH, pathSpec.getMaxFilenameLength() );
descr.props.put( Tests10PathWithContent.MAX_PATH_LENGTH, pathSpec.getMaxPathLength() );
descr.props.put( Tests10PathWithContent.GET_FILENAME_LENGTH, (Function<String,Integer>)pathSpec::getFilenameLength );
descr.props.put( Tests10PathWithContent.GET_PATH_LENGTH, (Function<String,Integer>)pathSpec::getPathLength );
descr.removeTopic( Posix.class );
descr.removeTopic( MoveWhile.class );
descr.removeTopic( NonCasePreserving.class );
descr.removeTopic( FileKeyT.class );
descr.attributeDescriptions.put( "dos",
attributeBuilding( DosAttributesT.class, "dos", DosFileAttributeView.class, DosFileAttributes.class ).
addAttribute( "hidden", DosFileAttributes::isHidden ).
addAttribute( "archive", DosFileAttributes::isArchive ).
addAttribute( "system", DosFileAttributes::isSystem ).
addAttribute( "readonly", DosFileAttributes::isReadOnly ).
build() );
}
项目:jimfs
文件:DosAttributeProviderTest.java
@Test
public void testView() throws IOException {
DosFileAttributeView view =
provider.view(
fileLookup(),
ImmutableMap.<String, FileAttributeView>of(
"basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
assertNotNull(view);
assertThat(view.name()).isEqualTo("dos");
DosFileAttributes attrs = view.readAttributes();
assertThat(attrs.isHidden()).isFalse();
assertThat(attrs.isArchive()).isFalse();
assertThat(attrs.isReadOnly()).isFalse();
assertThat(attrs.isSystem()).isFalse();
view.setArchive(true);
view.setReadOnly(true);
view.setHidden(true);
view.setSystem(false);
assertThat(attrs.isHidden()).isFalse();
assertThat(attrs.isArchive()).isFalse();
assertThat(attrs.isReadOnly()).isFalse();
attrs = view.readAttributes();
assertThat(attrs.isHidden()).isTrue();
assertThat(attrs.isArchive()).isTrue();
assertThat(attrs.isReadOnly()).isTrue();
assertThat(attrs.isSystem()).isFalse();
view.setTimes(FileTime.fromMillis(0L), null, null);
assertThat(view.readAttributes().lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
项目:simple-nfs
文件:LocalFileSystem.java
private Stat statPath(Path p, long inodeNumber) throws IOException {
Class<? extends BasicFileAttributeView> attributeClass =
IS_UNIX ? PosixFileAttributeView.class : DosFileAttributeView.class;
BasicFileAttributes attrs = Files.getFileAttributeView(p, attributeClass, NOFOLLOW_LINKS).readAttributes();
Stat stat = new Stat();
stat.setATime(attrs.lastAccessTime().toMillis());
stat.setCTime(attrs.creationTime().toMillis());
stat.setMTime(attrs.lastModifiedTime().toMillis());
if (IS_UNIX) {
stat.setGid((Integer) Files.getAttribute(p, "unix:gid", NOFOLLOW_LINKS));
stat.setUid((Integer) Files.getAttribute(p, "unix:uid", NOFOLLOW_LINKS));
stat.setMode((Integer) Files.getAttribute(p, "unix:mode", NOFOLLOW_LINKS));
stat.setNlink((Integer) Files.getAttribute(p, "unix:nlink", NOFOLLOW_LINKS));
} else {
DosFileAttributes dosAttrs = (DosFileAttributes)attrs;
stat.setGid(0);
stat.setUid(0);
int type = dosAttrs.isDirectory() ? Stat.S_IFDIR : Stat.S_IFREG;
stat.setMode( type |(dosAttrs.isReadOnly()? 0600 : 0400));
stat.setNlink(1);
}
stat.setDev(17);
stat.setIno((int) inodeNumber);
stat.setRdev(17);
stat.setSize(attrs.size());
stat.setFileid((int) inodeNumber);
stat.setGeneration(attrs.lastModifiedTime().toMillis());
return stat;
}
项目:jdk8u-jdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:openjdk-jdk10
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:openjdk9
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:jdk8u_jdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:lookaside_java-1.8.0-openjdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:infobip-open-jdk-8
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:jdk8u-dev-jdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testSetGetArchiveWindowsFile() throws Exception {
Path path = Files.createFile(root.resolve("file"));
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isArchive());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setArchive(false);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isArchive());
Files.write(path, new byte[] {1});
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isArchive());
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testSetGetArchiveWindowsDir() throws Exception {
Path path = Files.createDirectory(root.resolve("dir"));
DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
assertFalse(attributes.isArchive());
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setArchive(true);
attributes = Files.readAttributes(path, DosFileAttributes.class);
assertTrue(attributes.isArchive());
}
项目:ephemeralfs
文件:DosFileAttributesTest.java
private void clearReadOnly(Path path) throws IOException {
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
view.setReadOnly(false);
}
项目:jdk7-jdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:openjdk-source-code-learn
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:memoryfs
文件:MemoryFSBuilder.java
public static MemoryFSBuilder windows() {
return new MemoryFSBuilder().
pathSpec( new PathSpecWindows() ).
primaryStoreName( "c:").
attributeView( DosFileAttributeView.class );
}
项目:memoryfs
文件:MemoryFS.java
public static EightyFS create( Object s, RWAttributesBuilder ab, Map<String, Object> env ) {
List<?> attributeViews = (List<?>) env.getOrDefault( ATTRIBUTE_VIEWS, Collections.emptyList() );
ab.addOwner();
if ( attributeViews.contains( PosixFileAttributeView.class )) {
ab.addPosix();
}
if ( attributeViews.contains( DosFileAttributeView.class )) {
ab.addDos();
}
return new MemoryFS( s, env );
}
项目:OLD-OpenJDK8
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:JAVA_UNIT
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
项目:openjdk-jdk7u-jdk
文件:IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}