Package org.apache.hadoop.util
Class CrcUtil
java.lang.Object
org.apache.hadoop.util.CrcUtil
@LimitedPrivate({"Common","HDFS","MapReduce","Yarn"})
@Unstable
public final class CrcUtil
extends Object
This class provides utilities for working with CRCs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompose(int crcA, int crcB, long lengthB, ToIntFunction<Long> mod) compose.static intcomposeWithMonomial(int crcA, int crcB, int monomial, ToIntFunction<Long> mod) composeWithMonomial.static intgetMonomial(long lengthBytes, ToIntFunction<Long> mod) Compute x^(lengthBytes* 8) modmod, wheremodis in "reversed" (little-endian) format such thatmod & 1represents x^31 and has an implicit term x^32.static byte[]intToBytes(int value) static intreadInt(byte[] buf, int offset) Reads 4-byte big-endian int value frombufstarting atoffset. buf.length must be greater than or equal to offset + 4.static StringtoMultiCrcString(byte[] bytes) For use with debug statements; verifies bytes.length on creation, expecting it to be divisible by CRC byte size, and returns a list of hex formatted values.static StringtoSingleCrcString(byte[] bytes) For use with debug statements; verifies bytes.length on creation, expecting it to represent exactly one CRC, and returns a hex formatted value.static voidwriteInt(byte[] buf, int offset, int value) Writes big-endian representation ofvalueintobufstarting atoffset. buf.length must be greater than or equal to offset + 4.
-
Field Details
-
MULTIPLICATIVE_IDENTITY
public static final int MULTIPLICATIVE_IDENTITY- See Also:
-
GZIP_POLYNOMIAL
public static final int GZIP_POLYNOMIAL- See Also:
-
CASTAGNOLI_POLYNOMIAL
public static final int CASTAGNOLI_POLYNOMIAL- See Also:
-
-
Method Details
-
getMonomial
Compute x^(lengthBytes* 8) modmod, wheremodis in "reversed" (little-endian) format such thatmod & 1represents x^31 and has an implicit term x^32.- Parameters:
lengthBytes- lengthBytes.mod- mod.- Returns:
- monomial.
-
composeWithMonomial
composeWithMonomial.- Parameters:
crcA- crcA.crcB- crcB.monomial- Precomputed x^(lengthBInBytes * 8) modmodmod- mod.- Returns:
- compose with monomial.
-
compose
compose.- Parameters:
crcA- crcA.crcB- crcB.lengthB- length of content corresponding tocrcB, in bytes.mod- mod.- Returns:
- compose result.
-
intToBytes
public static byte[] intToBytes(int value) - Parameters:
value- value.- Returns:
- 4-byte array holding the big-endian representation of
value.
-
writeInt
public static void writeInt(byte[] buf, int offset, int value) Writes big-endian representation ofvalueintobufstarting atoffset. buf.length must be greater than or equal to offset + 4.- Parameters:
buf- buf size.offset- offset.value- value.
-
readInt
public static int readInt(byte[] buf, int offset) Reads 4-byte big-endian int value frombufstarting atoffset. buf.length must be greater than or equal to offset + 4.- Parameters:
offset- offset.buf- buf.- Returns:
- int.
-
toSingleCrcString
For use with debug statements; verifies bytes.length on creation, expecting it to represent exactly one CRC, and returns a hex formatted value.- Parameters:
bytes- bytes.- Returns:
- a list of hex formatted values.
-
toMultiCrcString
For use with debug statements; verifies bytes.length on creation, expecting it to be divisible by CRC byte size, and returns a list of hex formatted values.- Parameters:
bytes- bytes.- Returns:
- a list of hex formatted values.
-