summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2012-04-06 00:26:06 +0200
committerRobin Rosenberg <robin.rosenberg@dewire.com>2012-04-06 00:26:06 +0200
commit8f9c4ee41d043d97b4dd0944c4ee2e4d387b5d3c (patch)
tree0a213764cb560adbbd1b9d7ebcc8d6af8298e181
parent3f4725c179c176560937d756682fcd6cfbf685fe (diff)
downloadjgit-8f9c4ee41d043d97b4dd0944c4ee2e4d387b5d3c.tar.gz
jgit-8f9c4ee41d043d97b4dd0944c4ee2e4d387b5d3c.zip
Cleanup possiblyFilteredInputStream() in WorkingTreeIterator
Use early return instead of nested if/else Change-Id: I3b5048f9f5cfdfd01f916af550722532db3f9bb3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java55
1 files changed, 26 insertions, 29 deletions
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 955d7d8575..027101bf88 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -335,39 +335,36 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
private InputStream possiblyFilteredInputStream(final Entry e,
final InputStream is, final long len) throws IOException {
- InputStream filteredIs;
if (!mightNeedCleaning()) {
- filteredIs = is;
canonLen = len;
- } else {
- if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) {
- ByteBuffer rawbuf = IO.readWholeStream(is, (int) len);
- byte[] raw = rawbuf.array();
- int n = rawbuf.limit();
- if (!isBinary(raw, n)) {
- rawbuf = filterClean(raw, n);
- raw = rawbuf.array();
- n = rawbuf.limit();
- }
- filteredIs = new ByteArrayInputStream(raw, 0, n);
- canonLen = n;
- } else {
- if (isBinary(e)) {
- filteredIs = is;
- canonLen = len;
- } else {
- final InputStream lenIs = filterClean(e
- .openInputStream());
- try {
- canonLen = computeLength(lenIs);
- } finally {
- safeClose(lenIs);
- }
- filteredIs = filterClean(is);
- }
+ return is;
+ }
+
+ if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) {
+ ByteBuffer rawbuf = IO.readWholeStream(is, (int) len);
+ byte[] raw = rawbuf.array();
+ int n = rawbuf.limit();
+ if (!isBinary(raw, n)) {
+ rawbuf = filterClean(raw, n);
+ raw = rawbuf.array();
+ n = rawbuf.limit();
}
+ canonLen = n;
+ return new ByteArrayInputStream(raw, 0, n);
+ }
+
+ if (isBinary(e)) {
+ canonLen = len;
+ return is;
+ }
+
+ final InputStream lenIs = filterClean(e.openInputStream());
+ try {
+ canonLen = computeLength(lenIs);
+ } finally {
+ safeClose(lenIs);
}
- return filteredIs;
+ return filterClean(is);
}
private static void safeClose(final InputStream in) {