DataSize

A utility library for working with units of digital information

License

License

Categories

Categories

Data
GroupId

GroupId

io.aesy
ArtifactId

ArtifactId

datasize
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

DataSize
A utility library for working with units of digital information
Project URL

Project URL

https://github.com/aesy/datasize
Source Code Management

Source Code Management

https://github.com/aesy/datasize

Download datasize

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
javax.validation : validation-api jar 2.0.1.Final
com.github.petitparser : petitparser-core jar 2.2.0

test (4)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.0
org.junit.jupiter : junit-jupiter-params jar 5.4.0
org.junit.jupiter : junit-jupiter-engine jar 5.4.0
org.assertj : assertj-core jar 3.12.1

Project Modules

There are no modules declared in this project.

DataSize

maven-central Build Status Coverage Status MIT license

A small utility library for working with units of digital information, featuring:

  • Conversion
  • Comparison
  • Parsing
  • Formatting

Built for Java 8+.

API Reference

Usage

The DataSize class is the main focus of the library. It's an immutable container of a number and a unit.

DataSize fromDouble = DataSize.of(Math.PI, ByteUnit.SI.GIBIBYTE);
DataSize fromBigDecimal = DataSize.of(BigDecimal.valueOf(Math.PI), ByteUnit.SI.GIBIBYTE); 
DataSize fromString = DataSize.parse("3.14 GiB"); 

It features simple & convenient methods for conversion, formatting and parsing:

// Conversion
DataSize withNaturalUnit = DataSize.of(1024, ByteUnit.BYTE).toNaturalUnit(); 
assertEquals(withNaturalUnit.getUnit(), ByteUnit.IEC.KIBIBYTE);

DataSize dataSize = DataSize.of(1024, ByteUnit.BYTE).toUnit(ByteUnit.SI.KILOBYTE);
assertEquals(dataSize.getValue(), BigDecimal.valueOf(1.024));

// Formatting
DataSize dataSize = DataSize.of(1000, ByteUnit.BYTE); 
String formatted = dataSize.toString(); 
assertEquals(formatted, "1 kB");

// Parsing
DataSize oneByte = DataSize.parse("1 B"); 
DataSize twoByte = DataSize.parse("2B"); 

See the JavaDoc for each class for detailed usage.

Installation

Using Gradle, add this to your build script:

repositories {
    mavenCentral()
}
dependencies {
    compile 'io.aesy:datasize:1.0.0'
}

Using Maven, add this to your list of dependencies in pom.xml:

<dependency>
  <groupId>io.aesy</groupId>
  <artifactId>datasize</artifactId>
  <version>1.0.0</version>
</dependency>

Contribute

Use the issue tracker to report bugs or make feature requests. Pull requests are welcome, but it may be a good idea to create an issue to discuss any changes beforehand.

License

MIT, see LICENSE file.

Versions

Version
1.0.0