Skip to content
/ datasize Public

A Java 8+ utility library for working with units of digital information

License

Notifications You must be signed in to change notification settings

aesy/datasize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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+.

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.

About

A Java 8+ utility library for working with units of digital information

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages