Java Size Format formatPartSize(int size, NumberFormat format)

Here you can find the source of formatPartSize(int size, NumberFormat format)

Description

Format the size of a part like message or attachment.

License

Open Source License

Parameter

Parameter Description
size a parameter

Declaration

public static String formatPartSize(int size, NumberFormat format) 

Method Source Code

//package com.java2s;
/* MessageUtils.java//  w ww .  j a  va2  s. co  m
    
   Copyright (c) 2009 Juergen Schlierf, All Rights Reserved
       
   This file is part of Cubusmail (http://code.google.com/p/cubusmail/).
       
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.
       
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
       
   You should have received a copy of the GNU Lesser General Public
   License along with Cubusmail. If not, see <http://www.gnu.org/licenses/>.
       
 */

import java.text.NumberFormat;

public class Main {
    /**
     * Format the size of a part like message or attachment.
     * 
     * @param size
     * @return
     */
    public static String formatPartSize(int size, NumberFormat format) {

        String value = null;
        if (size >= 1024) {
            value = format.format(size / 1024) + " KB";
        } else {
            if (size > 0) {
                value = Integer.toString(size) + " B";
            } else {
                value = "n/a";
            }
        }
        return value;
    }
}

Related

  1. formatFileSize(long size)
  2. formatFileSize(Long sizeBytes)
  3. formatFilesizeGB(long filesize, int fractionDigits)
  4. formatGameSize(int size)
  5. formatMemorySize(long size)
  6. formatSize(double fileSize)
  7. formatSize(double size)
  8. formatSize(int size)
  9. formatSize(long bytes)