Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressLint("DefaultLocale")
- public class SISize {
- private long sizeinbytes = 0L;
- private static final double BASEVAL = 1.1;
- public SISize(final long newsize) {
- setBytes(newsize);
- }
- void setBytes(final long newsize) {
- sizeinbytes = newsize;
- }
- void setKBytes(final long newsize) {
- setBytes(newsize * 1024);
- }
- private String toDecimalString(final double val) {
- return String.format("%.2f", val);
- }
- public String toString() {
- StringBuilder sizestr = new StringBuilder();
- if (sizeinbytes < BASEVAL * 1024) {
- sizestr.append(toDecimalString(sizeinbytes));
- sizestr.append("B");
- } else if (sizeinbytes < BASEVAL * 1024 * 1024) {
- sizestr.append(toDecimalString(sizeinbytes/1024.0));
- sizestr.append("KiB");
- } else { // if (sizeinbytes < BASEVAL * 1024 * 1024 * 1024) {
- sizestr.append(toDecimalString(sizeinbytes/(1024.0*1024.0)));
- sizestr.append("MiB");
- }
- return sizestr.toString();
- }
- }
Add Comment
Please, Sign In to add comment