Commit 8ac80386 by Tom Tromey Committed by Tom Tromey

PipedInputStream.java (read(byte[],int,int)): Mostly rewrote.

	* java/io/PipedInputStream.java (read(byte[],int,int)): Mostly
	rewrote.
	(receive): Streamlined.

From-SVN: r35556
parent 320f9548
2000-08-07 Tom Tromey <tromey@cygnus.com>
* java/io/PipedInputStream.java (read(byte[],int,int)): Mostly
rewrote.
(receive): Streamlined.
2000-08-05 Tom Tromey <tromey@cygnus.com> 2000-08-05 Tom Tromey <tromey@cygnus.com>
* java/io/PrintWriter.java: Merged comments from Classpath. * java/io/PrintWriter.java: Merged comments from Classpath.
......
...@@ -285,61 +285,40 @@ read(byte[] buf, int offset, int len) throws IOException ...@@ -285,61 +285,40 @@ read(byte[] buf, int offset, int len) throws IOException
int bytes_read = 0; int bytes_read = 0;
for (;;) for (;;)
{ {
// If there are bytes, take them // If there are bytes, take them.
if (in != -1) if (in != -1)
{ {
int desired_bytes = len - bytes_read; int desired_bytes = len - bytes_read;
// We are in a "wrap" condition // We are in a "wrap" condition.
if (out > in) if (out >= in)
{ {
if (desired_bytes > (pipe_size - out)) desired_bytes = Math.min (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;
if (((out + desired_bytes) == pipe_size) && (in == 0)) System.arraycopy (buffer, out, buf, offset + bytes_read,
desired_bytes = (pipe_size - out) - 1; desired_bytes);
System.arraycopy(buffer, out, buf, offset + bytes_read, bytes_read += desired_bytes;
desired_bytes); out += desired_bytes;
desired_bytes = len - bytes_read;
bytes_read += desired_bytes; if (out == pipe_size)
out += desired_bytes; {
desired_bytes = len - bytes_read; 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) notifyAll();
out = 0;
notifyAll();
}
} }
// We are in a "no wrap" or condition (can also be fall through // We are in a "no wrap". This can be triggered by
// from above // fall-through from the above.
if (in > out) if (in > out)
{ {
if (desired_bytes >= ((in - out) - 1)) desired_bytes = Math.min (desired_bytes, in - out);
desired_bytes = (in - out) - 1;
System.arraycopy(buffer, out, buf, offset + bytes_read, System.arraycopy(buffer, out, buf, offset + bytes_read,
desired_bytes); desired_bytes);
...@@ -348,41 +327,42 @@ read(byte[] buf, int offset, int len) throws IOException ...@@ -348,41 +327,42 @@ read(byte[] buf, int offset, int len) throws IOException
out += desired_bytes; out += desired_bytes;
desired_bytes = len - bytes_read; 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; out = 0;
notifyAll(); notifyAll();
} }
} }
// If we are done, return // Return when we've read something. A short return is ok.
if (bytes_read == len) // Also return in the case where LEN==0.
return(bytes_read); if (bytes_read > 0 || bytes_read == len)
// Return a short count if necessary
if (bytes_read > 0 && bytes_read < len)
return(bytes_read); return(bytes_read);
// Handle the case where the end of stream was encountered. // Handle the case where the end of stream was encountered.
if (closed) if (closed)
{ {
// We never let in == out so there might be one last byte if (in == -1)
// available that we have not copied yet. {
if (in != -1) // The stream is closed and empty. We've already
{ // returned if bytes were read. So we know EOF is the
buf[offset + bytes_read] = buffer[out]; // only answer.
in = -1; return -1;
++out; }
++bytes_read;
} // 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
if (bytes_read != 0) // bytes in the buffer. Still...
return(bytes_read); continue;
else
return(-1);
} }
// Wait for a byte to be read // Wait for a byte to be received.
try try
{ {
wait(); wait();
...@@ -434,33 +414,39 @@ receive(byte[] buf, int offset, int len) throws IOException ...@@ -434,33 +414,39 @@ receive(byte[] buf, int offset, int len) throws IOException
return; return;
int total_written = 0; int total_written = 0;
outer:
while (total_written < len) while (total_written < len)
{ {
// If we are not at the end of the buffer with out = 0 // If the buffer is full, then wait.
if (!((in == (buffer.length - 1)) && (out == 0))) // 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 // This is the "no wrap" situation
if ((in - 1) >= out) if (in > out)
{ {
int bytes_written = 0; int bytes_written = 0;
if ((buffer.length - in) > (len - total_written)) if ((pipe_size - in) > (len - total_written))
bytes_written = (len - total_written); bytes_written = (len - total_written);
else if (out == 0) else if (out == 0)
bytes_written = (buffer.length - in) - 1; bytes_written = (pipe_size - in) - 1;
else else
bytes_written = (buffer.length - in); bytes_written = (pipe_size - in);
if (bytes_written > 0) if (bytes_written > 0)
System.arraycopy(buf, offset + total_written, buffer, in, {
bytes_written); System.arraycopy(buf, offset + total_written, buffer, in,
total_written += bytes_written; bytes_written);
in += bytes_written; total_written += bytes_written;
in += bytes_written;
if (in == buffer.length) if (in == pipe_size)
in = 0; in = 0;
notifyAll(); notifyAll();
}
} }
// This is the "wrap" situtation // This is the "wrap" situtation
if ((out > in) && (total_written != len)) if ((out > in) && (total_written != len))
{ {
...@@ -470,40 +456,20 @@ receive(byte[] buf, int offset, int len) throws IOException ...@@ -470,40 +456,20 @@ receive(byte[] buf, int offset, int len) throws IOException
if (in == -1) if (in == -1)
{ {
in = 0; in = 0;
bytes_written = Math.min (len - total_written, pipe_size);
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;
} }
else else
{ {
bytes_written = len - total_written; bytes_written = Math.min (len - total_written,
} out - in);
}
// If the buffer is full, wait for it to empty out
if ((out - 1) == in)
{
try
{
wait();
}
catch (InterruptedException e)
{
continue;
}
}
System.arraycopy(buf, offset + total_written, buffer, in, System.arraycopy(buf, offset + total_written, buffer, in,
bytes_written); bytes_written);
total_written += bytes_written; total_written += bytes_written;
in += bytes_written; in += bytes_written;
if (in == buffer.length) if (in == pipe_size)
in = 0; in = 0;
notifyAll(); notifyAll();
...@@ -522,4 +488,3 @@ receive(byte[] buf, int offset, int len) throws IOException ...@@ -522,4 +488,3 @@ receive(byte[] buf, int offset, int len) throws IOException
} }
} // class PipedInputStream } // class PipedInputStream
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -253,10 +253,13 @@ public final class Field extends AccessibleObject implements Member ...@@ -253,10 +253,13 @@ public final class Field extends AccessibleObject implements Member
StringBuffer sbuf = new StringBuffer (); StringBuffer sbuf = new StringBuffer ();
int mods = getModifiers(); int mods = getModifiers();
if (mods != 0) if (mods != 0)
Modifier.toString(mods, sbuf); {
Modifier.toString(mods, sbuf);
sbuf.append(' ');
}
sbuf.append(getType()); sbuf.append(getType());
sbuf.append(' '); sbuf.append(' ');
sbuf.append(getDeclaringClass()); sbuf.append(getDeclaringClass().getName());
sbuf.append('.'); sbuf.append('.');
sbuf.append(getName()); sbuf.append(getName());
return sbuf.toString(); return sbuf.toString();
......
...@@ -78,17 +78,17 @@ public final class Method extends AccessibleObject implements Member ...@@ -78,17 +78,17 @@ public final class Method extends AccessibleObject implements Member
getType (); getType ();
StringBuffer b = new StringBuffer (); StringBuffer b = new StringBuffer ();
b.append(Modifier.toString(getModifiers())); Modifier.toString(getModifiers(), b);
b.append(" "); b.append(" ");
b.append(return_type.toString()); b.append(return_type.toString());
b.append(" "); b.append(" ");
b.append(declaringClass.toString()); b.append(declaringClass.getName());
b.append("."); b.append(".");
b.append(name); b.append(name);
b.append("("); b.append("(");
for (int i = 0; i < parameter_types.length; ++i) 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) if (i < parameter_types.length - 1)
b.append(","); b.append(",");
} }
...@@ -98,7 +98,7 @@ public final class Method extends AccessibleObject implements Member ...@@ -98,7 +98,7 @@ public final class Method extends AccessibleObject implements Member
b.append(" throws "); b.append(" throws ");
for (int i = 0; i < exception_types.length; ++i) 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) if (i < exception_types.length - 1)
b.append(","); b.append(",");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment