cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [35/59] [abbrv] git commit: updated refs/heads/disk-cache to bbae6f8
Date Wed, 25 Sep 2013 10:29:30 GMT
Clean out a few warnings on potential resource leakage


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8b6dcf8b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8b6dcf8b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8b6dcf8b

Branch: refs/heads/disk-cache
Commit: 8b6dcf8b6e85b7164dbc5a3cc33b3ddc7b4da17d
Parents: d37b87d
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Sat Sep 21 15:32:52 2013 +0800
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Sat Sep 21 15:32:52 2013 +0800

----------------------------------------------------------------------
 utils/src/com/cloud/utils/NumbersUtil.java      | 10 +++++--
 utils/test/com/cloud/utils/NumbersUtilTest.java | 31 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b6dcf8b/utils/src/com/cloud/utils/NumbersUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/NumbersUtil.java b/utils/src/com/cloud/utils/NumbersUtil.java
index d9b06b7..e7e1f76 100755
--- a/utils/src/com/cloud/utils/NumbersUtil.java
+++ b/utils/src/com/cloud/utils/NumbersUtil.java
@@ -199,25 +199,29 @@ public class NumbersUtil {
     public static String toReadableSize(long bytes) {
         if (bytes <= KB && bytes >= 0) {
             return Long.toString(bytes) + " bytes";
-        } else if (bytes <= MB) {
+        } else if (bytes < MB) {
             StringBuilder builder = new StringBuilder();
             Formatter format = new Formatter(builder);
             format.format("%.2f KB", (float)bytes / (float)KB);
+            format.close();
             return builder.toString();
-        } else if (bytes <= GB) {
+        } else if (bytes < GB) {
             StringBuilder builder = new StringBuilder();
             Formatter format = new Formatter(builder);
             format.format("%.2f MB", (float)bytes / (float)MB);
+            format.close();
             return builder.toString();
-        } else if (bytes <= TB) {
+        } else if (bytes < TB) {
             StringBuilder builder = new StringBuilder();
             Formatter format = new Formatter(builder);
             format.format("%.2f GB", (float)bytes / (float)GB);
+            format.close();
             return builder.toString();
         } else {
             StringBuilder builder = new StringBuilder();
             Formatter format = new Formatter(builder);
             format.format("%.4f TB", (float)bytes / (float)TB);
+            format.close();
             return builder.toString();
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b6dcf8b/utils/test/com/cloud/utils/NumbersUtilTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/NumbersUtilTest.java b/utils/test/com/cloud/utils/NumbersUtilTest.java
new file mode 100644
index 0000000..711cc22
--- /dev/null
+++ b/utils/test/com/cloud/utils/NumbersUtilTest.java
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class NumbersUtilTest {
+
+    @Test
+    public void formattingCheck() {
+        long size = 1024*1024*1024;
+        String formatted = NumbersUtil.toReadableSize(size);
+        assertEquals("1.00 GB", formatted);
+    }
+}


Mime
View raw message