Author: koen.aers(a)jboss.com
Date: 2011-07-07 09:39:54 -0400 (Thu, 07 Jul 2011)
New Revision: 32710
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ConsoleInputStream.java
Log:
move ConsoleInputStream to org.jboss.tools.forge.core.io
Copied:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ConsoleInputStream.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsoleInputStream.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ConsoleInputStream.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/io/ConsoleInputStream.java 2011-07-07
13:39:54 UTC (rev 32710)
@@ -0,0 +1,66 @@
+package org.jboss.tools.forge.core.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ConsoleInputStream extends InputStream {
+
+ private byte[] input = new byte[0];
+ private int outPointer = 0;
+ private int size = 0;
+ private boolean eofSent = false;
+ private boolean closed = false;
+
+ public synchronized int read() throws IOException {
+ waitForData();
+ if (available() == -1) {
+ return -1;
+ }
+
+ byte b = input[outPointer];
+ outPointer++;
+ if (outPointer == input.length) {
+ outPointer = 0;
+ }
+ size -= 1;
+ return b;
+ }
+
+ private void waitForData() {
+ while (size == 0 && !closed) {
+ try {
+ wait();
+ } catch (InterruptedException e) {}
+ }
+ }
+
+ public synchronized void appendData(String text) {
+ input = text.getBytes();
+ size = text.length();
+ outPointer = 0;
+ notifyAll();
+ }
+
+ public int available() throws IOException {
+ if (closed && eofSent) {
+ throw new IOException("Input Stream Closed");
+ } else if (size == 0) {
+ if (!eofSent) {
+ eofSent = true;
+ return -1;
+ }
+ throw new IOException("Input Stream Closed");
+ }
+
+ return size;
+ }
+
+ public synchronized void close() throws IOException {
+ if(closed) {
+ throw new IOException("Input Stream Closed");
+ }
+ closed = true;
+ notifyAll();
+ }
+
+}
Show replies by date