]> source.dussan.org Git - jgit.git/commitdiff
Switch FileHeader.extractFileLines to TemporaryBuffer.Heap 30/37030/1
authorShawn Pearce <sop@google.com>
Tue, 25 Nov 2014 17:58:45 +0000 (09:58 -0800)
committerShawn Pearce <sop@google.com>
Tue, 25 Nov 2014 18:21:48 +0000 (10:21 -0800)
File contents are processed into a single byte[] for character
conversion. The data must fit entirely in memory, so avoid any
file IO.

Change-Id: I3fe8be2e5f37d5ae953596dda1ed3fe6d4f6aebc

org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java
org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java

index 8171669bc8c07c3af7fb88554d2d5f4424eb510b..534c8273140c62b41f537161a0eedb61cd0c84f5 100644 (file)
@@ -267,7 +267,7 @@ public class FileHeader extends DiffEntry {
                final TemporaryBuffer[] tmp = new TemporaryBuffer[getParentCount() + 1];
                try {
                        for (int i = 0; i < tmp.length; i++)
-                               tmp[i] = new TemporaryBuffer.LocalFile();
+                               tmp[i] = new TemporaryBuffer.Heap(Integer.MAX_VALUE);
                        for (final HunkHeader h : getHunks())
                                h.extractFileLines(tmp);
 
@@ -281,11 +281,6 @@ public class FileHeader extends DiffEntry {
                        return r;
                } catch (IOException ioe) {
                        throw new RuntimeException(JGitText.get().cannotConvertScriptToText, ioe);
-               } finally {
-                       for (final TemporaryBuffer b : tmp) {
-                               if (b != null)
-                                       b.destroy();
-                       }
                }
        }
 
index 7b48473523094291c75f77872db0f3794bc17385..383c1f8fef61cfec098bd81df3ac5b9e4fe7fc92 100644 (file)
@@ -139,14 +139,10 @@ public class Patch {
        }
 
        private static byte[] readFully(final InputStream is) throws IOException {
-               final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
-               try {
-                       b.copy(is);
-                       b.close();
-                       return b.toByteArray();
-               } finally {
-                       b.destroy();
-               }
+               TemporaryBuffer b = new TemporaryBuffer.Heap(Integer.MAX_VALUE);
+               b.copy(is);
+               b.close();
+               return b.toByteArray();
        }
 
        /**