From d94ce9c754b740defbd75230663d323f64cc9648 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 1 Apr 2015 12:59:33 -0700 Subject: [PATCH] Buffer overflow output stream 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 --- .../src/org/eclipse/jgit/util/TemporaryBuffer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java index 006c3c0a0..3719bf794 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java @@ -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 LocalFile(final File directory, final int inCoreLimit) { 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() {