aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-06 17:23:53 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-06 17:24:29 +0900
commite53edce867a5ff8e2d4e914b5debb74a6e10aec3 (patch)
treeed0442ead3225a3d6ba834d1b044166d5728c179 /org.eclipse.jgit/src/org
parent5f082de9bb4c558775203f06a91e58f2dadd88de (diff)
downloadjgit-e53edce867a5ff8e2d4e914b5debb74a6e10aec3.tar.gz
jgit-e53edce867a5ff8e2d4e914b5debb74a6e10aec3.zip
GC: Open auto-closeable resources in try-with-resource
Change-Id: If437e14636de7c5014ee2aa419d6518acd857792 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java33
1 files changed, 12 insertions, 21 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 56a742d505..92776a6b28 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -1189,27 +1189,21 @@ public class GC {
JGitText.get().cannotCreateIndexfile, tmpIdx.getPath()));
// write the packfile
- FileOutputStream fos = new FileOutputStream(tmpPack);
- FileChannel channel = fos.getChannel();
- OutputStream channelStream = Channels.newOutputStream(channel);
- try {
+ try (FileOutputStream fos = new FileOutputStream(tmpPack);
+ FileChannel channel = fos.getChannel();
+ OutputStream channelStream = Channels
+ .newOutputStream(channel)) {
pw.writePack(pm, pm, channelStream);
- } finally {
channel.force(true);
- channelStream.close();
- fos.close();
}
// write the packindex
- fos = new FileOutputStream(tmpIdx);
- FileChannel idxChannel = fos.getChannel();
- OutputStream idxStream = Channels.newOutputStream(idxChannel);
- try {
+ try (FileOutputStream fos = new FileOutputStream(tmpIdx);
+ FileChannel idxChannel = fos.getChannel();
+ OutputStream idxStream = Channels
+ .newOutputStream(idxChannel)) {
pw.writeIndex(idxStream);
- } finally {
idxChannel.force(true);
- idxStream.close();
- fos.close();
}
if (pw.prepareBitmapIndex(pm)) {
@@ -1221,15 +1215,12 @@ public class GC {
JGitText.get().cannotCreateIndexfile,
tmpBitmapIdx.getPath()));
- fos = new FileOutputStream(tmpBitmapIdx);
- idxChannel = fos.getChannel();
- idxStream = Channels.newOutputStream(idxChannel);
- try {
+ try (FileOutputStream fos = new FileOutputStream(tmpBitmapIdx);
+ FileChannel idxChannel = fos.getChannel();
+ OutputStream idxStream = Channels
+ .newOutputStream(idxChannel)) {
pw.writeBitmapIndex(idxStream);
- } finally {
idxChannel.force(true);
- idxStream.close();
- fos.close();
}
}