|
1 | | -# Bytes Java |
| 1 | +# Bytes |
| 2 | + |
| 3 | +Bytes is a utility library that makes it easy to **create**, **parse**, **transform**, |
| 4 | +**validate** and **convert** byte arrays in Java. It's main class `Bytes` is |
| 5 | +a collections of bytes and the main API. It supports [endianness](https://en.wikipedia.org/wiki/Endianness) |
| 6 | +as well as **immutability** and **mutability**, so the caller may decide to favor |
| 7 | +performance. This can be seen as combination of the features provided by |
| 8 | +[`BigInteger`](https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html), |
| 9 | +[`ByteBuffer`](https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html) but |
| 10 | +providing a lot of additional features. |
2 | 11 |
|
3 | 12 | [](https://bintray.com/patrickfav/maven/bytes-java/_latestVersion) |
4 | 13 | [](https://travis-ci.org/patrickfav/bytes-java) |
5 | 14 | [](https://www.javadoc.io/doc/at.favre.lib/bytes) |
6 | 15 | [](https://coveralls.io/github/patrickfav/bytes-java?branch=master) |
7 | 16 |
|
| 17 | +It's main features include: |
| 18 | + |
| 19 | +* **Creation** from a wide variety of sources: multiple arrays, integers, streams, random, files, ... |
| 20 | +* **Transformation** with many built-in: append, xor, and, or, shifts, shuffle, reverse, sort, ... |
| 21 | +* **Validators** with the ability to arbitrarily combine multiple ones |
| 22 | +* **Parsing and Encoding** in most common binary-to-text-encodings: [hex](https://en.wikipedia.org/wiki/Hexadecimal), [base64](https://en.wikipedia.org/wiki/Base64), ... |
| 23 | +* **Immutable, Mutable and Read-Only** versions |
| 24 | +* **Utility Features** like `indexOf`, `count`, `isEmpty`, `byteAt`, ... |
| 25 | + |
| 26 | +It is written in Java 7 to keep backwards compatibility with *Android* and older *Java* applications. |
| 27 | + |
| 28 | +## Quickstart |
| 29 | + |
| 30 | +Add dependency to your `pom.xml`: |
| 31 | + |
| 32 | + <dependency> |
| 33 | + <groupId>at.favre.lib</groupId> |
| 34 | + <artifactId>bytes</artifactId> |
| 35 | + <version>{latest-version}</version> |
| 36 | + </dependency> |
| 37 | + |
| 38 | +A very simple example: |
| 39 | + |
| 40 | +```java |
| 41 | +Bytes b = Bytes.wrap(someByteArray); //reuse given reference |
| 42 | +b.copy().reverse(); //reverse the bytes on a copied instance |
| 43 | +String hex = b.encodeHex(); //encode base16/hex |
| 44 | +``` |
8 | 45 |
|
9 | 46 | ## API Description |
10 | 47 |
|
@@ -41,7 +78,7 @@ The following code is equivalent: |
41 | 78 | Bytes.wrap(myArray).copy() ~ Bytes.from(myArray) |
42 | 79 | ``` |
43 | 80 |
|
44 | | -### More Constructors |
| 81 | +#### More Constructors |
45 | 82 |
|
46 | 83 | **Concatenating** of multiple byte arrays or bytes: |
47 | 84 |
|
|
0 commit comments