-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the high latency which results when using a PipedWriter/PipedOu…
…tputStream and not flushing it after every write See http://stackoverflow.com/questions/2843555/better-alternative-for-pipedreader-pipedwriter/2844689#2844689
- Loading branch information
Showing
4 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...-end-test/src/test/java/net/orfjackal/dimdwarf/test/util/LowLatencyPipedOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2008-2010 Esko Luontola <www.orfjackal.net> | ||
// This software is released under the Apache License 2.0. | ||
// The license text is at http://dimdwarf.sourceforge.net/LICENSE | ||
|
||
package net.orfjackal.dimdwarf.test.util; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* {@link java.io.PipedOutputStream} should be flushed after every write, or otherwise | ||
* there will be a one-second latency for the reader. This class does that automatically. | ||
* <a href="http://stackoverflow.com/questions/2843555/better-alternative-for-pipedreader-pipedwriter/2844689#2844689">More information</a>. | ||
*/ | ||
public class LowLatencyPipedOutputStream extends PipedOutputStream { | ||
|
||
public LowLatencyPipedOutputStream(PipedInputStream snk) throws IOException { | ||
super(snk); | ||
} | ||
|
||
public LowLatencyPipedOutputStream() { | ||
} | ||
|
||
public void write(int b) throws IOException { | ||
super.write(b); | ||
flush(); | ||
} | ||
|
||
public void write(byte[] b, int off, int len) throws IOException { | ||
super.write(b, off, len); | ||
flush(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...end-to-end-test/src/test/java/net/orfjackal/dimdwarf/test/util/LowLatencyPipedWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2008-2010 Esko Luontola <www.orfjackal.net> | ||
// This software is released under the Apache License 2.0. | ||
// The license text is at http://dimdwarf.sourceforge.net/LICENSE | ||
|
||
package net.orfjackal.dimdwarf.test.util; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* {@link java.io.PipedWriter} should be flushed after every write, or otherwise | ||
* there will be a one-second latency for the reader. This class does that automatically. | ||
* <a href="http://stackoverflow.com/questions/2843555/better-alternative-for-pipedreader-pipedwriter/2844689#2844689">More information</a>. | ||
*/ | ||
public class LowLatencyPipedWriter extends PipedWriter { | ||
|
||
public LowLatencyPipedWriter(PipedReader snk) throws IOException { | ||
super(snk); | ||
} | ||
|
||
public LowLatencyPipedWriter() { | ||
} | ||
|
||
public void write(int c) throws IOException { | ||
super.write(c); | ||
flush(); | ||
} | ||
|
||
public void write(char[] cbuf, int off, int len) throws IOException { | ||
super.write(cbuf, off, len); | ||
flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters