|
|
|
@ -317,6 +317,25 @@ public class PrismUtils |
|
|
|
throw new PrismException("Invalid amount of memory \"" + mem + "\""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Convert a number of bytes to a string representing the amount of memory (e.g. 125k, 50m, 4g). |
|
|
|
*/ |
|
|
|
public static String convertBytesToMemoryString(long bytes) throws PrismException |
|
|
|
{ |
|
|
|
String units[] = { "b", "k", "m", "g" }; |
|
|
|
for (int i = 3; i > 0; i--) { |
|
|
|
long pow = 1 << (i * 10); |
|
|
|
if (bytes >= pow) { |
|
|
|
return (bytes % pow == 0 ? (bytes / pow) : String.format("%.1f", ((double) bytes) / pow)) + units[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
return bytes + units[0]; |
|
|
|
|
|
|
|
/*for (String s : new String[] { "1g", "1500m", "2g", "1000m", "1024m", "1" }) { |
|
|
|
System.out.println(s + " => " + PrismUtils.convertMemoryStringtoKB(s) * 1024 + " => " + PrismUtils.convertBytesToMemoryString(PrismUtils.convertMemoryStringtoKB(s) * 1024)); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |