Reorganized IO utils. Added NonBlockingInputStreamReader
This commit is contained in:
parent
db15eb8f88
commit
3f50b81362
@ -1,6 +1,6 @@
|
|||||||
#Tue, 27 Nov 2012 08:38:33 -0600
|
#Thu, 14 Mar 2013 04:49:38 -0500
|
||||||
name=jdb-util
|
name=jdb-util
|
||||||
version=1.8
|
version=1.9
|
||||||
lib.local=true
|
lib.local=true
|
||||||
|
|
||||||
build.number=2
|
build.number=1
|
||||||
|
21
src/main/com/jdbernard/io/NonBlockingStreamReader.groovy
Normal file
21
src/main/com/jdbernard/io/NonBlockingStreamReader.groovy
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.jdbernard.io;
|
||||||
|
|
||||||
|
public class NonBlockingReader implements Runnable {
|
||||||
|
|
||||||
|
private Reader rin
|
||||||
|
private LinkedList buffer = []
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
String line = null
|
||||||
|
try {
|
||||||
|
while((line = rin.readLine()) != null &&
|
||||||
|
!Thread.currentThread().isInterrupted())
|
||||||
|
storeLine(line) }
|
||||||
|
catch (InterruptedException ie) { Thread.currentThread().interrupt() } }
|
||||||
|
|
||||||
|
public synchronized String readLine() { return buffer.poll() }
|
||||||
|
private synchronized void storeLine(String line) { buffer << line }
|
||||||
|
|
||||||
|
public NonBlockingReader(def sin) {
|
||||||
|
this.rin = new InputStreamReader(sin) }
|
||||||
|
}
|
@ -1,7 +1,12 @@
|
|||||||
|
/** # NullOutputStream
|
||||||
|
* @author Jonathan Bernard (jdbernard@gmail.com)
|
||||||
|
* @copyright 2011 Jonathan Bernard
|
||||||
|
*/
|
||||||
package com.jdbernard.util;
|
package com.jdbernard.util;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
/** This implementation of OutputStream drops all data sent to it. */
|
||||||
public class NullOutputStream extends OutputStream {
|
public class NullOutputStream extends OutputStream {
|
||||||
|
|
||||||
public NullOutputStream() {}
|
public NullOutputStream() {}
|
@ -1,4 +1,5 @@
|
|||||||
/** @author Jonathan Bernard (jdbernard@gmail.com)
|
/** # HTTP Context
|
||||||
|
* @author Jonathan Bernard (jdbernard@gmail.com)
|
||||||
* @copyright 2013 Jonathan Bernard. */
|
* @copyright 2013 Jonathan Bernard. */
|
||||||
package com.jdbernard.net
|
package com.jdbernard.net
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user