AmazonS3: Open OutputStream in try-with-resource

Change-Id: I0685a298a0f9fec465973cc718ae3bff373318a4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-02-26 20:38:12 +09:00
parent c2ff87e786
commit 12a589fb57
1 changed files with 5 additions and 10 deletions

View File

@ -402,9 +402,9 @@ public void put(final String bucket, final String key, final byte[] data)
// We have to copy to produce the cipher text anyway so use
// the large object code path as it supports that behavior.
//
final OutputStream os = beginPut(bucket, key, null, null);
os.write(data);
os.close();
try (OutputStream os = beginPut(bucket, key, null, null)) {
os.write(data);
}
return;
}
@ -418,11 +418,8 @@ public void put(final String bucket, final String key, final byte[] data)
authorize(c);
c.setDoOutput(true);
c.setFixedLengthStreamingMode(data.length);
final OutputStream os = c.getOutputStream();
try {
try (OutputStream os = c.getOutputStream()) {
os.write(data);
} finally {
os.close();
}
switch (HttpSupport.response(c)) {
@ -503,12 +500,10 @@ void putImpl(final String bucket, final String key,
authorize(c);
c.setDoOutput(true);
monitor.beginTask(monitorTask, (int) (len / 1024));
final OutputStream os = c.getOutputStream();
try {
try (OutputStream os = c.getOutputStream()) {
buf.writeTo(os, monitor);
} finally {
monitor.endTask();
os.close();
}
switch (HttpSupport.response(c)) {