public static String formatBytesHumanReadable ( long _bytes , boolean _use1000BytesPerMb ) { int unit = _use1000BytesPerMb ? 1000 : 1024 ; if ( _bytes < unit ) { return _bytes + " B" ; } int exp = ( int ) ( Math . log ( _bytes ) / Math . log ( unit ) ) ; String pre = ( _use1000BytesPerMb ? "kMGTPE" : "KMGTPE" ) . charAt ( exp - 1 ) + ( _use1000BytesPerMb ? "" : "i" ) ; return String . format ( "%.1f %sB" , _bytes / Math . pow ( unit , exp ) , pre ) ; }
Formats a file size given in byte to something human readable .