diff --git a/plugin.xml b/plugin.xml index 37aadfb..a1af8a6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,12 +5,13 @@ com.fanruan.fs yes no - 1.2.0 + 1.2.1 10.0 2020-01-27 richie [2020-08-17]修复key不存在时报错的问题。
[2020-07-09]修复zip文件上传之后为空的问题。
[2020-07-06]修复华为云OBS显示的问。
diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index e1f67f1..1151979 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -60,10 +60,15 @@ public class S3ResourceRepository extends BaseResourceRepository { GetObjectRequest request = new GetObjectRequest(bucket, path); try { S3Object s3Object = s3.getObject(request); - return s3Object2FileEntry(s3Object, path); + try { + return s3Object2FileEntry(s3Object, path); + } finally { + s3Object.close(); + } } catch (Exception e) { LogKit.info("{} not exist!", path); } + return null; } @@ -116,7 +121,12 @@ public class S3ResourceRepository extends BaseResourceRepository { public InputStream read(String filePath) throws ResourceIOException { GetObjectRequest request = new GetObjectRequest(bucket, filePath); try { - return s3.getObject(request).getObjectContent(); + S3Object s3Object = s3.getObject(request); + try { + return s3Object.getObjectContent(); + } finally { + s3Object.close(); + } } catch (Exception e) { return new ByteArrayInputStream(new byte[0]); } @@ -224,30 +234,48 @@ public class S3ResourceRepository extends BaseResourceRepository { if (listing.getObjectSummaries().isEmpty()) { return false; } - if (listing.getObjectSummaries().size() > 1) { + if (listing.getObjectSummaries().size() > 1) { return true; } else { S3ObjectSummary summary = listing.getObjectSummaries().get(0); - return !StringKit.equals(listing.getPrefix(), summary.getKey()); + return !StringKit.equals(listing.getPrefix(), summary.getKey()); } } @Override public long lastModified(String path) { - S3Object s3Object = s3.getObject(bucket, path); - if (s3Object == null) { - return -1L; + try { + S3Object s3Object = s3.getObject(bucket, path); + if (s3Object != null) { + try { + return s3Object.getObjectMetadata().getLastModified().getTime(); + } finally { + s3Object.close(); + } + } + } catch (Exception e) { + LogKit.info("{} not exist!", path); } - return s3Object.getObjectMetadata().getLastModified().getTime(); + + return -1L; } @Override public long length(String path) { - S3Object s3Object = s3.getObject(bucket, path); - if (s3Object == null) { - return -1L; + try { + S3Object s3Object = s3.getObject(bucket, path); + if (s3Object != null) { + try { + return s3Object.getObjectMetadata().getContentLength(); + } finally { + s3Object.close(); + } + } + } catch (Exception e) { + LogKit.info("{} not exist!", path); } - return s3Object.getObjectMetadata().getContentLength(); + + return -1L; } @Override