Skip to content

Commit 42e2fce

Browse files
committed
Added formatFileSize() method to StringUtils
1 parent 0d82eb3 commit 42e2fce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/javaxt/express/utils/StringUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public static String capitalize(String fieldName){
9494
//**************************************************************************
9595
//** rtrim
9696
//**************************************************************************
97+
/** Used to remove whitespaces at the end of a given string
98+
*/
9799
public static String rtrim(String s) {
98100
int i = s.length()-1;
99101
while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
@@ -119,6 +121,25 @@ public static String getElapsedTime(long startTime){
119121
}
120122

121123

124+
//**************************************************************************
125+
//** formatFileSize
126+
//**************************************************************************
127+
public static String formatFileSize(long size){
128+
if (size>0){
129+
size = size/1024;
130+
if (size<=1) return "1 KB";
131+
else{
132+
size = size/1024;
133+
if (size<=1) return "1 MB";
134+
else{
135+
return format(Math.round(size)) + " MB";
136+
}
137+
}
138+
}
139+
return "";
140+
};
141+
142+
122143
//**************************************************************************
123144
//** format
124145
//**************************************************************************

0 commit comments

Comments
 (0)