Skip to content

Commit 5ecd16f

Browse files
committed
[opt] set position 0 when object not exist
1 parent 1c73e1e commit 5ecd16f

File tree

1 file changed

+12
-11
lines changed
  • aws/aws-sink/src/main/java/com/dtstack/flink/sql/sink/aws/util

1 file changed

+12
-11
lines changed

aws/aws-sink/src/main/java/com/dtstack/flink/sql/sink/aws/util/AwsManager.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ public static AmazonS3Client initClient(String accessKey,
6969
return client;
7070
}
7171

72-
/**
73-
* 关闭s3 客户端
74-
*
75-
* @param client s3 client
76-
*/
77-
public static void closeClient(AmazonS3Client client) {
78-
if (Objects.nonNull(client)) {
79-
client.shutdown();
80-
}
81-
}
82-
8372
/**
8473
* 创建bucket
8574
*
@@ -150,7 +139,19 @@ public static void setBucketAccessControl(AmazonS3Client client,
150139
client.setBucketAcl(request);
151140
}
152141

142+
/**
143+
* 获取当前 Object 字节位数,如果 Object 不存在,那么返回 0
144+
*
145+
* @param bucket bucket
146+
* @param objectName object name
147+
* @param client client
148+
* @return object bytes 位数
149+
*/
153150
public static long getObjectPosition(String bucket, String objectName, AmazonS3Client client) {
151+
if (!client.doesObjectExist(bucket, objectName)) {
152+
return 0;
153+
}
154+
154155
S3Object object = client.getObject(bucket, objectName);
155156
ObjectMetadata objectMetadata = object.getObjectMetadata();
156157
return objectMetadata.getContentLength();

0 commit comments

Comments
 (0)