Java Code Examples for java.nio.file.attribute.FileOwnerAttributeView

Following code examples demonstrate how to use java.nio.file.attribute.FileOwnerAttributeView from java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.nio.file.attribute.FileOwnerAttributeView and various code implementation of this class.
Example 1
Project : java Source File : FileInfo.java View Source Code on GitHub

    public static void main(String[] args) throws IOException{
    	
            Path testPath = Paths.get("E:\\EclipseBulider\\j-util\\src\\main\\webapp\\WEB-INF\\lib\\mybatis-generator-core-1.3.2.jar");
            BasicFileAttributeView basicView = Files.
                    getFileAttributeView(testPath, BasicFileAttributeView.class);
            BasicFileAttributes basicFileAttributes = basicView.readAttributes();

            System.out.println("创建时间:" + new Date(basicFileAttributes.creationTime()
                    .toMillis()));

            System.out.println("最后访问时间:" + new Date(basicFileAttributes.
                    lastAccessTime().toMillis()));

            System.out.println("最后修改时间:" + new Date(basicFileAttributes.
                    lastModifiedTime().toMillis()));

            System.out.println("文件大小:" + basicFileAttributes.size());

            FileOwnerAttributeView ownerView = Files.getFileAttributeView(testPath, 
                    FileOwnerAttributeView.class);

            System.out.println("文件所有者:" + ownerView.getOwner());


    }
			
Example 2
Project : java Source File : FileOwnerManagement.java View Source Code on GitHub

	public static void main(String[] args) throws IOException {
		try {
			Path path = Paths.get("C:\\poems\\luci1.txt");
			
			FileOwnerAttributeView foav =
			 Files.getFileAttributeView(
				path,FileOwnerAttributeView.class);

			UserPrincipal owner = foav.getOwner();
			System.out.format("Original owner of %s is %s%n",
			                  path, owner.getName());
			
			FileSystem fs = FileSystems.getDefault();
			UserPrincipalLookupService upls =
				fs.getUserPrincipalLookupService();
			
			UserPrincipal newOwner = 
				upls.lookupPrincipalByName("brice");
			foav.setOwner(newOwner);

			UserPrincipal changedOwner = foav.getOwner();
			System.out.format("New owner of %s is %s%n",
			                  path, changedOwner.getName());
		} 
		catch (UnsupportedOperationException | IOException e) {
			e.printStackTrace();
		} 
	}
			
Example 3
Project : java Source File : AttributeViewTest.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {
        Path testPath = Paths.get("src/le10/AttributeViewTest.java");
        BasicFileAttributeView basicView = Files.getFileAttributeView(
                testPath, BasicFileAttributeView.class);
        BasicFileAttributes basicAttribs = basicView.readAttributes();
        System.out.println("创建时间:" + new Date(basicAttribs.creationTime().toMillis()));
        System.out.println("最后访问时间:" + new Date(basicAttribs.lastAccessTime().toMillis()));
        System.out.println("最后修改时间:" + new Date(basicAttribs.lastModifiedTime().toMillis()));
        System.out.println("文件大小:" + basicAttribs.size());
        FileOwnerAttributeView fileOwnAttrs = Files.getFileAttributeView(
                testPath, FileOwnerAttributeView.class);
        System.out.println("文件拥有者:" + fileOwnAttrs.getOwner());
    }
			
Example 4
Project : java Source File : FileOwnerView02.java View Source Code on GitHub

	public static void main(String[] args) {
		UserPrincipal owner = null;
		Path path = Paths.get(System.getProperty("user.home"), "Downloads", "dojo.pdf");
		FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
		
		try {
			owner = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("administrator");
			foav.setOwner(owner);
		} catch (IOException e) {
			System.err.println(e);
		}
		
		System.out.println(owner);
	}
			
