Skip to content
Snippets Groups Projects
Commit 07c06cfb authored by ivan's avatar ivan
Browse files

[s3] added try-with-resources

parent 66127813
No related branches found
No related tags found
No related merge requests found
......@@ -336,28 +336,26 @@ public class S3Client extends DB {
System.arraycopy(sourceArray, 0, destinationArray, offset, sizeArray);
offset += sizeArray;
}
InputStream input = new ByteArrayInputStream(destinationArray);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(totalSize);
try {
PutObjectResult res =
s3Client.putObject(bucket, key, input, metadata);
if(res.getETag() == null) {
return 1;
}
} catch (Exception e) {
System.err.println("Not possible to write object :"+key);
e.printStackTrace();
return 1;
} finally {
try (InputStream input = new ByteArrayInputStream(destinationArray)) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(totalSize);
try {
input.close();
PutObjectResult res =
s3Client.putObject(bucket, key, input, metadata);
if(res.getETag() == null) {
return 1;
}
} catch (Exception e) {
System.err.println("Not possible to close the stream :"+e.toString());
System.err.println("Not possible to write object :"+key);
e.printStackTrace();
return 1;
} finally {
return 0;
}
return 0;
} catch (Exception e) {
System.err.println("Error in the creation of the stream :"+e.toString());
e.printStackTrace();
return 1;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment