package io.dropwizard.util;

A unit of size.
/** * A unit of size. */
public enum SizeUnit {
Bytes.
/** * Bytes. */
BYTES(8),
Kilobytes.
/** * Kilobytes. */
KILOBYTES(8L * 1024),
Megabytes.
/** * Megabytes. */
MEGABYTES(8L * 1024 * 1024),
Gigabytes.
/** * Gigabytes. */
GIGABYTES(8L * 1024 * 1024 * 1024),
Terabytes.
/** * Terabytes. */
TERABYTES(8L * 1024 * 1024 * 1024 * 1024); private final long bits; SizeUnit(long bits) { this.bits = bits; }
Converts a size of the given unit into the current unit.
Params:
  • size – the magnitude of the size
  • unit – the unit of the size
Returns:the given size in the current unit.
/** * Converts a size of the given unit into the current unit. * * @param size the magnitude of the size * @param unit the unit of the size * @return the given size in the current unit. */
public long convert(long size, SizeUnit unit) { return (size * unit.bits) / bits; }
Converts the given number of the current units into bytes.
Params:
  • l – the magnitude of the size in the current unit
Returns:l of the current units in bytes
/** * Converts the given number of the current units into bytes. * * @param l the magnitude of the size in the current unit * @return {@code l} of the current units in bytes */
public long toBytes(long l) { return BYTES.convert(l, this); }
Converts the given number of the current units into kilobytes.
Params:
  • l – the magnitude of the size in the current unit
Returns:l of the current units in kilobytes
/** * Converts the given number of the current units into kilobytes. * * @param l the magnitude of the size in the current unit * @return {@code l} of the current units in kilobytes */
public long toKilobytes(long l) { return KILOBYTES.convert(l, this); }
Converts the given number of the current units into megabytes.
Params:
  • l – the magnitude of the size in the current unit
Returns:l of the current units in megabytes
/** * Converts the given number of the current units into megabytes. * * @param l the magnitude of the size in the current unit * @return {@code l} of the current units in megabytes */
public long toMegabytes(long l) { return MEGABYTES.convert(l, this); }
Converts the given number of the current units into gigabytes.
Params:
  • l – the magnitude of the size in the current unit
Returns:l of the current units in bytes
/** * Converts the given number of the current units into gigabytes. * * @param l the magnitude of the size in the current unit * @return {@code l} of the current units in bytes */
public long toGigabytes(long l) { return GIGABYTES.convert(l, this); }
Converts the given number of the current units into terabytes.
Params:
  • l – the magnitude of the size in the current unit
Returns:l of the current units in terabytes
/** * Converts the given number of the current units into terabytes. * * @param l the magnitude of the size in the current unit * @return {@code l} of the current units in terabytes */
public long toTerabytes(long l) { return TERABYTES.convert(l, this); } }