Class SizeUtils

java.lang.Object
dev.sympho.modular_commands.utils.SizeUtils

public final class SizeUtils extends Object
Utilities for working with file sizes.

Note the possibility of integer overflow depending on the data type used.

Since:
1.0
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The value of the G prefix.
    static final int
    The value of the K prefix.
    static final int
    The value of the M prefix.
    static final long
    The value of the T prefix.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(@org.checkerframework.common.value.qual.IntRange(from=0L) long size)
    Formats a size to the nearest (supported) prefix.
    static int
    giga(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2L) int size)
    Makes a size in gigabytes.
    static long
    giga(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036L) long size)
    Makes a size in gigabytes.
    static int
    kilo(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483L) int size)
    Makes a size in kilobytes.
    static long
    kilo(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036854775L) long size)
    Makes a size in kilobytes.
    static int
    mega(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147L) int size)
    Makes a size in megabytes.
    static long
    mega(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036854L) long size)
    Makes a size in megabytes.
    static long
    tera(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372L) long size)
    Makes a size in terabytes.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • kilo

      public static int kilo(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483L) int size)
      Makes a size in kilobytes.
      Parameters:
      size - The size in KB.
      Returns:
      The size in bytes.
    • kilo

      public static long kilo(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036854775L) long size)
      Makes a size in kilobytes.
      Parameters:
      size - The size in KB.
      Returns:
      The size in bytes.
    • mega

      public static int mega(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147L) int size)
      Makes a size in megabytes.
      Parameters:
      size - The size in MB.
      Returns:
      The size in bytes.
    • mega

      public static long mega(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036854L) long size)
      Makes a size in megabytes.
      Parameters:
      size - The size in MB.
      Returns:
      The size in bytes.
    • giga

      public static int giga(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2L) int size)
      Makes a size in gigabytes.
      Parameters:
      size - The size in GB.
      Returns:
      The size in bytes.
    • giga

      public static long giga(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372036L) long size)
      Makes a size in gigabytes.
      Parameters:
      size - The size in GB.
      Returns:
      The size in bytes.
    • tera

      public static long tera(@org.checkerframework.common.value.qual.IntRange(from=0L, to=9223372L) long size)
      Makes a size in terabytes.
      Parameters:
      size - The size in TB.
      Returns:
      The size in bytes.
    • format

      public static String format(@org.checkerframework.common.value.qual.IntRange(from=0L) long size)
      Formats a size to the nearest (supported) prefix.
      Parameters:
      size - The size to format.
      Returns:
      The formatted size.