Slice is a Java library for efficiently working with Java byte arrays. Slice provides fast and efficient
methods such as read a long
at an index without having to assemble the long
from individual bytes.
In addition to reading and writing single private values, there are methods to bulk transfer data to and
from primitive arrays.
Slice provides classes for interacting with InputStreams and OutputStreams. The classes support the same fast single primitive access and bulk transfer methods as the Slice class.
Slice provides a library for interacting UTF-8 data stored in byte arrays. The UTF-8 library provides functions to count code points, substring, trim, case change, and so on.
The Slice Library uses sun.misc.Unsafe
to bulk transfer data between byte arrays and other array types
directly as there is no other way to do this in Java today. The proposed Memory Access API (JEP 370) may
provide support for this feature, and assuming performance is good, this library will be updated to use
once it is available. Due to the direct usage of Unsafe, this library can only be used on a little endian
CPU.
Version of Slice before 2.0 support off-heap memory and can be backed by any Java primitive array type. These features were rarely used, and were removed in version 2.0 to simplify the codebase. If you need these versions, they are available in the release-0.x branch.