Files
ProjectOctopus/server/src/main/java/io/wdd/common/utils/DataUnit.java
2024-06-14 10:37:40 +08:00

64 lines
1.3 KiB
Java
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package io.wdd.common.utils;
import org.springframework.util.unit.DataSize;
/**
* 数据单位封装<p>
* 此类来自于Spring-framework
*
* <pre>
* BYTES 1B 2^0 1
* KILOBYTES 1KB 2^10 1,024
* MEGABYTES 1MB 2^20 1,048,576
* GIGABYTES 1GB 2^30 1,073,741,824
* TERABYTES 1TB 2^40 1,099,511,627,776
* </pre>
*
* @author Sam BrannenStephane Nicoll
* @since 5.3.10
*/
public enum DataUnit {
/**
* Bytes, 后缀表示为: {@code B}.
*/
BYTES("B", DataSize.ofBytes(1)),
/**
* Kilobytes, 后缀表示为: {@code KB}.
*/
KILOBYTES("KB", DataSize.ofKilobytes(1)),
/**
* Megabytes, 后缀表示为: {@code MB}.
*/
MEGABYTES("MB", DataSize.ofMegabytes(1)),
/**
* Gigabytes, 后缀表示为: {@code GB}.
*/
GIGABYTES("GB", DataSize.ofGigabytes(1)),
/**
* Terabytes, 后缀表示为: {@code TB}.
*/
TERABYTES("TB", DataSize.ofTerabytes(1));
public static final String[] UNIT_NAMES = new String[]{"B", "KB", "MB", "GB", "TB", "PB", "EB"};
private final String suffix;
private final DataSize size;
DataUnit(String suffix, DataSize size) {
this.suffix = suffix;
this.size = size;
}
DataSize size() {
return this.size;
}
}