Skip to content

Commit

Permalink
Improve S3Client to instantiate default instance dynamically rather t…
Browse files Browse the repository at this point in the history
…han doing it on class load time

Signed-off-by: Benjamin Rögner <benjamin.roegner@here.com>
  • Loading branch information
roegi committed May 14, 2024
1 parent 60a03d8 commit c3f8e58
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.zip.GZIPOutputStream;

public class S3Client {
private static final S3Client instance = new S3Client(Config.instance.JOBS_S3_BUCKET);
private static S3Client instance;
private final String bucketName;
protected static final int PRESIGNED_URL_EXPIRATION_SECONDS = 7 * 24 * 60 * 60;

Expand Down Expand Up @@ -81,6 +81,8 @@ protected S3Client(String bucketName) {
}

public static S3Client getInstance() {
if (instance == null)
instance = new S3Client(Config.instance.JOBS_S3_BUCKET);
return instance;
}

Expand Down Expand Up @@ -160,7 +162,8 @@ public void putObject(String s3Key, String contentType, byte[] content, boolean

client.putObject(new PutObjectRequest(bucketName, s3Key,
new ByteArrayInputStream(baos.toByteArray()), metadata));
} else {
}
else {
metadata.setContentLength(content.length);
client.putObject(new PutObjectRequest(bucketName, s3Key, new ByteArrayInputStream(content), metadata));
}
Expand Down

0 comments on commit c3f8e58

Please sign in to comment.