]> source.dussan.org Git - jgit.git/commitdiff
Buffer overflow output stream 67/45067/1
authorShawn Pearce <spearce@spearce.org>
Wed, 1 Apr 2015 19:59:33 +0000 (12:59 -0700)
committerShawn Pearce <spearce@spearce.org>
Wed, 1 Apr 2015 20:02:09 +0000 (13:02 -0700)
Most callers/users of TemporaryBuffer are sizing the in-memory
portion large enough that most outputs fit into RAM. With this
assumption they don't pay close attention to the size of IOs
being written, as it "should" just be a copy from one byte array
to another.

Overflow sets up a local file handle, which is costly to write to
for small IO units. Wrap the local file in a BufferedOutputStream
to combine small writes together. Larger writes can still bypass the
buffer as BOS automatically avoids copying for larger writes.

Change-Id: I09f4136dd65c48830cfda86d9101bc647581018a

org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java

index 006c3c0a0102d0a634851ff3c751f5f50a5c5229..3719bf794966fe9bedffe75a90423fab89d27dec 100644 (file)
@@ -44,6 +44,7 @@
 
 package org.eclipse.jgit.util;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -435,7 +436,7 @@ public abstract class TemporaryBuffer extends OutputStream {
 
                protected OutputStream overflow() throws IOException {
                        onDiskFile = File.createTempFile("jgit_", ".buf", directory); //$NON-NLS-1$ //$NON-NLS-2$
-                       return new FileOutputStream(onDiskFile);
+                       return new BufferedOutputStream(new FileOutputStream(onDiskFile));
                }
 
                public long length() {