Package com.imyeyu.io

Class IOSize

java.lang.Object
com.imyeyu.io.IOSize

public class IOSize extends Object
字节大小工具
Version:
2023-06-01 16:41
Author:
夜雨
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    储存单位
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static long
    1 字节
    static long
    1 EB
    static long
    1 GB
    static long
    1 KB
    static long
    1 MB
    static long
    1 PB
    static long
    1 TB
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(double size)
    格式化一个储存容量,保留两位小数
    static String
    format(double size, int decimal, IOSize.Unit stopUnit)
    格式化一个储存容量
    static String
    format(double size, IOSize.Unit stopUnit)
    格式化一个储存容量
    static String
    formatWithoutUnit(double size, int decimal, IOSize.Unit stopUnit)
    格式化一个储存容量,不带单位
    static long
    parse(String sizeStr)
    将格式化的储存量字符串解析为字节量

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BYTE

      public static long BYTE
      1 字节
    • KB

      public static long KB
      1 KB
    • MB

      public static long MB
      1 MB
    • GB

      public static long GB
      1 GB
    • TB

      public static long TB
      1 TB
    • PB

      public static long PB
      1 PB
    • EB

      public static long EB
      1 EB
  • Constructor Details

    • IOSize

      public IOSize()
  • Method Details

    • format

      public static String format(double size)

      格式化一个储存容量,保留两位小数

           // 返回 100.01 KB
           Tools.byteFormat(102411, 2);
       
      Parameters:
      size - 字节大小
      Returns:
      格式化结果
    • format

      public static String format(double size, IOSize.Unit stopUnit)

      格式化一个储存容量

           // 返回 100.01 KB
           Tools.byteFormat(102411, 2);
       
      Parameters:
      size - 字节大小
      stopUnit - 最高等级,格式化到某单位后不再升级,最低 IOSize.Unit.B,最高 IOSize.Unit.EB
      Returns:
      格式化结果
    • format

      public static String format(double size, int decimal, IOSize.Unit stopUnit)

      格式化一个储存容量

           // 返回 100.01 KB
           Tools.byteFormat(102411, 2);
       
      Parameters:
      size - 字节大小
      decimal - 保留小数
      stopUnit - 最高等级,格式化到某单位后不再升级,最低 IOSize.Unit.B,最高 IOSize.Unit.EB
      Returns:
      格式化结果
    • formatWithoutUnit

      public static String formatWithoutUnit(double size, int decimal, IOSize.Unit stopUnit)

      格式化一个储存容量,不带单位

           // 返回 100.01
           Tools.byteFormat(102411, 2);
       
      Parameters:
      size - 字节大小
      decimal - 保留小数
      stopUnit - 最高等级,格式化到某单位后不再升级,最低 IOSize.Unit.B,最高 IOSize.Unit.TB
      Returns:
      格式化结果(不带单位)
    • parse

      public static long parse(String sizeStr)
      将格式化的储存量字符串解析为字节量

      支持格式:10GB, 10 GB, 1TB, 1.24 KB 等(单位不区分大小写)

           // 返回 102400
           IOSize.parse("100 KB");
           // 返回 1073741824
           IOSize.parse("1GB");
       
      Parameters:
      sizeStr - 格式化后的储存量字符串
      Returns:
      字节量
      Throws:
      IllegalArgumentException - 格式无效