From 3f50b813627a593541795fc00cf01536ca0cfb47 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 8 Aug 2013 19:55:15 -0500 Subject: [PATCH] Reorganized IO utils. Added NonBlockingInputStreamReader --- project.properties | 6 +++--- .../io/NonBlockingStreamReader.groovy | 21 +++++++++++++++++++ .../{util => io}/NullOutputStream.java | 5 +++++ .../{util => io}/WrappedPrinter.java | 0 src/main/com/jdbernard/net/HttpContext.groovy | 3 ++- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/main/com/jdbernard/io/NonBlockingStreamReader.groovy rename src/main/com/jdbernard/{util => io}/NullOutputStream.java (64%) rename src/main/com/jdbernard/{util => io}/WrappedPrinter.java (100%) diff --git a/project.properties b/project.properties index 3e06a5c..e7d8533 100644 --- a/project.properties +++ b/project.properties @@ -1,6 +1,6 @@ -#Tue, 27 Nov 2012 08:38:33 -0600 +#Thu, 14 Mar 2013 04:49:38 -0500 name=jdb-util -version=1.8 +version=1.9 lib.local=true -build.number=2 +build.number=1 diff --git a/src/main/com/jdbernard/io/NonBlockingStreamReader.groovy b/src/main/com/jdbernard/io/NonBlockingStreamReader.groovy new file mode 100644 index 0000000..a9d712b --- /dev/null +++ b/src/main/com/jdbernard/io/NonBlockingStreamReader.groovy @@ -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) } +} diff --git a/src/main/com/jdbernard/util/NullOutputStream.java b/src/main/com/jdbernard/io/NullOutputStream.java similarity index 64% rename from src/main/com/jdbernard/util/NullOutputStream.java rename to src/main/com/jdbernard/io/NullOutputStream.java index 59f708f..e270c0a 100644 --- a/src/main/com/jdbernard/util/NullOutputStream.java +++ b/src/main/com/jdbernard/io/NullOutputStream.java @@ -1,7 +1,12 @@ +/** # NullOutputStream + * @author Jonathan Bernard (jdbernard@gmail.com) + * @copyright 2011 Jonathan Bernard + */ package com.jdbernard.util; import java.io.OutputStream; +/** This implementation of OutputStream drops all data sent to it. */ public class NullOutputStream extends OutputStream { public NullOutputStream() {} diff --git a/src/main/com/jdbernard/util/WrappedPrinter.java b/src/main/com/jdbernard/io/WrappedPrinter.java similarity index 100% rename from src/main/com/jdbernard/util/WrappedPrinter.java rename to src/main/com/jdbernard/io/WrappedPrinter.java diff --git a/src/main/com/jdbernard/net/HttpContext.groovy b/src/main/com/jdbernard/net/HttpContext.groovy index 3fa7106..5b1e078 100644 --- a/src/main/com/jdbernard/net/HttpContext.groovy +++ b/src/main/com/jdbernard/net/HttpContext.groovy @@ -1,4 +1,5 @@ -/** @author Jonathan Bernard (jdbernard@gmail.com) +/** # HTTP Context + * @author Jonathan Bernard (jdbernard@gmail.com) * @copyright 2013 Jonathan Bernard. */ package com.jdbernard.net