public final class BytesTransformers extends Object
BytesTransformer
for more specific use casesModifier and Type | Class and Description |
---|---|
static class |
BytesTransformers.ChecksumTransformer
Adds or converts to arbitrary checksum
|
static class |
BytesTransformers.GzipCompressor
Byte compression with gzip
|
static class |
BytesTransformers.HmacTransformer
HMAC transformer
|
static class |
BytesTransformers.ShuffleTransformer
Shuffles the internal byte array
|
static class |
BytesTransformers.SortTransformer
Sorts the internal byte array with given
Comparator |
Modifier and Type | Method and Description |
---|---|
static BytesTransformer |
checksum(Checksum checksum,
BytesTransformers.ChecksumTransformer.Mode mode,
int checksumLengthByte)
Create a
BytesTransformer which transforms to 4 byte Crc32 checksum of given bytes |
static BytesTransformer |
checksumAppendCrc32()
Create a
BytesTransformer which appends 4 byte Crc32 checksum to given bytes |
static BytesTransformer |
checksumCrc32()
Create a
BytesTransformer which transforms to 4 byte Crc32 checksum of given bytes |
static BytesTransformer |
compressGzip()
Create a
BytesTransformer which gzip compresses the internal byte array |
static BytesTransformer |
decompressGzip()
Create a
BytesTransformer which gzip decompresses the internal byte array |
static BytesTransformer |
hmac(byte[] key,
String algorithmName)
Create a
BytesTransformer which returns the HMAC with given key, algorithm of the target byte array |
static BytesTransformer |
hmacSha1(byte[] key)
Create a
BytesTransformer which returns the HMAC-SHA1 with given key, of the target byte array |
static BytesTransformer |
hmacSha256(byte[] key)
Create a
BytesTransformer which returns the HMAC-SHA256 with given key, of the target byte array |
static BytesTransformer |
shuffle()
Create a
BytesTransformer which shuffles the individual bytes in an array
with an SecureRandom instance. |
static BytesTransformer |
shuffle(Random random)
Create a
BytesTransformer which shuffles the individual bytes in an array |
static BytesTransformer |
sort()
Create a
BytesTransformer which sorts the internal byte array with it's natural ordering treating
each byte as signed byte (-128...127). |
static BytesTransformer |
sort(Comparator<Byte> comparator)
Create a
BytesTransformer which sorts the internal byte array according to given comparator. |
static BytesTransformer |
sortUnsigned()
Create a
BytesTransformer which sorts the internal byte array with it's natural ordering treating
each byte as unsigned byte (0...255). |
public static BytesTransformer shuffle()
BytesTransformer
which shuffles the individual bytes in an array
with an SecureRandom
instance.public static BytesTransformer shuffle(Random random)
BytesTransformer
which shuffles the individual bytes in an arrayrandom
- to use for entropypublic static BytesTransformer sort()
BytesTransformer
which sorts the internal byte array with it's natural ordering treating
each byte as signed byte (-128...127). Using inplace sorting, this can be reasonable fast.public static BytesTransformer sortUnsigned()
BytesTransformer
which sorts the internal byte array with it's natural ordering treating
each byte as unsigned byte (0...255). That is, the byte string ff
sorts after 00
.
Note: this requires 2 copies of the internal array and a lot of unboxing due to
the fact that no primitives are not allowed as generic type arguments - so only use on small arrays.public static BytesTransformer sort(Comparator<Byte> comparator)
BytesTransformer
which sorts the internal byte array according to given comparator.
Note: this requires 2 copies of the internal array and a lot of unboxing due to
the fact that no primitives are not allowed as generic type arguments - so only use on small arrays.comparator
- to sort the bytespublic static BytesTransformer checksumAppendCrc32()
BytesTransformer
which appends 4 byte Crc32 checksum to given bytespublic static BytesTransformer checksumCrc32()
BytesTransformer
which transforms to 4 byte Crc32 checksum of given bytespublic static BytesTransformer checksum(Checksum checksum, BytesTransformers.ChecksumTransformer.Mode mode, int checksumLengthByte)
BytesTransformer
which transforms to 4 byte Crc32 checksum of given byteschecksum
- used algorithmmode
- mode (append or convert)checksumLengthByte
- the byte length of the checksum; the Checksum
class always returns 8 byte, but some
checksum algorithms (e.g. CRC32) only require smaller output. Must be between 1 and 8 byte.public static BytesTransformer compressGzip()
BytesTransformer
which gzip compresses the internal byte arrayIllegalStateException
- if compression was not possible (i.e. wrapped IOException
)public static BytesTransformer decompressGzip()
BytesTransformer
which gzip decompresses the internal byte arrayIllegalStateException
- if compression was not possible (i.e. wrapped IOException
)public static BytesTransformer hmacSha1(byte[] key)
BytesTransformer
which returns the HMAC-SHA1 with given key, of the target byte arraykey
- to use for HMACpublic static BytesTransformer hmacSha256(byte[] key)
BytesTransformer
which returns the HMAC-SHA256 with given key, of the target byte arraykey
- to use for HMACpublic static BytesTransformer hmac(byte[] key, String algorithmName)
BytesTransformer
which returns the HMAC with given key, algorithm of the target byte arraykey
- to use for HMACalgorithmName
- e.g. 'HmacSHA256' - check if the algorithm is supported on your JVM/runtimeCopyright © 2017–2018. All rights reserved.