bytesize

A simple Java utility for formatting and parsing data sizes.

License

License

GroupId

GroupId

org.codeswarm
ArtifactId

ArtifactId

bytesize
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

bytesize
A simple Java utility for formatting and parsing data sizes.
Project URL

Project URL

https://github.com/codeswarm/bytesize
Source Code Management

Source Code Management

https://github.com/codeswarm/bytesize

Download bytesize

How to add to project

<!-- https://jarcasting.com/artifacts/org.codeswarm/bytesize/ -->
<dependency>
    <groupId>org.codeswarm</groupId>
    <artifactId>bytesize</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.codeswarm/bytesize/
implementation 'org.codeswarm:bytesize:1.0'
// https://jarcasting.com/artifacts/org.codeswarm/bytesize/
implementation ("org.codeswarm:bytesize:1.0")
'org.codeswarm:bytesize:jar:1.0'
<dependency org="org.codeswarm" name="bytesize" rev="1.0">
  <artifact name="bytesize" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.codeswarm', module='bytesize', version='1.0')
)
libraryDependencies += "org.codeswarm" % "bytesize" % "1.0"
[org.codeswarm/bytesize "1.0"]

Dependencies

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.2.1

Project Modules

There are no modules declared in this project.

bytesize

A Java utility for dealing with data sizes. Supports internationalized formatting and parsing.

Example usage

import org.codeswarm.bytesize.*;

public class ByteSizeDemo {

  public static void main(String[] args) throws java.text.ParseException {

    // Create a new byte size format using the default locale and settings.
    ByteSizeFormat format = new ByteSizeFormatBuilder().build();

    // Parse a byte size string.
    ByteSize a = format.parse(".85 gigabytes");

    // Convert 0.85 gigabytes to megabytes. Prints "850.0".
    System.out.println(a.numberOfBytes(ByteSizeUnits.MB));

    // Create a ByteSize object representing 1500 bytes.
    ExactByteSize b = ByteSizes.byteSize(1500);

    // Get the number of bytes. Prints "1500".
    System.out.println(b.numberOfBytes());

    // Format the size using abbreviated units. Prints "1.5 kB".
    System.out.println(format.format(b, ByteSizeFormat.WordLength.ABBREVIATION));

    // Create a new formatter for the Slovak language using IEC units (powers of 2)
    ByteSizeFormat format2 = new ByteSizeFormatBuilder()
      .unitSystem(ByteSizeUnits.IEC)
      .locale(java.util.Locale.forLanguageTag("sk"))
      .build();

    // Format the first size using full words.
    // Prints "810,623 mebibajtov" (810.623 mebibytes).
    System.out.println(format2.format(a, ByteSizeFormat.WordLength.FULL));

  }

}

Download

Bytesize is available from Maven Central. The latest version is 1.0.

<dependency>
  <groupId>org.codeswarm</groupId>
  <artifactId>bytesize</artifactId>
  <version>1.0</version>
</dependency>

Language support

  • English
  • Slovak
  • Esperanto

If your language is missing from this list, please leave us a note in the issue tracker.

org.codeswarm

Codeswarm

Versions

Version
1.0