⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formatutilities.java

📁 peeranha42是jxta的 p2p程序核心
💻 JAVA
字号:
package de.uni_bremen.informatik.p2p.plugins.filesharing.control;

import java.text.NumberFormat;

/**
 * Class contains methods for formating numbers and strings.
 * 
 * @author Lars Kordes
 */
public class FormatUtilities {

	/**
	 * Returns a formated String of a long integer.
	 * 
	 * @param d Number the gets formated.
	 * @return String that contains the formated number.
	 */
	public static String giveFormatedString(long l) {
		return Long.toString(l);
	}
	
	/**
	 * Gets file size and returns a correct formatted string.
	 * 
	 * @param size File size
	 * @return Formatted string with file size in
	 */
	public static String giveCorrectSizeString(long size) {
	    NumberFormat nf = NumberFormat.getInstance();
	    nf.setMaximumFractionDigits(1);
	    nf.setMinimumFractionDigits(1);
	    nf.setGroupingUsed(true);

	    // if size is less then one kbyte, return 1
		if(size < 1024) return size + " B";
		// if size is less then one Mbyte, return kbyte size
		if(size < 1048576) return nf.format(size / 1024.0) + " KB";
		// if return Mbyte size
		if(size < 1073741824) return nf.format(size / (1024.0*1024.0)) + " MB";
		// else gigabyte
		else return nf.format(size / (1024.0*1024.0*1024.0)) + " GB";
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -