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

bufferedReader bug

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.1
    • 1.1
    • core-libs
    • None
    • 1.1.1
    • x86
    • windows_95
    • Not verified

      From: Laurence Vanhelsuwe <###@###.###>
      This does not look like form output to me.


      Hi, (sorry my left shift key is dead so capitalizaation will be poor0

      i think i found a bug in the xxxReader classes (java.io)

      in an attempt to write 1.1 "clean" pograms for an upcoming book on
      Java beans, i wanted to convert a standard datainputstream.readline()
      to the new bufferedreader(new inputstreamreader(somestream))) variant.

      If i do this, then compiler stops complaining (clean compile0, but
      the program doesn#t work anymore.

      the program is very simple. it just takes a JAR file as argument and
      prints a summary of the MANIFEST file in the file.

      I include the complete source (2 classes), incl. the commented lines with
      the original datainputstream objects (which worked fine).

      the prgram hangs in printmanifestsummary...


        laurence


      ps. FEEDBACK much appreciated.

      -----------------------------------------------------------------------------

      import java.io.*;

      public class Manifest {

      //-------------------------------------------------------------------
      // main entry point. Check command line args. Find manifest file in
      // JAR file and produce summary report of its contents.
      //-------------------------------------------------------------------
      protected void go(String[] args) throws IOException {
      //DataInputStream manifestFile;
      BufferedReader manifestFile;
      String filename;

              if ( args.length != 1 ) {
                      System.out.println("Usage: Manifest <jarfile>");
                      System.exit(10);
              }

              filename = args[0];

              // go find the MANIFEST.MF file in the ZIP file.
              manifestFile = ZipLocate.zipLocate(filename, "META-INF/MANIFEST.MF");

              if ( manifestFile == null ) {
                      System.out.println(
                              "Could not locate MANIFEST.MF entry in " + filename);
                      System.exit(10);
              }

              System.out.println(
                      "MANIFEST file for JAR file '"+ filename +"' contains:");
              PrintManifestSummary(manifestFile);
      }
      //-------------------------------------------------------------------
      // PrintManifestSummary
      //-------------------------------------------------------------------
      //protected void PrintManifestSummary(DataInputStream manifestFile)
      protected void PrintManifestSummary(BufferedReader manifestFile)
                                                                                                              throws IOException {
      String line = "";

              while( (line = manifestFile.readLine()) != null) {
                      if ( line.startsWith("Name:") ) {
                              System.out.println(line);
                      }
              }
      }
      //-------------------------------------------------------------------
      // static main delegates work to object
      //-------------------------------------------------------------------
      public static void main (String[] args) {
              try {
                      new Manifest().go(args);
              } catch (IOException IOerror) {
                      System.out.println("An I/O error occurred: " + IOerror);
              }
      }
      } // End of Class Manifest



      import java.util.zip.*;
      import java.io.*;

      public class ZipLocate {

      //-------------------------------------------------------------------
      // static utility method to locate and return a handle to a ZIP entry
      //-------------------------------------------------------------------
      //public static DataInputStream zipLocate(
      public static BufferedReader zipLocate(
                                                                      String filename, String zipEntryName)
                                                                              throws ZipException, IOException {
      FileInputStream fin;
      ZipInputStream in;
      ZipEntry entry;
      int entrySize;

              fin = new FileInputStream(filename);
              in = new ZipInputStream(fin);

              entry = in.getNextEntry();
              while ( entry != null ) {
                      if ( entry.getName().equals(zipEntryName) ) {
                              break;
                      }
                      entry = in.getNextEntry();
              }
              if ( ! entry.getName().equals(zipEntryName) ) {
                      in.close();
                      return null;
              }
      // return new DataInputStream(in);
              return new BufferedReader(new InputStreamReader(in));
      }
      //-------------------------------------------------------------------
      // static main contains self-test code.
      //-------------------------------------------------------------------
      public static void main(String[] args) {
      boolean OK;

              try {
                      OK = ( zipLocate("test.jar", "META-INF/MANIFEST.MF") != null);
              } catch (ZipException zipProblem) {
                      System.out.println(zipProblem);
                      OK = false;
              } catch (IOException IOfailed) {
                      System.out.println(IOfailed);
                      OK = false;
              }

              String report = OK ? "OK" : "failed";
              System.out.println("ZipLocate test: " + report);
      }
      } // End of Class ZipLocate


          | Laurence Vanhelsuwe |
          | |
          | E-Mail...: ###@###.### |
          | WWW......: http://www.telework.demon.co.uk/ |

            mr Mark Reinhold
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: