Search in sources :

Example 11 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project OpenClinica by OpenClinica.

the class SystemController method displayOwnerShipForTomcatDirectory.

public ArrayList<HashMap<String, Object>> displayOwnerShipForTomcatDirectory(File file) throws IOException {
    ArrayList<HashMap<String, Object>> listOfHashMaps = new ArrayList<>();
    HashMap<String, Object> hashMap = null;
    if (file.isDirectory()) {
        hashMap = new HashMap<String, Object>();
        hashMap.put("Read Access", getReadAccess(file));
        hashMap.put("Write Access", getWriteAccess(file));
        Path path = Paths.get(file.getCanonicalPath());
        FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
        UserPrincipal owner = ownerAttributeView.getOwner();
        // hashMap.put("ownership", owner.getName());
        hashMap.put("Folder Name", file.getName());
        listOfHashMaps.add(hashMap);
        int dirCount = getNumberOfSubFolders(file.getCanonicalPath().toString());
        if (dirCount != 0) {
            hashMap.put("Sub Folders", displayOwnerShipForTomcatSubDirectories(file));
        }
    }
    return listOfHashMaps;
}
Also used : Path(java.nio.file.Path) FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserPrincipal(java.nio.file.attribute.UserPrincipal)

Aggregations

FileOwnerAttributeView (java.nio.file.attribute.FileOwnerAttributeView)11 File (java.io.File)4 Path (java.nio.file.Path)4 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)4 UserPrincipal (java.nio.file.attribute.UserPrincipal)4 HashMap (java.util.HashMap)4 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 Date (java.util.Date)3 IOException (java.io.IOException)2 FileStore (java.nio.file.FileStore)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1