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