fix parsing of bytes value

This commit is contained in:
kimchy 2010-10-31 15:47:19 +02:00
parent feb854b742
commit f79719beaa
1 changed files with 3 additions and 3 deletions

View File

@ -129,9 +129,7 @@ public class ByteSizeValue implements Serializable, Streamable {
} }
long bytes; long bytes;
try { try {
if (sValue.endsWith("b")) { if (sValue.endsWith("k") || sValue.endsWith("K")) {
bytes = Long.parseLong(sValue.substring(0, sValue.length() - 1));
} else if (sValue.endsWith("k") || sValue.endsWith("K")) {
bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * ByteSizeUnit.C1); bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * ByteSizeUnit.C1);
} else if (sValue.endsWith("kb")) { } else if (sValue.endsWith("kb")) {
bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 2)) * ByteSizeUnit.C1); bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 2)) * ByteSizeUnit.C1);
@ -143,6 +141,8 @@ public class ByteSizeValue implements Serializable, Streamable {
bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * ByteSizeUnit.C3); bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * ByteSizeUnit.C3);
} else if (sValue.endsWith("gb")) { } else if (sValue.endsWith("gb")) {
bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 2)) * ByteSizeUnit.C3); bytes = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 2)) * ByteSizeUnit.C3);
} else if (sValue.endsWith("b")) {
bytes = Long.parseLong(sValue.substring(0, sValue.length() - 1));
} else { } else {
bytes = Long.parseLong(sValue); bytes = Long.parseLong(sValue);
} }