[libbluray-devel] BDJUtil.makeFiveDigitStr(): check range. Avoid using DecimalFormat.

hpi1 git at videolan.org
Tue Nov 24 09:45:02 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Nov 24 10:19:43 2015 +0200| [09a64d011edd6f4c890e1baa3df146c4dc91208f] | committer: hpi1

BDJUtil.makeFiveDigitStr(): check range. Avoid using DecimalFormat.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=09a64d011edd6f4c890e1baa3df146c4dc91208f
---

 src/libbluray/bdj/java/org/videolan/BDJUtil.java |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJUtil.java b/src/libbluray/bdj/java/org/videolan/BDJUtil.java
index b5a9864..cc17992 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJUtil.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJUtil.java
@@ -25,20 +25,31 @@ public class BDJUtil {
     /**
      * Make a five digit zero padded string based on an integer
      * Ex. integer 1 -> string "00001"
-     * 
+     *
      * @param id
      * @return
      */
-    public static String makeFiveDigitStr(int id) 
+    public static String makeFiveDigitStr(int id)
     {
+        if (id < 0 || id > 99999) {
+            System.err.println("Invalid ID: " + id);
+            throw new IllegalArgumentException("Invalid ID " + id);
+        }
+        String s = "" + id;
+        while (s.length() < 5) {
+            s = "0" + s;
+        }
+        return s;
+        /*
         DecimalFormat fmt = new DecimalFormat();
         fmt.setMaximumIntegerDigits(5);
         fmt.setMinimumIntegerDigits(5);
         fmt.setGroupingUsed(false);
-        
+
         return fmt.format(id);
+        */
     }
-    
+
     /**
      * Make a path based on the disc root to an absolute path based on the filesystem of the computer
      * Ex. /BDMV/JAR/00000.jar -> /bluray/disc/mount/point/BDMV/JAR/00000.jar



More information about the libbluray-devel mailing list