diff options
author | Tom Tromey <tromey@cygnus.com> | 2000-08-07 19:59:48 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2000-08-07 19:59:48 +0000 |
commit | 8ac80386cab58a0bf055924baf58ec1b28c0e6e9 (patch) | |
tree | 6fb33f433f640ace30f10253c268911edf522165 /libjava/java | |
parent | 320f95489d1a822d0b67fa63aa5691d70cd3ae0d (diff) | |
download | gcc-8ac80386cab58a0bf055924baf58ec1b28c0e6e9.zip gcc-8ac80386cab58a0bf055924baf58ec1b28c0e6e9.tar.gz gcc-8ac80386cab58a0bf055924baf58ec1b28c0e6e9.tar.bz2 |
PipedInputStream.java (read(byte[],int,int)): Mostly rewrote.
* java/io/PipedInputStream.java (read(byte[],int,int)): Mostly
rewrote.
(receive): Streamlined.
From-SVN: r35556
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/io/PipedInputStream.java | 175 | ||||
-rw-r--r-- | libjava/java/lang/reflect/Field.java | 9 | ||||
-rw-r--r-- | libjava/java/lang/reflect/Method.java | 8 |
3 files changed, 80 insertions, 112 deletions
diff --git a/libjava/java/io/PipedInputStream.java b/libjava/java/io/PipedInputStream.java index e25f163..b5c7931 100644 --- a/libjava/java/io/PipedInputStream.java +++ b/libjava/java/io/PipedInputStream.java @@ -285,61 +285,40 @@ read(byte[] buf, int offset, int len) throws IOException int bytes_read = 0; for (;;) { - // If there are bytes, take them + // If there are bytes, take them. if (in != -1) { int desired_bytes = len - bytes_read; - // We are in a "wrap" condition - if (out > in) + // We are in a "wrap" condition. + if (out >= in) { - if (desired_bytes > (pipe_size - out)) - { - if (in == 0) - desired_bytes = (pipe_size - out) - 1; - else - desired_bytes = pipe_size - out; - - System.arraycopy(buffer, out, buf, offset + bytes_read, - desired_bytes); - - bytes_read += desired_bytes; - out += desired_bytes; - desired_bytes = len - bytes_read; - - if (out == pipe_size) - out = 0; - - notifyAll(); - } - else - { - if ((out + desired_bytes) == in) - --desired_bytes; + desired_bytes = Math.min (desired_bytes, pipe_size - out); - if (((out + desired_bytes) == pipe_size) && (in == 0)) - desired_bytes = (pipe_size - out) - 1; + System.arraycopy (buffer, out, buf, offset + bytes_read, + desired_bytes); - System.arraycopy(buffer, out, buf, offset + bytes_read, - desired_bytes); + bytes_read += desired_bytes; + out += desired_bytes; + desired_bytes = len - bytes_read; - bytes_read += desired_bytes; - out += desired_bytes; - desired_bytes = len - bytes_read; + if (out == pipe_size) + { + out = 0; + // OUT has wrapped. Make sure that we don't falsely + // indicate that the buffer is full. + if (in == 0) + in = -1; + } - if (out == pipe_size) - out = 0; - - notifyAll(); - } + notifyAll(); } - - // We are in a "no wrap" or condition (can also be fall through - // from above + + // We are in a "no wrap". This can be triggered by + // fall-through from the above. if (in > out) { - if (desired_bytes >= ((in - out) - 1)) - desired_bytes = (in - out) - 1; + desired_bytes = Math.min (desired_bytes, in - out); System.arraycopy(buffer, out, buf, offset + bytes_read, desired_bytes); @@ -348,41 +327,42 @@ read(byte[] buf, int offset, int len) throws IOException out += desired_bytes; desired_bytes = len - bytes_read; - if (out == pipe_size) + if (out == in) + { + // Don't falsely indicate that the buffer is full. + out = 0; + in = -1; + } + else if (out == pipe_size) out = 0; notifyAll(); } } - // If we are done, return - if (bytes_read == len) - return(bytes_read); - - // Return a short count if necessary - if (bytes_read > 0 && bytes_read < len) + // Return when we've read something. A short return is ok. + // Also return in the case where LEN==0. + if (bytes_read > 0 || bytes_read == len) return(bytes_read); // Handle the case where the end of stream was encountered. if (closed) { - // We never let in == out so there might be one last byte - // available that we have not copied yet. - if (in != -1) - { - buf[offset + bytes_read] = buffer[out]; - in = -1; - ++out; - ++bytes_read; - } - - if (bytes_read != 0) - return(bytes_read); - else - return(-1); + if (in == -1) + { + // The stream is closed and empty. We've already + // returned if bytes were read. So we know EOF is the + // only answer. + return -1; + } + + // I think this shouldn't happen. I don't think there is a + // way to get here when nothing has been read but there are + // bytes in the buffer. Still... + continue; } - // Wait for a byte to be read + // Wait for a byte to be received. try { wait(); @@ -434,33 +414,39 @@ receive(byte[] buf, int offset, int len) throws IOException return; int total_written = 0; + outer: while (total_written < len) { - // If we are not at the end of the buffer with out = 0 - if (!((in == (buffer.length - 1)) && (out == 0))) + // If the buffer is full, then wait. + // Also, if we are at the end of the buffer and OUT is 0, wait. + if (! (in == out + || (in == pipe_size - 1 && out == 0))) { // This is the "no wrap" situation - if ((in - 1) >= out) + if (in > out) { int bytes_written = 0; - if ((buffer.length - in) > (len - total_written)) + if ((pipe_size - in) > (len - total_written)) bytes_written = (len - total_written); else if (out == 0) - bytes_written = (buffer.length - in) - 1; + bytes_written = (pipe_size - in) - 1; else - bytes_written = (buffer.length - in); + bytes_written = (pipe_size - in); if (bytes_written > 0) - System.arraycopy(buf, offset + total_written, buffer, in, - bytes_written); - total_written += bytes_written; - in += bytes_written; + { + System.arraycopy(buf, offset + total_written, buffer, in, + bytes_written); + total_written += bytes_written; + in += bytes_written; - if (in == buffer.length) - in = 0; + if (in == pipe_size) + in = 0; - notifyAll(); + notifyAll(); + } } + // This is the "wrap" situtation if ((out > in) && (total_written != len)) { @@ -470,40 +456,20 @@ receive(byte[] buf, int offset, int len) throws IOException if (in == -1) { in = 0; - - if (buffer.length > len) - bytes_written = len; - else - bytes_written = buffer.length - 1; - } - else if (((out - in) - 1) < (len - total_written)) - { - bytes_written = (out - in) - 1; + bytes_written = Math.min (len - total_written, pipe_size); } else - { - bytes_written = len - total_written; - } - - // If the buffer is full, wait for it to empty out - if ((out - 1) == in) - { - try - { - wait(); - } - catch (InterruptedException e) - { - continue; - } - } + { + bytes_written = Math.min (len - total_written, + out - in); + } System.arraycopy(buf, offset + total_written, buffer, in, bytes_written); total_written += bytes_written; in += bytes_written; - if (in == buffer.length) + if (in == pipe_size) in = 0; notifyAll(); @@ -522,4 +488,3 @@ receive(byte[] buf, int offset, int len) throws IOException } } // class PipedInputStream - diff --git a/libjava/java/lang/reflect/Field.java b/libjava/java/lang/reflect/Field.java index d0d4164..768194d 100644 --- a/libjava/java/lang/reflect/Field.java +++ b/libjava/java/lang/reflect/Field.java @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000 Free Software Foundation This file is part of libgcj. @@ -253,10 +253,13 @@ public final class Field extends AccessibleObject implements Member StringBuffer sbuf = new StringBuffer (); int mods = getModifiers(); if (mods != 0) - Modifier.toString(mods, sbuf); + { + Modifier.toString(mods, sbuf); + sbuf.append(' '); + } sbuf.append(getType()); sbuf.append(' '); - sbuf.append(getDeclaringClass()); + sbuf.append(getDeclaringClass().getName()); sbuf.append('.'); sbuf.append(getName()); return sbuf.toString(); diff --git a/libjava/java/lang/reflect/Method.java b/libjava/java/lang/reflect/Method.java index beefbe7..f7a9794 100644 --- a/libjava/java/lang/reflect/Method.java +++ b/libjava/java/lang/reflect/Method.java @@ -78,17 +78,17 @@ public final class Method extends AccessibleObject implements Member getType (); StringBuffer b = new StringBuffer (); - b.append(Modifier.toString(getModifiers())); + Modifier.toString(getModifiers(), b); b.append(" "); b.append(return_type.toString()); b.append(" "); - b.append(declaringClass.toString()); + b.append(declaringClass.getName()); b.append("."); b.append(name); b.append("("); for (int i = 0; i < parameter_types.length; ++i) { - b.append(parameter_types[i].toString()); + b.append(parameter_types[i].getName()); if (i < parameter_types.length - 1) b.append(","); } @@ -98,7 +98,7 @@ public final class Method extends AccessibleObject implements Member b.append(" throws "); for (int i = 0; i < exception_types.length; ++i) { - b.append(exception_types[i].toString()); + b.append(exception_types[i].getName()); if (i < exception_types.length - 1) b.append(","); } |