commons-file/src/main/java/info/monitorenter/util/FileUtil.java
public String formatFilesize(final long filesize, final Locale locale) {

    String result;
    final long filesizeNormal = Math.abs(filesize);

    if (Math.abs(filesize) < 1024) {
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_BYTES_1"),
          new Object[] {new Long(filesizeNormal) });
    } else if (filesizeNormal < 1048576) {
      // 1048576 = 1024.0 * 1024.0
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_KBYTES_1"),
          new Object[] {new Double(filesizeNormal / 1024.0) });
    } else if (filesizeNormal < 1073741824) {
      // 1024.0^3 = 1073741824
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_MBYTES_1"),
          new Object[] {new Double(filesize / 1048576.0) });
    } else {
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_GBYTES_1"),
          new Object[] {new Double(filesizeNormal / 1073741824.0) });
    }
    return result;
  }
public String formatFilesize(final long filesize, final Locale locale) {

    String result;
    final long filesizeNormal = Math.abs(filesize);

    if (Math.abs(filesize) < 1024) {
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_BYTES_1"),
          new Object[] {new Long(filesizeNormal) });
    } else if (filesizeNormal < 1048576) {
      // 1048576 = 1024.0 * 1024.0
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_KBYTES_1"),
          new Object[] {new Double(filesizeNormal / 1024.0) });
    } else if (filesizeNormal < 1073741824) {
      // 1024.0^3 = 1073741824
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_MBYTES_1"),
          new Object[] {new Double(filesize / 1048576.0) });
    } else {
      result = MessageFormat.format(this.m_bundle.getString("GUI_FILEUTIL_FILESIZE_GBYTES_1"),
          new Object[] {new Double(filesizeNormal / 1073741824.0) });
    }
    return result;
  }
public String formatFilesize ( final long filesize , final Locale locale ) { String result ; final long filesizeNormal = Math . abs ( filesize ) ; if ( Math . abs ( filesize ) < 1024 ) { result = MessageFormat . format ( this . m_bundle . getString ( "GUI_FILEUTIL_FILESIZE_BYTES_1" ) , new Object [ ] { new Long ( filesizeNormal ) } ) ; } else if ( filesizeNormal < 1048576 ) { // 1048576 = 1024.0 * 1024.0 result = MessageFormat . format ( this . m_bundle . getString ( "GUI_FILEUTIL_FILESIZE_KBYTES_1" ) , new Object [ ] { new Double ( filesizeNormal / 1024.0 ) } ) ; } else if ( filesizeNormal < 1073741824 ) { // 1024.0^3 = 1073741824 result = MessageFormat . format ( this . m_bundle . getString ( "GUI_FILEUTIL_FILESIZE_MBYTES_1" ) , new Object [ ] { new Double ( filesize / 1048576.0 ) } ) ; } else { result = MessageFormat . format ( this . m_bundle . getString ( "GUI_FILEUTIL_FILESIZE_GBYTES_1" ) , new Object [ ] { new Double ( filesizeNormal / 1073741824.0 ) } ) ; } return result ; }
Returns the formatted file size to Bytes, KB, MB or GB depending on the
given value.
<p>

@param filesize
in bytes

@param locale
the locale to translate the result to (e.g. in France they us

@return the formatted filesize to Bytes, KB, MB or GB depending on the
given value.
Returns the formatted file size to Bytes KB MB or GB depending on the given value . <p >