]> source.dussan.org Git - jgit.git/commitdiff
Cleanup possiblyFilteredInputStream() in WorkingTreeIterator 39/5539/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 5 Apr 2012 22:26:06 +0000 (00:26 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 5 Apr 2012 22:26:06 +0000 (00:26 +0200)
Use early return instead of nested if/else

Change-Id: I3b5048f9f5cfdfd01f916af550722532db3f9bb3

org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

index 955d7d857518588605c46ac0183537b62b210455..027101bf881eff8925a34364e5551e65093b444e 100644 (file)
@@ -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) {