Byte Units
Utility classes for converting between granularities of SI and IEC byte units
and bit units.
Example Usage
What's the difference in hard drive space between perception and actual?
long perception = BinaryByteUnit.TEBIBYTES.toBytes(2);
long usable = DecimalByteUnit.TERABYTES.toBytes(2);
long lost = BinaryByteUnit.BYTES.toGibibytes(perception - usable);
System.out.println(lost + " GiB lost on a 2TB drive.");
Method parameter for specifying a resource size.
public void installDiskCache(long count, ByteUnit unit) {
long size = unit.toBytes(count);
}
Print human-readable strings for byte and bit amounts.
long bytes = 2 * 1024 * 1024 * 1024;
System.out.println(BinaryByteUnit.format(bytes));
Download
Grab the latest .jar or add via Gradle:
compile 'com.jakewharton.byteunits:byteunits:0.9.1'
or Maven:
<dependency>
<groupId>com.jakewharton.byteunits</groupId>
<artifactId>byteunits</artifactId>
<version>0.9.1</version>
</dependency>
Snapshots of the development version are available in Sonatype's snapshots repository.
License
Copyright 2014 Jake Wharton
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.