--- kaffe/libraries/javalib/java/io/DataInputStream.java	Wed Sep  4 06:21:52 2002
+++ patched-kaffe/libraries/javalib/java/io/DataInputStream.java	Wed Oct 23 12:05:49 2002
@@ -17,7 +17,7 @@
 	private boolean skipNextLF;
 
 public DataInputStream(InputStream in) {
-	super(in);
+	super(new PushbackInputStream(in));
 }
 
 public final int read(byte b[]) throws IOException {
@@ -101,7 +101,34 @@
 				break;
 			}
 			if (ch == '\r') {
-				skipNextLF = true;
+				/* Since not all streams support marking
+				   and resetting, the underlying stream is
+				   wrapped in a PushbackInputStream. If
+				   there are bytes available for reading,
+				   we use its read() and unread() methods
+				   to skip the eventual '\n' character.
+
+				   Making sure bytes are available before
+				   reading should prevent hanging on a socket.
+
+				   The alternative method is to	set a
+				   skipNextLF flag. If the user switches to
+				   another InputStream using the underlying
+				   stream, as she might have to deal with a
+				   '\n' character that should have been
+				   skipped.
+				*/
+				if (available() > 0) {
+					final int lf = read();
+
+					if (lf != -1 && lf != '\n') {
+						((PushbackInputStream) in).unread((byte) lf);
+					}
+				}
+				else {
+					skipNextLF = true;
+				}
+
 				break;
 			}
 
