summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2020-06-05 14:59:54 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2020-06-05 14:59:54 +0900
commitc0c7f445f4e8daf2900f8735b088edb2288882b0 (patch)
tree1469b02c0be19bc81e66d38cbe38f9ddc3df69ca /org.eclipse.jgit
parentf4f5d448b691c06688cb3636dc2294308b1a433f (diff)
downloadjgit-c0c7f445f4e8daf2900f8735b088edb2288882b0.tar.gz
jgit-c0c7f445f4e8daf2900f8735b088edb2288882b0.zip
ObjectDirectoryInserter: Open FileOutputStream in try-with-resource
Change-Id: Icc569aeefdc79baee5dfb71fb34d881c561dcf52 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java32
1 files changed, 16 insertions, 16 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java
index 2d2401b5b4..e6b2cc12f4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java
@@ -162,17 +162,16 @@ class ObjectDirectoryInserter extends ObjectInserter {
}
}
- @SuppressWarnings("resource" /* java 7 */)
private File toTemp(final SHA1 md, final int type, long len,
final InputStream is) throws IOException {
boolean delete = true;
File tmp = newTempFile();
- try {
- FileOutputStream fOut = new FileOutputStream(tmp);
+ try (FileOutputStream fOut = new FileOutputStream(tmp)) {
try {
OutputStream out = fOut;
- if (config.getFSyncObjectFiles())
+ if (config.getFSyncObjectFiles()) {
out = Channels.newOutputStream(fOut.getChannel());
+ }
DeflaterOutputStream cOut = compress(out);
SHA1OutputStream dOut = new SHA1OutputStream(cOut, md);
writeHeader(dOut, type, len);
@@ -180,53 +179,54 @@ class ObjectDirectoryInserter extends ObjectInserter {
final byte[] buf = buffer();
while (len > 0) {
int n = is.read(buf, 0, (int) Math.min(len, buf.length));
- if (n <= 0)
+ if (n <= 0) {
throw shortInput(len);
+ }
dOut.write(buf, 0, n);
len -= n;
}
dOut.flush();
cOut.finish();
} finally {
- if (config.getFSyncObjectFiles())
+ if (config.getFSyncObjectFiles()) {
fOut.getChannel().force(true);
- fOut.close();
+ }
}
delete = false;
return tmp;
} finally {
- if (delete)
+ if (delete) {
FileUtils.delete(tmp, FileUtils.RETRY);
+ }
}
}
- @SuppressWarnings("resource" /* java 7 */)
private File toTemp(final int type, final byte[] buf, final int pos,
final int len) throws IOException {
boolean delete = true;
File tmp = newTempFile();
- try {
- FileOutputStream fOut = new FileOutputStream(tmp);
+ try (FileOutputStream fOut = new FileOutputStream(tmp)) {
try {
OutputStream out = fOut;
- if (config.getFSyncObjectFiles())
+ if (config.getFSyncObjectFiles()) {
out = Channels.newOutputStream(fOut.getChannel());
+ }
DeflaterOutputStream cOut = compress(out);
writeHeader(cOut, type, len);
cOut.write(buf, pos, len);
cOut.finish();
} finally {
- if (config.getFSyncObjectFiles())
+ if (config.getFSyncObjectFiles()) {
fOut.getChannel().force(true);
- fOut.close();
+ }
}
-
delete = false;
return tmp;
} finally {
- if (delete)
+ if (delete) {
FileUtils.delete(tmp, FileUtils.RETRY);
+ }
}
}