summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-02-11 18:10:45 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-03-12 16:08:14 -0800
commit2156aa894cefbabd322fc405138c306bb4e939cd (patch)
treed02fd77a9510e41fd90a4aa018c1fa2016163918 /org.eclipse.jgit.junit
parent882d03f70e089bfad2fe2e84f4f9cd69e805e332 (diff)
downloadjgit-2156aa894cefbabd322fc405138c306bb4e939cd.tar.gz
jgit-2156aa894cefbabd322fc405138c306bb4e939cd.zip
Reduce multi-level buffered streams in transport code
Some transports actually provide stream buffering on their own, without needing to be wrapped up inside of a BufferedInputStream in order to smooth out system calls to read or write. A great example of this is the JSch SSH client, or the Apache MINA SSHD server. Both use custom buffering to packetize the streams into the encrypted SSH channel, and wrapping them up inside of a BufferedInputStream or BufferedOutputStream is relatively pointless. Our SideBandOutputStream implementation also provides some fairly large buffering, equal to one complete side-band packet on the main data channel. Wrapping that inside of a BufferedOutputStream just to smooth out small writes from PackWriter causes extra data copies, and provides no advantage. We can save some memory and some CPU cycles by letting PackWriter dump directly into the SideBandOutputStream's internal buffer array. Instead we push the buffering streams down to be as close to the network socket (or operating system pipe) as possible. This allows us to smooth out the smaller reads/writes from pkt-line messages during advertisement and negotation, but avoid copying altogether when the stream switches to larger writes over a side band channel. Change-Id: I2f6f16caee64783c77d3dd1b2a41b3cc0c64c159 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index e738276bd8..59504aa780 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -43,9 +43,11 @@
package org.eclipse.jgit.junit;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
@@ -570,10 +572,10 @@ public class TestRepository {
pw.preparePack(all, Collections.<ObjectId> emptySet());
final ObjectId name = pw.computeName();
- FileOutputStream out;
+ OutputStream out;
final File pack = nameFor(odb, name, ".pack");
- out = new FileOutputStream(pack);
+ out = new BufferedOutputStream(new FileOutputStream(pack));
try {
pw.writePack(out);
} finally {
@@ -582,7 +584,7 @@ public class TestRepository {
pack.setReadOnly();
final File idx = nameFor(odb, name, ".idx");
- out = new FileOutputStream(idx);
+ out = new BufferedOutputStream(new FileOutputStream(idx));
try {
pw.writeIndex(out);
} finally {