aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/io/DataInputStream.java
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@albatross.co.nz>1999-06-09 17:42:26 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>1999-06-09 18:42:26 +0100
commit1e45a14105a4d5a218af2e718b58858f846c3f70 (patch)
treecfcc17dc0b0ed3f23921fd3008f2b30835bad356 /libjava/java/io/DataInputStream.java
parent8d30c4ee0138e22442da8564c3a952a9ea708435 (diff)
downloadgcc-1e45a14105a4d5a218af2e718b58858f846c3f70.zip
gcc-1e45a14105a4d5a218af2e718b58858f846c3f70.tar.gz
gcc-1e45a14105a4d5a218af2e718b58858f846c3f70.tar.bz2
Runtime.java (exec): Convert prog name and arguments to string array.
* java/lang/Runtime.java (exec): Convert prog name and arguments to string array. * java/lang/natPosixProcess.cc (startProcess): Fix typo in environment array conversion. Preserve current environment if envp not passed. Preserve PATH unless explicitly specified. * java/io/DataInputStream.java (readLine): Fix case where '\r' is followed by EOF. Set a flag when a line is terminated by '\r' and ignore following '\n' if set. From-SVN: r27458
Diffstat (limited to 'libjava/java/io/DataInputStream.java')
-rw-r--r--libjava/java/io/DataInputStream.java67
1 files changed, 52 insertions, 15 deletions
diff --git a/libjava/java/io/DataInputStream.java b/libjava/java/io/DataInputStream.java
index d03f8f4..bbcf1da 100644
--- a/libjava/java/io/DataInputStream.java
+++ b/libjava/java/io/DataInputStream.java
@@ -21,6 +21,11 @@ package java.io;
public class DataInputStream extends FilterInputStream implements DataInput
{
+ // readLine() hack to ensure that an '\r' not followed by an '\n' is
+ // handled correctly. If set, readLine() will ignore the first char it sees
+ // if that char is a '\n'
+ boolean ignoreInitialNewline = false;
+
public DataInputStream(InputStream in)
{
super(in);
@@ -103,14 +108,29 @@ public class DataInputStream extends FilterInputStream implements DataInput
{
StringBuffer strb = new StringBuffer();
- while (true)
+ readloop: while (true)
{
- int c = read();
- if (c < 0) // got an EOF
- return strb.length() > 0 ? strb.toString() : null;
- char ch = (char) c;
- if ((ch &= 0xFF) == '\n')
- break;
+ int c = 0;
+ char ch = ' ';
+ boolean getnext = true;
+ while (getnext)
+ {
+ getnext = false;
+ c = read();
+ if (c < 0) // got an EOF
+ return strb.length() > 0 ? strb.toString() : null;
+ ch = (char) c;
+ if ((ch &= 0xFF) == '\n')
+ // hack to correctly handle '\r\n' sequences
+ if (ignoreInitialNewline)
+ {
+ ignoreInitialNewline = false;
+ getnext = true;
+ }
+ else
+ break readloop;
+ }
+
if (ch == '\r')
{
// FIXME: The following code tries to adjust the stream back one
@@ -134,18 +154,35 @@ public class DataInputStream extends FilterInputStream implements DataInput
// and since it is undesirable to make non-deprecated methods
// less efficient, the following seems like the most reasonable
// approach.
- if (in instanceof BufferedInputStream && (read() & 0xFF) != '\n')
+ int next_c = 0;
+ char next_ch = ' ';
+ if (in instanceof BufferedInputStream)
{
- BufferedInputStream bin = (BufferedInputStream) in;
- if (bin.pos > 0)
- bin.pos--;
+ next_c = read();
+ next_ch = (char) (next_c & 0xFF);
+ if ((next_ch != '\n') && (next_c >= 0))
+ {
+ BufferedInputStream bin = (BufferedInputStream) in;
+ if (bin.pos > 0)
+ bin.pos--;
+ }
}
else if (markSupported())
{
- mark(1);
- if ((read() & 0xFF) != '\n')
- reset();
- }
+ next_c = read();
+ next_ch = (char) (next_c & 0xFF);
+ if ((next_ch != '\n') && (next_c >= 0))
+ {
+ mark(1);
+ if ((read() & 0xFF) != '\n')
+ reset();
+ }
+ }
+ // In order to catch cases where 'in' isn't a BufferedInputStream
+ // and doesn't support mark() (such as reading from a Socket), set
+ // a flag that instructs readLine() to ignore the first character
+ // it sees _if_ that character is a '\n'.
+ else ignoreInitialNewline = true;
break;
}
strb.append(ch);