1515public class S3Utils {
1616
1717 /**
18- * Get the {@link com.amazonaws.services.s3.model. S3ObjectSummary} that represent this Path or her first child if this path not exists
19- * @param s3Path {@link com.upplication.s3fs. S3Path}
20- * @return {@link com.amazonaws.services.s3.model. S3ObjectSummary}
21- * @throws java.nio.file. NoSuchFileException if not found the path and any child
18+ * Get the {@link S3ObjectSummary} that represent this Path or her first child if this path not exists
19+ * @param s3Path {@link S3Path}
20+ * @return {@link S3ObjectSummary}
21+ * @throws NoSuchFileException if not found the path and any child
2222 */
2323 public S3ObjectSummary getS3ObjectSummary (S3Path s3Path ) throws NoSuchFileException {
2424 String key = s3Path .getKey ();
@@ -61,9 +61,19 @@ public S3ObjectSummary getS3ObjectSummary(S3Path s3Path) throws NoSuchFileExcept
6161 * @return S3FileAttributes
6262 */
6363 public S3FileAttributes getS3FileAttributes (S3Path s3Path ) throws NoSuchFileException {
64- String key = s3Path .getKey ();
6564 S3ObjectSummary objectSummary = getS3ObjectSummary (s3Path );
65+ return toS3FileAttributes (objectSummary , s3Path .getKey ());
66+ }
6667
68+ /**
69+ * convert S3ObjectSummary to S3FileAttributes
70+ * @param objectSummary S3ObjectSummary mandatory not null, the real objectSummary with
71+ * exactly the same key than the key param or the immediate descendant
72+ * if it is a virtual directory
73+ * @param key String the real key that can be exactly equal than the objectSummary or
74+ * @return S3FileAttributes
75+ */
76+ public S3FileAttributes toS3FileAttributes (S3ObjectSummary objectSummary , String key ) {
6777 // parse the data to BasicFileAttributes.
6878 FileTime lastModifiedTime = null ;
6979 if (objectSummary .getLastModified () != null ){
@@ -77,8 +87,7 @@ public S3FileAttributes getS3FileAttributes(S3Path s3Path) throws NoSuchFileExce
7787 if (key .endsWith ("/" ) && resolvedKey .equals (key ) ||
7888 resolvedKey .equals (key + "/" )) {
7989 directory = true ;
80- }
81- else if (key .isEmpty ()) { // is a bucket (no key)
90+ } else if (key .isEmpty ()) { // is a bucket (no key)
8291 directory = true ;
8392 resolvedKey = "/" ;
8493 }
@@ -88,8 +97,9 @@ else if (!resolvedKey.equals(key) && resolvedKey.startsWith(key)) { // is a dire
8897 size = 0 ;
8998 // delete extra part
9099 resolvedKey = key + "/" ;
91- } else
100+ } else {
92101 regularFile = true ;
102+ }
93103 return new S3FileAttributes (resolvedKey , lastModifiedTime , size , directory , regularFile );
94104 }
95- }
105+ }
0 commit comments