AmazonS3Client: Open Input/OutputStream in try-with-resource
Change-Id: I32d4031159dff9005e839d0b53940431cba12beb Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
f6dbc7d472
commit
e1c1b80c93
|
@ -89,8 +89,7 @@ protected void run() throws Exception {
|
||||||
if ("get".equals(op)) { //$NON-NLS-1$
|
if ("get".equals(op)) { //$NON-NLS-1$
|
||||||
final URLConnection c = s3.get(bucket, key);
|
final URLConnection c = s3.get(bucket, key);
|
||||||
int len = c.getContentLength();
|
int len = c.getContentLength();
|
||||||
final InputStream in = c.getInputStream();
|
try (InputStream in = c.getInputStream()) {
|
||||||
try {
|
|
||||||
outw.flush();
|
outw.flush();
|
||||||
final byte[] tmp = new byte[2048];
|
final byte[] tmp = new byte[2048];
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
@ -103,8 +102,6 @@ protected void run() throws Exception {
|
||||||
len -= n;
|
len -= n;
|
||||||
}
|
}
|
||||||
outs.flush();
|
outs.flush();
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("ls".equals(op) || "list".equals(op)) { //$NON-NLS-1$//$NON-NLS-2$
|
} else if ("ls".equals(op) || "list".equals(op)) { //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
@ -115,13 +112,12 @@ protected void run() throws Exception {
|
||||||
s3.delete(bucket, key);
|
s3.delete(bucket, key);
|
||||||
|
|
||||||
} else if ("put".equals(op)) { //$NON-NLS-1$
|
} else if ("put".equals(op)) { //$NON-NLS-1$
|
||||||
final OutputStream os = s3.beginPut(bucket, key, null, null);
|
try (OutputStream os = s3.beginPut(bucket, key, null, null)) {
|
||||||
final byte[] tmp = new byte[2048];
|
final byte[] tmp = new byte[2048];
|
||||||
int n;
|
int n;
|
||||||
while ((n = ins.read(tmp)) > 0)
|
while ((n = ins.read(tmp)) > 0)
|
||||||
os.write(tmp, 0, n);
|
os.write(tmp, 0, n);
|
||||||
os.close();
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw die(MessageFormat.format(CLIText.get().unsupportedOperation, op));
|
throw die(MessageFormat.format(CLIText.get().unsupportedOperation, op));
|
||||||
}
|
}
|
||||||
|
@ -129,13 +125,10 @@ protected void run() throws Exception {
|
||||||
|
|
||||||
private Properties properties() {
|
private Properties properties() {
|
||||||
try {
|
try {
|
||||||
final InputStream in = new FileInputStream(propertyFile);
|
try (InputStream in = new FileInputStream(propertyFile)) {
|
||||||
try {
|
|
||||||
final Properties p = new Properties();
|
final Properties p = new Properties();
|
||||||
p.load(in);
|
p.load(in);
|
||||||
return p;
|
return p;
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw die(MessageFormat.format(CLIText.get().noSuchFile, propertyFile), e);
|
throw die(MessageFormat.format(CLIText.get().noSuchFile, propertyFile), e);
|
||||||
|
|
Loading…
Reference in New Issue