aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java10
14 files changed, 34 insertions, 97 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index 79b0efbe6d..f368e836ae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -386,12 +386,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
if (!update.call().isEmpty()) {
SubmoduleWalk walk = SubmoduleWalk.forIndex(clonedRepo);
while (walk.next()) {
- Repository subRepo = walk.getRepository();
- if (subRepo != null) {
- try {
+ try (Repository subRepo = walk.getRepository()) {
+ if (subRepo != null) {
cloneSubmodules(subRepo);
- } finally {
- subRepo.close();
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
index da1ff06ae5..98c16b8931 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -1734,23 +1734,17 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String content)
throws IOException {
File file = new File(parentDir, name);
- FileOutputStream fos = new FileOutputStream(file);
- try {
+ try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
fos.write('\n');
- } finally {
- fos.close();
}
}
private static void appendToFile(File file, String content)
throws IOException {
- FileOutputStream fos = new FileOutputStream(file, true);
- try {
+ try (FileOutputStream fos = new FileOutputStream(file, true)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
fos.write('\n');
- } finally {
- fos.close();
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
index 3495ff8a9d..82c7a4b6c7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
@@ -303,12 +303,9 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
entry.setLastModified(wtIter.getEntryLastModified());
entry.setFileMode(wtIter.getEntryFileMode());
long contentLength = wtIter.getEntryContentLength();
- InputStream in = wtIter.openEntryStream();
- try {
+ try (InputStream in = wtIter.openEntryStream()) {
entry.setObjectId(inserter.insert(
Constants.OBJ_BLOB, contentLength, in));
- } finally {
- in.close();
}
if (indexIter == null && headIter == null)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
index 8b4d2ec8fc..09c0351b80 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
@@ -147,19 +147,13 @@ public class SimilarityIndex {
private void hashLargeObject(ObjectLoader obj) throws IOException,
TableFullException {
- ObjectStream in1 = obj.openStream();
boolean text;
- try {
+ try (ObjectStream in1 = obj.openStream()) {
text = !RawText.isBinary(in1);
- } finally {
- in1.close();
}
- ObjectStream in2 = obj.openStream();
- try {
+ try (ObjectStream in2 = obj.openStream()) {
hash(in2, in2.getSize(), text);
- } finally {
- in2.close();
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
index e827612d23..7ba83c7cbf 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java
@@ -131,18 +131,10 @@ public class RepoProject implements Comparable<RepoProject> {
File srcFile = new File(repo.getWorkTree(),
path + "/" + src); //$NON-NLS-1$
File destFile = new File(repo.getWorkTree(), dest);
- FileInputStream input = new FileInputStream(srcFile);
- try {
- FileOutputStream output = new FileOutputStream(destFile);
- try {
- FileChannel channel = input.getChannel();
- output.getChannel().transferFrom(
- channel, 0, channel.size());
- } finally {
- output.close();
- }
- } finally {
- input.close();
+ try (FileInputStream input = new FileInputStream(srcFile);
+ FileOutputStream output = new FileOutputStream(destFile)) {
+ FileChannel channel = input.getChannel();
+ output.getChannel().transferFrom(channel, 0, channel.size());
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index 7e360421ac..87419c780c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -209,8 +209,7 @@ public final class DfsPackFile extends BlockBasedFile {
try {
ctx.stats.readIdx++;
long start = System.nanoTime();
- ReadableChannel rc = ctx.db.openFile(desc, INDEX);
- try {
+ try (ReadableChannel rc = ctx.db.openFile(desc, INDEX)) {
InputStream in = Channels.newInputStream(rc);
int wantSize = 8192;
int bs = rc.blockSize();
@@ -221,7 +220,6 @@ public final class DfsPackFile extends BlockBasedFile {
idx = PackIndex.read(new BufferedInputStream(in, bs));
ctx.stats.readIdxBytes += rc.position();
} finally {
- rc.close();
ctx.stats.readIdxMicros += elapsedMicros(start);
}
} catch (EOFException e) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
index 5dcba6001a..b5a4d5c3fd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
@@ -429,8 +429,7 @@ public class ObjectDirectoryPackParser extends PackParser {
private void writeIdx() throws IOException {
List<PackedObjectInfo> list = getSortedObjectList(null /* by ObjectId */);
- final FileOutputStream os = new FileOutputStream(tmpIdx);
- try {
+ try (FileOutputStream os = new FileOutputStream(tmpIdx)) {
final PackIndexWriter iw;
if (indexVersion <= 0)
iw = PackIndexWriter.createOldestPossible(os, list);
@@ -438,8 +437,6 @@ public class ObjectDirectoryPackParser extends PackParser {
iw = PackIndexWriter.createVersion(os, indexVersion);
iw.write(list, packHash);
os.getChannel().force(true);
- } finally {
- os.close();
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java
index 432f5a6cd9..64f2a6fc6d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java
@@ -194,8 +194,7 @@ public abstract class ObjectLoader {
if (!isLarge())
return getCachedBytes();
- ObjectStream in = openStream();
- try {
+ try (ObjectStream in = openStream()) {
long sz = in.getSize();
if (sizeLimit < sz)
throw new LargeObjectException.ExceedsLimit(sizeLimit, sz);
@@ -212,8 +211,6 @@ public abstract class ObjectLoader {
IO.readFully(in, buf, 0, buf.length);
return buf;
- } finally {
- in.close();
}
}
@@ -255,8 +252,7 @@ public abstract class ObjectLoader {
public void copyTo(OutputStream out) throws MissingObjectException,
IOException {
if (isLarge()) {
- ObjectStream in = openStream();
- try {
+ try (ObjectStream in = openStream()) {
final long sz = in.getSize();
byte[] tmp = new byte[8192];
long copied = 0;
@@ -269,8 +265,6 @@ public abstract class ObjectLoader {
}
if (0 <= in.read())
throw new EOFException();
- } finally {
- in.close();
}
} else {
out.write(getCachedBytes());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 42ca248459..c43037ea0e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -1946,11 +1946,8 @@ public abstract class Repository implements AutoCloseable {
private void writeCommitMsg(File msgFile, String msg) throws IOException {
if (msg != null) {
- FileOutputStream fos = new FileOutputStream(msgFile);
- try {
+ try (FileOutputStream fos = new FileOutputStream(msgFile)) {
fos.write(msg.getBytes(Constants.CHARACTER_ENCODING));
- } finally {
- fos.close();
}
} else {
FileUtils.delete(msgFile, FileUtils.SKIP_MISSING);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index af5a0b7c98..a487252eef 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -1642,17 +1642,17 @@ public abstract class PackParser {
private void inflateAndSkip(final Source src, final long inflatedSize)
throws IOException {
- final InputStream inf = inflate(src, inflatedSize);
- IO.skipFully(inf, inflatedSize);
- inf.close();
+ try (InputStream inf = inflate(src, inflatedSize)) {
+ IO.skipFully(inf, inflatedSize);
+ }
}
private byte[] inflateAndReturn(final Source src, final long inflatedSize)
throws IOException {
final byte[] dst = new byte[(int) inflatedSize];
- final InputStream inf = inflate(src, inflatedSize);
- IO.readFully(inf, dst, 0, dst.length);
- inf.close();
+ try (InputStream inf = inflate(src, inflatedSize)) {
+ IO.readFully(inf, dst, 0, dst.length);
+ }
return dst;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
index c6191eceb0..ac68ba2fdd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
@@ -339,11 +339,8 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport {
final String s;
String ref = ROOT_DIR + rn;
try {
- final BufferedReader br = openReader(ref);
- try {
+ try (BufferedReader br = openReader(ref)) {
s = br.readLine();
- } finally {
- br.close();
}
} catch (FileNotFoundException noRef) {
return null;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
index 6708964d5e..46fd5cf1d6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
@@ -853,17 +853,12 @@ class WalkFetchConnection extends BaseFetchConnection {
pm.beginTask("Get " + idxName.substring(0, 12) + "..idx", //$NON-NLS-1$ //$NON-NLS-2$
s.length < 0 ? ProgressMonitor.UNKNOWN
: (int) (s.length / 1024));
- try {
- final FileOutputStream fos = new FileOutputStream(tmpIdx);
- try {
- final byte[] buf = new byte[2048];
- int cnt;
- while (!pm.isCancelled() && (cnt = s.in.read(buf)) >= 0) {
- fos.write(buf, 0, cnt);
- pm.update(cnt / 1024);
- }
- } finally {
- fos.close();
+ try (final FileOutputStream fos = new FileOutputStream(tmpIdx)) {
+ final byte[] buf = new byte[2048];
+ int cnt;
+ while (!pm.isCancelled() && (cnt = s.in.read(buf)) >= 0) {
+ fos.write(buf, 0, cnt);
+ pm.update(cnt / 1024);
}
} catch (IOException err) {
FileUtils.delete(tmpIdx);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index 68cc7cb580..bb022e0a92 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -1280,11 +1280,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
IgnoreNode load() throws IOException {
IgnoreNode r = new IgnoreNode();
- InputStream in = entry.openInputStream();
- try {
+ try (InputStream in = entry.openInputStream()) {
r.parse(in);
- } finally {
- in.close();
}
return r.getRules().isEmpty() ? null : r;
}
@@ -1332,11 +1329,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
private static void loadRulesFromFile(IgnoreNode r, File exclude)
throws FileNotFoundException, IOException {
if (FS.DETECTED.exists(exclude)) {
- FileInputStream in = new FileInputStream(exclude);
- try {
+ try (FileInputStream in = new FileInputStream(exclude)) {
r.parse(in);
- } finally {
- in.close();
}
}
}
@@ -1353,11 +1347,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
AttributesNode load() throws IOException {
AttributesNode r = new AttributesNode();
- InputStream in = entry.openInputStream();
- try {
+ try (InputStream in = entry.openInputStream()) {
r.parse(in);
- } finally {
- in.close();
}
return r.getRules().isEmpty() ? null : r;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
index dd933a0294..887f69b87c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
@@ -487,11 +487,8 @@ public abstract class TemporaryBuffer extends OutputStream {
if (Integer.MAX_VALUE < len)
throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize);
final byte[] out = new byte[(int) len];
- final FileInputStream in = new FileInputStream(onDiskFile);
- try {
+ try (FileInputStream in = new FileInputStream(onDiskFile)) {
IO.readFully(in, out, 0, (int) len);
- } finally {
- in.close();
}
return out;
}
@@ -505,16 +502,13 @@ public abstract class TemporaryBuffer extends OutputStream {
}
if (pm == null)
pm = NullProgressMonitor.INSTANCE;
- final FileInputStream in = new FileInputStream(onDiskFile);
- try {
+ try (FileInputStream in = new FileInputStream(onDiskFile)) {
int cnt;
final byte[] buf = new byte[Block.SZ];
while ((cnt = in.read(buf)) >= 0) {
os.write(buf, 0, cnt);
pm.update(cnt / 1024);
}
- } finally {
- in.close();
}
}