hello there,

the attached patch --already committed-- re-factors the above class to 
expose a method that prints the help text without exiting the VM.

2006-04-29  Raif S. Naffah  <[EMAIL PROTECTED]>

        * tools/gnu/classpath/tools/HelpPrinter.java (printHelp): New method.
        (printHelpAndExit): Re-factored to use the above method.

 
cheers;
rsn
Index: HelpPrinter.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/tools/gnu/classpath/tools/HelpPrinter.java,v
retrieving revision 1.1
diff -u -r1.1 HelpPrinter.java
--- HelpPrinter.java    8 Feb 2006 12:14:02 -0000       1.1
+++ HelpPrinter.java    29 Apr 2006 07:44:31 -0000
@@ -70,30 +70,47 @@
   }

   /**
-   * Prints the help message and terminates.
+   * Prints the contents of the resource specified by the designated path.
    *
-   * @param helpResourcePath the path to the help resource, related to the
+   * @param helpResourcePath the path to a help resource, related to the
    *          HelpPrinter class.
    */
-  public static void printHelpAndExit(String helpResourcePath)
+  public static void printHelp(String helpResourcePath)
   {
     InputStream in = HelpPrinter.class.getResourceAsStream(helpResourcePath);
-    BufferedReader r = new BufferedReader(new InputStreamReader(in));
-
+    BufferedReader br = new BufferedReader(new InputStreamReader(in));
     try
       {
         String s;
-        while ((s = r.readLine()) != null)
-          {
-            System.out.println(s);
-          }
-        r.close();
+        while ((s = br.readLine()) != null)
+          System.out.println(s);
       }
-    catch (IOException e)
+    catch (IOException x)
       {
         System.err.print("Resource loading is broken:");
-        e.printStackTrace();
+        x.printStackTrace(System.err);
       }
+    finally
+      {
+        try
+          {
+            br.close();
+          }
+        catch (IOException ignored)
+          {
+          }
+      }
+  }
+
+  /**
+   * Prints the help message and terminates.
+   *
+   * @param helpResourcePath the path to the help resource, related to the
+   *          HelpPrinter class.
+   */
+  public static void printHelpAndExit(String helpResourcePath)
+  {
+    printHelp(helpResourcePath);
     System.exit(0);
   }
 }

Attachment: pgpyBmElCvPBQ.pgp
Description: PGP signature

Reply via email to