|
|
|
@ -19,7 +19,6 @@ import com.fanruan.api.util.StringKit;
|
|
|
|
|
import com.fr.io.repository.FineFileEntry; |
|
|
|
|
import com.fr.io.repository.base.BaseResourceRepository; |
|
|
|
|
import com.fr.stable.Filter; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.workspace.resource.ResourceIOException; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
@ -58,11 +57,9 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public FineFileEntry getEntry(String path) { |
|
|
|
|
GetObjectRequest request = new GetObjectRequest(bucket, path); |
|
|
|
|
try { |
|
|
|
|
try (S3Object s3Object = s3.getObject(request)) { |
|
|
|
|
return s3Object2FileEntry(s3Object, path); |
|
|
|
|
} |
|
|
|
|
ObjectMetadata metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
|
return s3Object2FileEntry(metadata, path); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
LogKit.info("{} not exist!", path); |
|
|
|
|
} |
|
|
|
@ -225,7 +222,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { |
|
|
|
|
|
|
|
|
|
String key = objectSummary.getKey(); |
|
|
|
|
if (StringUtils.equals(key, dir)) { |
|
|
|
|
if (StringKit.equals(key, dir)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String[] arr = key.split(DELIMITER); |
|
|
|
@ -291,14 +288,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
@Override |
|
|
|
|
public long length(String path) { |
|
|
|
|
try { |
|
|
|
|
S3Object s3Object = s3.getObject(bucket, path); |
|
|
|
|
if (s3Object != null) { |
|
|
|
|
try { |
|
|
|
|
return s3Object.getObjectMetadata().getContentLength(); |
|
|
|
|
} finally { |
|
|
|
|
s3Object.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ObjectMetadata metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
|
return metadata.getContentLength(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
LogKit.info("{} not exist!", path); |
|
|
|
|
} |
|
|
|
@ -342,17 +333,17 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
|
|
|
|
|
private FineFileEntry s3Object2FileEntry(S3ObjectSummary s3Object, String path) { |
|
|
|
|
FineFileEntry entry = new FineFileEntry(path); |
|
|
|
|
entry.setDirectory(s3Object.getKey().endsWith("/")); |
|
|
|
|
entry.setDirectory(s3Object.getKey().endsWith(DELIMITER)); |
|
|
|
|
entry.setSize(s3Object.getSize()); |
|
|
|
|
entry.setTimestamp(s3Object.getLastModified().getTime()); |
|
|
|
|
return entry; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private FineFileEntry s3Object2FileEntry(S3Object s3Object, String path) { |
|
|
|
|
private FineFileEntry s3Object2FileEntry(ObjectMetadata metadata, String path) { |
|
|
|
|
FineFileEntry entry = new FineFileEntry(path); |
|
|
|
|
entry.setDirectory(s3Object.getKey().endsWith("/")); |
|
|
|
|
entry.setSize(s3Object.getObjectMetadata().getContentLength()); |
|
|
|
|
entry.setTimestamp(s3Object.getObjectMetadata().getLastModified().getTime()); |
|
|
|
|
entry.setDirectory(path.endsWith(DELIMITER)); |
|
|
|
|
entry.setSize(metadata.getContentLength()); |
|
|
|
|
entry.setTimestamp(metadata.getLastModified().getTime()); |
|
|
|
|
return entry; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|