Byte Units

Utility classes for converting between granularities of SI and IEC byte units and bit units.

License

License

GroupId

GroupId

com.jakewharton.byteunits
ArtifactId

ArtifactId

byteunits
Last Version

Last Version

0.9.1
Release Date

Release Date

Type

Type

jar
Description

Description

Byte Units
Utility classes for converting between granularities of SI and IEC byte units and bit units.
Source Code Management

Source Code Management

http://github.com/JakeWharton/byteunits

Download byteunits

How to add to project

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

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

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);
  // TODO Install disk cache of 'size' bytes.
}

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 with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.9.1
0.9.0