Java Memory memorySize(long bytesSize)

Here you can find the source of memorySize(long bytesSize)

Description

memory Size

License

Apache License

Declaration

public static String memorySize(long bytesSize) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String memorySize(long bytesSize) {
        if (bytesSize < 1024) {
            return stringBuffer(bytesSize, 'B');
        } else if (bytesSize < 1024 * 1024) {
            float kb = (float) bytesSize / 1024.f;
            return stringBuffer(String.format("%.2f", kb), "KB");
        } else {/*from w ww  .ja  va 2  s.co  m*/
            float mb = (float) bytesSize / 1024.f / 1024.f;
            return stringBuffer(String.format("%.2f", mb), "MB");
        }
    }

    public static String stringBuffer(Object... strs) {
        StringBuilder buf = new StringBuilder();
        for (Object str : strs) {
            buf.append(str);
        }
        return buf.toString();
    }
}

Related

  1. memory()
  2. memoryEqual(byte[] left, int leftOffset, byte[] right, int rightOffset, int length)
  3. memoryInfo()
  4. memoryIsLow()
  5. memoryOccupied()
  6. memoryUtilization()
  7. memoryValue(long inBytes)
  8. normalizeMemoryMeasure(String memory)
  9. percentMemoryFull()