Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4219653

BufferedReader.readLine() fails reading EOF from Socket

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.7
    • core-libs
    • x86
    • windows_nt



      Name: dbT83986 Date: 03/11/99


      When making a socket connection to *certain* servers, BufferedReader.readLine() (or read() and read(char[], int, int] for that matter)
      fails to recognize EOF.

      One such server is Sun's FTP server (ftp.sun.com). Observe the following code.

      package MyUtils;

      import java.io.*;
      import java.net.*;

      public class FTPTest
      {
        public static void main(String[] args)
        {
          try {
            Socket sock = new Socket("ftp.sun.com", 21);
            sock.setSoTimeout(10000);
            BufferedReader reader = new BufferedReader(new
              InputStreamReader(sock.getInputStream()));

            String line = reader.readLine();
            System.out.println("line: [" + line + "]");
            while (line != null) {
              line = reader.readLine();
              System.out.println("line: [" + line + "]");
            }
          }
          catch (Exception e) {
            e.printStackTrace();
          }
          finally {
          }
        }
      }

      ---

      This code generates this output:

      line: [220-Welcome to Sun Microsystems Corporate FTP Server.]
      line: [220-]
      line: [220 ftp FTP server (ftpd Wed Oct 30 23:31:06 PST 1996) ready.]
      java.io.InterruptedIOException: Read timed out
              at java.net.SocketInputStream.read(SocketInputStream.java:84)
              at java.net.SocketInputStream.read(SocketInputStream.java:67)
              at java.io.InputStreamReader.fill(Compiled Code)
              at java.io.InputStreamReader.read(InputStreamReader.java:227)
              at java.io.BufferedReader.fill(Compiled Code)
              at java.io.BufferedReader.readLine(Compiled Code)
              at PDUtils.FTPTest.main(Compiled Code)
      (Review ID: 55258)
      ======================================================================

            Unassigned Unassigned
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: