Java Long Number Readable Format convertHumanSize(long byteSize)

Here you can find the source of convertHumanSize(long byteSize)

Description

Check whether file is executable according to its extenstion and executable extension name list from Edgenius configuaration.

License

Open Source License

Parameter

Parameter Description
filename a parameter

Declaration






















public static String convertHumanSize(long byteSize) 

Method Source Code

//package com.java2s;
/* //from w w  w .j a va  2s .  c  o m
 * =============================================================
 * Copyright (C) 2007-2011 Edgenius (http://www.edgenius.com)
 * =============================================================
 * License Information: http://www.edgenius.com/licensing/edgenius/2.0/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2.0
 * as published by the Free Software Foundation.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * http://www.gnu.org/licenses/gpl.txt
 *  
 * ****************************************************************
 */

import java.text.NumberFormat;

public class Main {
    /**
     * Check whether file is executable according to its extenstion and executable extension name list from Edgenius configuaration.
     * @param filename
     * @return
     */
    //     public static boolean isExecutableFile(String filename){
    //        String extname = FileUtil.getFileExtension(filename);
    //        log.debug("Check executable file for extension name " + extname);
    //        
    //        if(StringUtils.isBlank(extname))
    //           return false;
    //        extname = "." + extname;
    //        
    //        String exeListStr = Global.ExecuteFileExt;
    //        String[] extList = StringUtils.split(exeListStr, ',');
    //        boolean executable = false;
    //        for (String ext : extList) {
    //         if(StringUtils.equalsIgnoreCase(ext, extname)){
    //            executable = true;
    //            break;
    //         }
    //      }
    //        
    //        return executable;
    //     }

    public static String convertHumanSize(long byteSize) {
        String unit = "";
        float size = (float) byteSize;
        if (size > 1024) {
            size = size / 1024;
            unit = "K";
        }
        if (size > 1024) {
            size = size / 1024;
            unit = "M";
        }
        if (size > 1024) {
            size = size / 1024;
            unit = "G";
        }

        NumberFormat format = NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(1);
        String ret = format.format(size);

        return ret + unit;
    }
}

Related

  1. bytesToString(long bytes)
  2. convertBytes(long bytes)
  3. convertBytes(long size)
  4. convertByteToGMKB(long bytes)
  5. convertByteUnit(Long l)
  6. convertLongToMega(long value)
  7. convertMbIntoGb(long megaBytes)
  8. formatBytes(long bts)
  9. formatBytes(long bytes)