diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 20:13:51 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 20:13:51 +0900 |
commit | e1c1b80c93658e45c8500c12d7ab12a9af7a2358 (patch) | |
tree | bacb748718a3620c1ce8472c296f44cf31caa177 /org.eclipse.jgit.pgm/src | |
parent | f6dbc7d4728c6ed51157a5f05a332b71ecebae3b (diff) | |
download | jgit-e1c1b80c93658e45c8500c12d7ab12a9af7a2358.tar.gz jgit-e1c1b80c93658e45c8500c12d7ab12a9af7a2358.zip |
AmazonS3Client: Open Input/OutputStream in try-with-resource
Change-Id: I32d4031159dff9005e839d0b53940431cba12beb
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java index 086c9766ac..cce889b76e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java @@ -89,8 +89,7 @@ class AmazonS3Client extends TextBuiltin { if ("get".equals(op)) { //$NON-NLS-1$ final URLConnection c = s3.get(bucket, key); int len = c.getContentLength(); - final InputStream in = c.getInputStream(); - try { + try (InputStream in = c.getInputStream()) { outw.flush(); final byte[] tmp = new byte[2048]; while (len > 0) { @@ -103,8 +102,6 @@ class AmazonS3Client extends TextBuiltin { len -= n; } outs.flush(); - } finally { - in.close(); } } else if ("ls".equals(op) || "list".equals(op)) { //$NON-NLS-1$//$NON-NLS-2$ @@ -115,13 +112,12 @@ class AmazonS3Client extends TextBuiltin { s3.delete(bucket, key); } else if ("put".equals(op)) { //$NON-NLS-1$ - final OutputStream os = s3.beginPut(bucket, key, null, null); - final byte[] tmp = new byte[2048]; - int n; - while ((n = ins.read(tmp)) > 0) - os.write(tmp, 0, n); - os.close(); - + try (OutputStream os = s3.beginPut(bucket, key, null, null)) { + final byte[] tmp = new byte[2048]; + int n; + while ((n = ins.read(tmp)) > 0) + os.write(tmp, 0, n); + } } else { throw die(MessageFormat.format(CLIText.get().unsupportedOperation, op)); } @@ -129,13 +125,10 @@ class AmazonS3Client extends TextBuiltin { private Properties properties() { try { - final InputStream in = new FileInputStream(propertyFile); - try { + try (InputStream in = new FileInputStream(propertyFile)) { final Properties p = new Properties(); p.load(in); return p; - } finally { - in.close(); } } catch (FileNotFoundException e) { throw die(MessageFormat.format(CLIText.get().noSuchFile, propertyFile), e); |