Example 5
Project : java Source File : FileOwnerAttributeTest.java View Source Code on GitHub

	public static void main(String[] args) {
		Path path = Paths.get("C:/application_logs/spring_jta_transaction/transaction.log");
		UserPrincipal owner = null;
		FileOwnerAttributeView foav = null;
		try {
			owner = (UserPrincipal) Files.getAttribute(path, "owner:owner", NOFOLLOW_LINKS);
			foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
			String role_owner = foav.getOwner().getName();
			System.out.println("FileOwnerAttributeView role:"+role_owner);
		}catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
			
Example 6
Project : java Source File : FileAttributeTest.java View Source Code on GitHub

	public static void main(String[] args) {
		AclFileAttributeView a;
		BasicFileAttributeView b;
		DosFileAttributeView d;
		FileOwnerAttributeView f;
		PosixFileAttributeView p;
	}
			
Example 7
Project : java Source File : FilesAttributeViewRunner.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {
        final Path derbyLogPath = Paths.get("derby.log");
        final BasicFileAttributes fileAttributes = Files.readAttributes(derbyLogPath, BasicFileAttributes.class);
        System.out.println("Creation time: " + fileAttributes.creationTime());
        System.out.println("Size: " + fileAttributes.size());

        final BasicFileAttributeView basicFileAttributeView = Files.getFileAttributeView(derbyLogPath, BasicFileAttributeView.class);
        basicFileAttributeView.setTimes(null, null, null);
        System.out.println("Name: " + basicFileAttributeView.name());

        final FileOwnerAttributeView fileOwnerAttributeView = Files.getFileAttributeView(derbyLogPath, FileOwnerAttributeView.class);
        System.out.println("Owner: " + fileOwnerAttributeView.getOwner());

        final UserPrincipalLookupService userPrincipalLookupService = FileSystems.getDefault().getUserPrincipalLookupService();
        final UserPrincipal mxf = userPrincipalLookupService.lookupPrincipalByName("mxf");
        System.out.println(mxf);
    }
			
Example 8
Project : java Source File : UserPrincipalTest.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {

        Path path = Paths.get("D:\\daily\\BR_BRAND_CRM_zfb_20111215", "brandcrm.properties");

        UserPrincipal gaopengxiang = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("gaopengxiang");

        System.out.println(gaopengxiang.getName());


        Files.setOwner(path, gaopengxiang);


        FileOwnerAttributeView fileAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        UserPrincipal owner = fileAttributeView.getOwner();

        Files.setOwner(path,owner);

        fileAttributeView.setOwner(owner);

        Files.setAttribute(path, "owner:owner", owner, LinkOption.NOFOLLOW_LINKS);

    }
			
Example 9
Project : java Source File : FileOwnerView04.java View Source Code on GitHub

	public static void main(String[] args) {
		Path path = Paths.get(System.getProperty("user.home"), "Downloads", "dojo.pdf");
		FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
		
		try {
			String owner = foav.getOwner().getName();
			System.out.println(owner);
		} catch (IOException e) {
			System.err.println(e);
		}
	}
			
Example 10
Project : java Source File : Execute.java View Source Code on GitHub

	public static void main(String[] args) {
		Path dire = Paths.get("source\\dalieOCP\\fileAndDirectoryAttributes");
		Path file = Paths.get("Execute.txt");
		FileOwnerAttributeView fileOwnerView = Files.getFileAttributeView(dire.resolve(file), FileOwnerAttributeView.class);
		try {
			UserPrincipal userPrincipal = fileOwnerView.getOwner();
		
		} catch (IOException e){
			e.printStackTrace();
		}
	}
			
Example 11
Project : java Source File : FileOwner.java View Source Code on GitHub

	public void getOwner() {
		FileOwnerAttributeView attributes = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
		try {
			System.out.println(attributes.getOwner().getName()
			);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
			
Example 12
Project : java Source File : GetOwnerExample.java View Source Code on GitHub

    public static void main(String[] args) {
        Path path = Paths.get("C:/home/docs/users.txt");
        try {
            FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
            UserPrincipal userPrincipal = view.getOwner();
            System.out.println(userPrincipal.getName());
           

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
			
Example 13
Project : java Source File : FileItemProcessor.java View Source Code on GitHub

	public FileInfo process(final File file) throws Exception {
		Path path = Paths.get(file.getPath());
		FileInfo fileInfo = new FileInfo();
		fileInfo.setFileName(file.getName());
		fileInfo.setFilePath(file.getAbsolutePath());
		fileInfo.setSize(file.length());
		fileInfo.setLastModified(file.lastModified());
		FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
		fileInfo.setOwner(ownerAttributeView.getOwner().getName());
		BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
		fileInfo.setCreated(attributes.creationTime().toMillis());

		return fileInfo;
	}
			
Example 14
Project : java Source File : SearchByFileOwner.java View Source Code on GitHub

    public boolean check(File file, String criteria) {
        FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(file.toPath(), FileOwnerAttributeView.class);
        try {
            UserPrincipal owner = ownerAttributeView.getOwner();
            return owner.getName().equalsIgnoreCase(criteria);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
			
Example 15
Project : java Source File : Pjava.java View Source Code on GitHub

	 public static void main(String[] args) throws Exception{

	        Path path = Paths.get("/home/jianglibo/pjava.txt");
	        FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
	        UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
	        UserPrincipal userPrincipal = lookupService.lookupPrincipalByName("tomcat");
	        view.setOwner(userPrincipal);
	        System.out.println("Owner: " + view.getOwner().getName());
	}
			
Example 16
Project : java Source File : UsageFileOwnerAttributeView.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {
        Path path = Paths.get("/tmp/docs/users.txt");

        FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
        UserPrincipal userPrincipal = view.getOwner();
        System.out.println(userPrincipal.getName());
    }
			
Example 17
Project : java Source File : SettingOwnerExample.java View Source Code on GitHub

    public static void main(String[] args) {
        Path path = Paths.get("C:/home/docs/users.txt");
        FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
        try {
            UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
            UserPrincipal userPrincipal = lookupService.lookupPrincipalByName("mary");

            view.setOwner(userPrincipal);
            System.out.println("Owner: " + view.getOwner().getName());
        } catch (IOException ex) {
            ex.printStackTrace();
        }


    }
			
Example 18
Project : java Source File : FileOwnerAttributeViewClassTests.java View Source Code on GitHub

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to FileOwnerAttributeView.class!",
                   FileOwnerAttributeView.class.isAssignableFrom(sut));
    }
			
Example 19
Project : java Source File : UsageOwnerAttributes.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {
        Path path = Paths.get("/tmp/docs/users.txt");

        FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
        UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
        UserPrincipal userPrincipal = lookupService.lookupPrincipalByName("jennifer");

        view.setOwner(userPrincipal);
        System.out.println("Owner : " + view.getOwner().getName());
    }
			
Example 20
Project : java Source File : SupportedFileAttribViews.java View Source Code on GitHub

	public static void main(String[] args) {
		Path path = Paths.get("C:");

		try {
			FileStore fs = Files.getFileStore(path);
			printDetails(fs, AclFileAttributeView.class);
			printDetails(fs, BasicFileAttributeView.class);
			printDetails(fs, DosFileAttributeView.class);
			printDetails(fs, FileOwnerAttributeView.class);
			printDetails(fs, PosixFileAttributeView.class);
			printDetails(fs, UserDefinedFileAttributeView.class);
		} 
		catch (IOException ex) {
			ex.printStackTrace();
		}
	}