Browse Source

Switch FileHeader.extractFileLines to TemporaryBuffer.Heap

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
tags/v3.4.2.201412180340-r
Shawn Pearce 9 years ago
parent
commit
4206ea43b8

+ 1
- 6
org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java View File

final TemporaryBuffer[] tmp = new TemporaryBuffer[getParentCount() + 1]; final TemporaryBuffer[] tmp = new TemporaryBuffer[getParentCount() + 1];
try { try {
for (int i = 0; i < tmp.length; i++) 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()) for (final HunkHeader h : getHunks())
h.extractFileLines(tmp); h.extractFileLines(tmp);


return r; return r;
} catch (IOException ioe) { } catch (IOException ioe) {
throw new RuntimeException(JGitText.get().cannotConvertScriptToText, ioe); throw new RuntimeException(JGitText.get().cannotConvertScriptToText, ioe);
} finally {
for (final TemporaryBuffer b : tmp) {
if (b != null)
b.destroy();
}
} }
} }



+ 4
- 8
org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java View File

} }


private static byte[] readFully(final InputStream is) throws IOException { 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();
} }


/** /**

Loading…
Cancel
Save