19 package org.sleuthkit.autopsy.datasourcesummary.ui;
21 import java.text.DecimalFormat;
22 import java.util.Arrays;
23 import java.util.List;
24 import org.openide.util.NbBundle;
35 private static List<String>
UNITS = Arrays.asList(
36 Bundle.SizeRepresentationUtil_units_bytes(),
37 Bundle.SizeRepresentationUtil_units_kilobytes(),
38 Bundle.SizeRepresentationUtil_units_megabytes(),
39 Bundle.SizeRepresentationUtil_units_gigabytes(),
40 Bundle.SizeRepresentationUtil_units_terabytes(),
41 Bundle.SizeRepresentationUtil_units_petabytes()
68 "SizeRepresentationUtil_units_bytes= bytes",
69 "SizeRepresentationUtil_units_kilobytes= kB",
70 "SizeRepresentationUtil_units_megabytes= MB",
71 "SizeRepresentationUtil_units_gigabytes= GB",
72 "SizeRepresentationUtil_units_terabytes= TB",
73 "SizeRepresentationUtil_units_petabytes= PB"
75 public static String
getSizeString(Long size, DecimalFormat format,
boolean showFullSize) {
79 double approximateSize = size;
81 for (; unitsIndex < UNITS.size(); unitsIndex++) {
82 if (approximateSize < SIZE_CONVERSION_CONSTANT) {
89 String fullSize = size + UNITS.get(0);
90 String closestUnitSize = format.format(approximateSize) + UNITS.get(unitsIndex);
92 if (unitsIndex == 0) {
94 }
else if (showFullSize) {
95 return String.format(
"%s (%s)", closestUnitSize, fullSize);
97 return closestUnitSize;
static final DecimalFormat APPROXIMATE_SIZE_FORMAT
static List< String > UNITS
static final int SIZE_CONVERSION_CONSTANT
static String getSizeString(Long size, DecimalFormat format, boolean showFullSize)
static String getSizeString(Long size)