Author: gnodet
Date: Fri Aug 28 06:40:46 2009
New Revision: 808773
URL: http://svn.apache.org/viewvc?rev=808773&view=rev
Log:
FELIX-1529: The console does not work anymore when connecting to another karaf
instance
Modified:
felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
Modified:
felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
URL:
http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java?rev=808773&r1=808772&r2=808773&view=diff
==============================================================================
---
felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
(original)
+++
felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
Fri Aug 28 06:40:46 2009
@@ -202,29 +202,62 @@
private class ConsoleInputStream extends InputStream
{
- @Override
- public int read() throws IOException
+ private int read(boolean wait) throws IOException
{
- if (!running)
- {
+ if (!running) {
return -1;
}
checkInterrupt();
- int i;
- try {
- i = queue.take();
- }
- catch (InterruptedException e)
- {
- throw new InterruptedIOException();
+ Integer i;
+ if (wait) {
+ try {
+ i = queue.take();
+ } catch (InterruptedException e) {
+ throw new InterruptedIOException();
+ }
+ checkInterrupt();
+ } else {
+ i = queue.poll();
}
- if (i == 4)
- {
+ if (i == null || i == 4) {
return -1;
}
- checkInterrupt();
return i;
}
+
+ @Override
+ public int read() throws IOException
+ {
+ return read(true);
+ }
+
+ @Override
+ public int read(byte b[], int off, int len) throws IOException
+ {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if (off < 0 || len < 0 || len > b.length - off) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ int nb = 1;
+ int i = read(true);
+ if (i < 0) {
+ return -1;
+ }
+ b[off++] = (byte) i;
+ while (nb < len) {
+ i = read(false);
+ if (i < 0) {
+ return nb;
+ }
+ b[off++] = (byte) i;
+ nb++;
+ }
+ return nb;
+ }
}
private class Pipe implements Runnable