Author: toad
Date: 2008-03-01 23:56:18 +0000 (Sat, 01 Mar 2008)
New Revision: 18315

Modified:
   trunk/freenet/src/freenet/support/Fields.java
Log:
Add a few utilities - parseLong/Int/Short(string,default)

Modified: trunk/freenet/src/freenet/support/Fields.java
===================================================================
--- trunk/freenet/src/freenet/support/Fields.java       2008-03-01 23:54:22 UTC 
(rev 18314)
+++ trunk/freenet/src/freenet/support/Fields.java       2008-03-01 23:56:18 UTC 
(rev 18315)
@@ -574,6 +574,30 @@
         return buf;
        }

+       public static long parseLong(String s, long defaultValue) {
+               try {
+                       return Long.parseLong(s);
+               } catch (NumberFormatException e) {
+                       return defaultValue;
+               }
+       }
+       
+       public static int parseInt(String s, int defaultValue) {
+               try {
+                       return Integer.parseInt(s);
+               } catch (NumberFormatException e) {
+                       return defaultValue;
+               }
+       }
+       
+       public static long parseShort(String s, short defaultValue) {
+               try {
+                       return Short.parseShort(s);
+               } catch (NumberFormatException e) {
+                       return defaultValue;
+               }
+       }
+       
     /**
      * Parse a human-readable string possibly including SI units into a short.
         * @throws NumberFormatException


Reply via email to