forked from martint/s3fs
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed issue #56 implemented readAttributes(Path, String)
- Loading branch information
Showing
7 changed files
with
283 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/com/upplication/s3fs/util/AttributesUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.upplication.s3fs.util; | ||
|
||
|
||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Utilities to help transforming BasicFileAttributes to Map | ||
*/ | ||
public abstract class AttributesUtil { | ||
|
||
/** | ||
* Given a BasicFileAttributes not null then return a Map | ||
* with the keys as the fields of the BasicFileAttributes and the values | ||
* with the content of the fields | ||
* @param attr BasicFileAttributes | ||
* @return Map String Object never null | ||
*/ | ||
public static Map<String, Object> fileAttributeToMap(BasicFileAttributes attr) { | ||
Map<String, Object> result = new HashMap<>(); | ||
result.put("creationTime", attr.creationTime()); | ||
result.put("fileKey", attr.fileKey()); | ||
result.put("isDirectory", attr.isDirectory()); | ||
result.put("isOther", attr.isOther()); | ||
result.put("isRegularFile", attr.isRegularFile()); | ||
result.put("isSymbolicLink", attr.isSymbolicLink()); | ||
result.put("lastAccessTime", attr.lastAccessTime()); | ||
result.put("lastModifiedTime", attr.lastModifiedTime()); | ||
result.put("size", attr.size()); | ||
return result; | ||
} | ||
|
||
/** | ||
* transform the BasicFileAttributes to Map filtering by the keys | ||
* given in the filters param | ||
* @param attr BasicFileAttributes not null to tranform to map | ||
* @param filters String[] filters | ||
* @return Map String Object with the same keys as the filters | ||
*/ | ||
public static Map<String, Object> fileAttributeToMap(BasicFileAttributes attr, String[] filters) { | ||
Map<String, Object> result = new HashMap<>(); | ||
|
||
for (String filter : filters) { | ||
filter = filter.replace("basic:", ""); | ||
switch (filter){ | ||
case "creationTime": | ||
result.put("creationTime", attr.creationTime()); | ||
break; | ||
case "fileKey": | ||
result.put("fileKey", attr.fileKey()); | ||
break; | ||
case "isDirectory": | ||
result.put("isDirectory", attr.isDirectory()); | ||
break; | ||
case "isOther": | ||
result.put("isOther", attr.isDirectory()); | ||
break; | ||
case "isRegularFile": | ||
result.put("isRegularFile", attr.isRegularFile()); | ||
break; | ||
case "isSymbolicLink": | ||
result.put("isSymbolicLink", attr.isSymbolicLink()); | ||
break; | ||
case "lastAccessTime": | ||
result.put("lastAccessTime", attr.lastAccessTime()); | ||
break; | ||
case "lastModifiedTime": | ||
result.put("lastModifiedTime", attr.lastModifiedTime()); | ||
break; | ||
case "size": | ||
result.put("size", attr.size()); | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.