当前位置: 首页>>代码示例>>Java>>正文


Java Files.getAttribute方法代码示例

本文整理汇总了Java中java.nio.file.Files.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Files.getAttribute方法的具体用法?Java Files.getAttribute怎么用?Java Files.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.getAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInode

import java.nio.file.Files; //导入方法依赖的package包/类
private long getInode(File file) throws IOException {

        UserDefinedFileAttributeView view = null;
        // windows system and file customer Attribute
        if (OS_WINDOWS.equals(os)) {
            view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class);// 把文件的内容属性值放置在view里面?
            try {
                ByteBuffer buffer = ByteBuffer.allocate(view.size(INODE));// view.size得到inode属性值大小
                view.read(INODE, buffer);// 把属性值放置在buffer中
                buffer.flip();
                return Long.parseLong(Charset.defaultCharset().decode(buffer).toString());// 返回编码后的inode的属性值

            }
            catch (NoSuchFileException e) {
                long winode = random.nextLong();
                view.write(INODE, Charset.defaultCharset().encode(String.valueOf(winode)));
                return winode;
            }
        }
        long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");// 返回unix的inode的属性值
        return inode;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:ReliableTaildirEventReader.java

示例2: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	try (Scanner scanner = new Scanner(System.in)) {
		System.out.println("Enter path to the directory you want to mirror:");
		Path p = Paths.get(scanner.nextLine());
		int uid = (int) Files.getAttribute(p, "unix:uid");
		int gid = (int) Files.getAttribute(p, "unix:gid");
		System.out.println("Enter mount point:");
		Path m = Paths.get(scanner.nextLine());
		if (Files.isDirectory(p) && Files.isDirectory(m)) {
			try (FuseNioAdapter fs = AdapterFactory.createReadWriteAdapter(p)) {
				fs.mount(m, false, false, new String[]{"-ouid="+uid, "-ogid="+gid, "-ovolname=FUSE-NIO-Adapter", "-oauto_xattr", "-oatomic_o_trunc"});
				System.out.println("Mounted successfully. Enter anything to stop the server...");
				System.in.read();
				fs.umount();
				System.out.println("Unmounted successfully. Exiting...");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			System.err.println("Invalid directory.");
		}
	}
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:24,代码来源:MacMirroringTest.java

示例3: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	try (Scanner scanner = new Scanner(System.in)) {
		System.out.println("Enter path to the directory you want to mirror:");
		Path p = Paths.get(scanner.nextLine());
		int uid = (int) Files.getAttribute(p, "unix:uid");
		int gid = (int) Files.getAttribute(p, "unix:gid");
		System.out.println("Enter mount point:");
		Path m = Paths.get(scanner.nextLine());
		if (Files.isDirectory(p) && Files.isDirectory(m)) {
			try (FuseNioAdapter fs = AdapterFactory.createReadWriteAdapter(p)) {
				fs.mount(m, false, false, new String[]{"-ouid="+uid, "-ogid="+gid, "-oatomic_o_trunc"});
				System.out.println("Mounted successfully. Enter anything to stop the server...");
				System.in.read();
				fs.umount();
				System.out.println("Unmounted successfully. Exiting...");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			System.err.println("Invalid directory.");
		}
	}
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:24,代码来源:LinuxMirroringTest.java

示例4: getFileAttributes

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void getFileAttributes() throws IOException {

    Object obj = Files.getAttribute(new File("/Users/fathead/temp/file3").toPath(), "unix:ino");
    System.out.println(obj);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:7,代码来源:DoTestRuleFilterFactory.java

示例5: getUserId

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 *
 * @param filename the file name
 * @return the file user id
 * @throws FileSystemOperationException
 */
private long getUserId(
                        String filename ) {

    try {
        Integer uid = ( Integer ) Files.getAttribute( new File( filename ).toPath(), "unix:uid",
                                                      LinkOption.NOFOLLOW_LINKS );
        return uid.longValue();

    } catch( Exception e ) {
        throw new FileSystemOperationException( "Could not get UID for '" + filename + "'", e );
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:19,代码来源:LocalFileSystemOperations.java

示例6: getGroupId

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 *
 * @param filename file name
 * @return the file group id
 * @throws FileSystemOperationException
 */
private long getGroupId(
                         String filename ) {

    try {
        Integer gid = ( Integer ) Files.getAttribute( new File( filename ).toPath(), "unix:gid",
                                                      LinkOption.NOFOLLOW_LINKS );
        return gid.longValue();

    } catch( Exception e ) {
        throw new FileSystemOperationException( "Could not get GID for '" + filename + "'", e );
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:19,代码来源:LocalFileSystemOperations.java

示例7: getInode

import java.nio.file.Files; //导入方法依赖的package包/类
private long getInode(File file) throws IOException {
  long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");
  return inode;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:5,代码来源:ReliableTaildirEventReader.java

示例8: loadAndCheck

import java.nio.file.Files; //导入方法依赖的package包/类
private int loadAndCheck(Path p, AuthTimeWithHash time,
        KerberosTime currTime)
        throws IOException, KrbApErrException {
    int missed = 0;
    if (Files.isSymbolicLink(p)) {
        throw new IOException("Symlink not accepted");
    }
    try {
        Set<PosixFilePermission> perms =
                Files.getPosixFilePermissions(p);
        if (uid != -1 &&
                (Integer)Files.getAttribute(p, "unix:uid") != uid) {
            throw new IOException("Not mine");
        }
        if (perms.contains(PosixFilePermission.GROUP_READ) ||
                perms.contains(PosixFilePermission.GROUP_WRITE) ||
                perms.contains(PosixFilePermission.GROUP_EXECUTE) ||
                perms.contains(PosixFilePermission.OTHERS_READ) ||
                perms.contains(PosixFilePermission.OTHERS_WRITE) ||
                perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            throw new IOException("Accessible by someone else");
        }
    } catch (UnsupportedOperationException uoe) {
        // No POSIX permissions? Ignore it.
    }
    chan = Files.newByteChannel(p, StandardOpenOption.WRITE,
            StandardOpenOption.READ);

    long timeLimit = currTime.getSeconds() - readHeader(chan);

    long pos = 0;
    boolean seeNewButNotSame = false;
    while (true) {
        try {
            pos = chan.position();
            AuthTime a = AuthTime.readFrom(chan);
            if (a instanceof AuthTimeWithHash) {
                if (time.equals(a)) {
                    // Exact match, must be a replay
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                } else if (time.isSameIgnoresHash(a)) {
                    // Two different authenticators in the same second.
                    // Remember it
                    seeNewButNotSame = true;
                }
            } else {
                if (time.isSameIgnoresHash(a)) {
                    // Two authenticators in the same second. Considered
                    // same if we haven't seen a new style version of it
                    if (!seeNewButNotSame) {
                        throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                    }
                }
            }
            if (a.ctime < timeLimit) {
                missed++;
            } else {
                missed--;
            }
        } catch (BufferUnderflowException e) {
            // Half-written file?
            chan.position(pos);
            break;
        }
    }
    return missed;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:68,代码来源:DflCache.java

示例9: loadAndCheck

import java.nio.file.Files; //导入方法依赖的package包/类
private int loadAndCheck(Path p, AuthTimeWithHash time,
        KerberosTime currTime)
        throws IOException, KrbApErrException {
    int missed = 0;
    if (Files.isSymbolicLink(p)) {
        throw new IOException("Symlink not accepted");
    }
    try {
        Set<PosixFilePermission> perms =
                Files.getPosixFilePermissions(p);
        if (uid != -1 &&
                (Integer)Files.getAttribute(p, "unix:uid") != uid) {
            throw new IOException("Not mine");
        }
        if (perms.contains(PosixFilePermission.GROUP_READ) ||
                perms.contains(PosixFilePermission.GROUP_WRITE) ||
                perms.contains(PosixFilePermission.GROUP_EXECUTE) ||
                perms.contains(PosixFilePermission.OTHERS_READ) ||
                perms.contains(PosixFilePermission.OTHERS_WRITE) ||
                perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            throw new IOException("Accessible by someone else");
        }
    } catch (UnsupportedOperationException uoe) {
        // No POSIX permissions? Ignore it.
    }
    chan = Files.newByteChannel(p, StandardOpenOption.WRITE,
            StandardOpenOption.READ);

    long timeLimit = currTime.getSeconds() - readHeader(chan);

    long pos = 0;
    boolean seeNewButNotSame = false;
    while (true) {
        try {
            pos = chan.position();
            AuthTime a = AuthTime.readFrom(chan);
            if (a instanceof AuthTimeWithHash) {
                if (time.equals(a)) {
                    // Exact match, must be a replay
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                } else if (time.sameTimeDiffHash((AuthTimeWithHash)a)) {
                    // Two different authenticators in the same second.
                    // Remember it
                    seeNewButNotSame = true;
                }
            } else {
                if (time.isSameIgnoresHash(a)) {
                    // Two authenticators in the same second. Considered
                    // same if we haven't seen a new style version of it
                    if (!seeNewButNotSame) {
                        throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                    }
                }
            }
            if (a.ctime < timeLimit) {
                missed++;
            } else {
                missed--;
            }
        } catch (BufferUnderflowException e) {
            // Half-written file?
            chan.position(pos);
            break;
        }
    }
    return missed;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:68,代码来源:DflCache.java


注:本文中的java.nio.file.Files.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。