Package org.apache.commons.codec.digest
Class Crc16
- java.lang.Object
-
- org.apache.commons.codec.digest.Crc16
-
- All Implemented Interfaces:
java.util.zip.Checksum
public final class Crc16 extends java.lang.Object implements java.util.zip.ChecksumCRC-16 checksum implementations you can customize with a table and init value.Since there are so many CRC-16 variants, we do not pick a default.
For example, to create a create a custom variant of CRC16-MODBUS with an init value of
0x0000, use:Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCrc16.BuilderBuildsCrc16instances.
-
Field Summary
Fields Modifier and Type Field Description private static int[]ARCprivate static intARC_INITprivate static int[]CCITTprivate static intCCITT_INITprivate intcrcCRC.private static int[]DNPprivate static intDNP_INITprivate static intDNP_XOROUTprivate static int[]IBM_SDLCprivate static intIBM_SDLC_INITprivate static intIBM_SDLC_XOROUTprivate intinitprivate static int[]MAXIMprivate static intMAXIM_INITprivate static intMAXIM_XOROUTprivate static int[]MCRF4XXprivate static intMCRF4XX_INITprivate static int[]MODBUSprivate static intMODBUS_INITprivate static int[]NRSC5private static intNRSC5_INITprivate int[]tableprivate static int[]USBprivate static intUSB_INITprivate static intUSB_XOROUTprivate intxorOut
-
Constructor Summary
Constructors Modifier Constructor Description privateCrc16(Crc16.Builder builder)Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Crc16arc()Creates a new CRC16-CCITT Checksum.static Crc16.Builderbuilder()Creates a new builder.static Crc16ccitt()Creates a new CRC16-CCITT Checksum.static Crc16dnp()Creates a new CRC16-DNP Checksum.static int[]getArcTable()Gets a copy of the CRC16-CCITT table.static int[]getCcittTable()Gets a copy of the CRC16-CCITT table.static int[]getDnpTable()Gets a copy of the CRC16-DNP table.static int[]getIbmSdlcTable()Gets a copy of the CRC16-IBM-SDLC table.static int[]getMaximTable()Gets a copy of the CRC16-MAXIM table.static int[]getMcrf4xxTable()Gets a copy of the CRC16-MCRF4XX table.static int[]getModbusTable()Gets a copy of the CRC16-MODBUS table.static int[]getNrsc5Table()Gets a copy of the CRC16-NRSC-5 table.longgetValue()static Crc16ibmSdlc()Creates a new CRC16-IBM-SDLC Checksum.static Crc16maxim()Creates a new instance for CRC16-MAXIM Checksum.static Crc16mcrf4xx()Creates a new instance for CRC16-MCRF4XX Checksum.static Crc16modbus()Creates a new instance for CRC16-MODBUS Checksum.static Crc16nrsc5()Creates a new instance for CRC16-NRSC-5 Checksum.voidreset()java.lang.StringtoString()voidupdate(byte[] b, int off, int len)voidupdate(int b)static Crc16usb()Creates a new instance for CRC16-USB Checksum.
-
-
-
Field Detail
-
ARC
private static final int[] ARC
-
ARC_INIT
private static final int ARC_INIT
- See Also:
- Constant Field Values
-
CCITT
private static final int[] CCITT
-
CCITT_INIT
private static final int CCITT_INIT
- See Also:
- Constant Field Values
-
DNP
private static final int[] DNP
-
DNP_INIT
private static final int DNP_INIT
- See Also:
- Constant Field Values
-
DNP_XOROUT
private static final int DNP_XOROUT
- See Also:
- Constant Field Values
-
IBM_SDLC
private static final int[] IBM_SDLC
-
IBM_SDLC_INIT
private static final int IBM_SDLC_INIT
- See Also:
- Constant Field Values
-
IBM_SDLC_XOROUT
private static final int IBM_SDLC_XOROUT
- See Also:
- Constant Field Values
-
MAXIM
private static final int[] MAXIM
-
MAXIM_INIT
private static final int MAXIM_INIT
- See Also:
- Constant Field Values
-
MAXIM_XOROUT
private static final int MAXIM_XOROUT
- See Also:
- Constant Field Values
-
MCRF4XX
private static final int[] MCRF4XX
-
MCRF4XX_INIT
private static final int MCRF4XX_INIT
- See Also:
- Constant Field Values
-
MODBUS
private static final int[] MODBUS
-
MODBUS_INIT
private static final int MODBUS_INIT
- See Also:
- Constant Field Values
-
NRSC5
private static final int[] NRSC5
-
NRSC5_INIT
private static final int NRSC5_INIT
- See Also:
- Constant Field Values
-
USB
private static final int[] USB
-
USB_INIT
private static final int USB_INIT
- See Also:
- Constant Field Values
-
USB_XOROUT
private static final int USB_XOROUT
- See Also:
- Constant Field Values
-
crc
private int crc
CRC.
-
init
private final int init
-
table
private final int[] table
-
xorOut
private final int xorOut
-
-
Constructor Detail
-
Crc16
private Crc16(Crc16.Builder builder)
Constructs a new instance.
-
-
Method Detail
-
arc
public static Crc16 arc()
Creates a new CRC16-CCITT Checksum.- The init value is
0x0000. - The XorOut value is
0x0000.
Also known as:
- CRC-16/ARC
- ARC
- CRC-16
- CRC-16/LHA
- CRC-IBM
- Returns:
- a new CRC16-CCITT Checksum.
- The init value is
-
builder
public static Crc16.Builder builder()
Creates a new builder.Since there are so many CRC-16 variants, we do not pick a default.
- Returns:
- a new builder.
-
ccitt
public static Crc16 ccitt()
Creates a new CRC16-CCITT Checksum.- The init value is
0x0000. - The XorOut value is
0x0000.
Also known as:
- CRC-16/KERMIT
- CRC-16/BLUETOOTH
- CRC-16/CCITT
- CRC-16/CCITT-TRUE
- CRC-16/V-41-LSB
- CRC-CCITT
- KERMIT
- Returns:
- a new CRC16-CCITT Checksum.
- The init value is
-
dnp
public static Crc16 dnp()
Creates a new CRC16-DNP Checksum.- The init value is
0x0000. - The XorOut value is
0xFFFF.
- Returns:
- a new CRC16-DNP Checksum.
- The init value is
-
getArcTable
public static int[] getArcTable()
Gets a copy of the CRC16-CCITT table.- Returns:
- a copy of the CCRC16-CITT table.
-
getCcittTable
public static int[] getCcittTable()
Gets a copy of the CRC16-CCITT table.- Returns:
- a copy of the CCRC16-CITT table.
-
getDnpTable
public static int[] getDnpTable()
Gets a copy of the CRC16-DNP table.- Returns:
- a copy of the CCRC16-DNP table.
-
getIbmSdlcTable
public static int[] getIbmSdlcTable()
Gets a copy of the CRC16-IBM-SDLC table.- Returns:
- a copy of the CRC16-IBM-SDLC table.
-
getMaximTable
public static int[] getMaximTable()
Gets a copy of the CRC16-MAXIM table.- Returns:
- a copy of the CRC16-MAXIM table.
-
getMcrf4xxTable
public static int[] getMcrf4xxTable()
Gets a copy of the CRC16-MCRF4XX table.- Returns:
- a copy of the CRC16-MCRF4XX table.
-
getModbusTable
public static int[] getModbusTable()
Gets a copy of the CRC16-MODBUS table.- Returns:
- a copy of the CRC16-MODBUS table.
-
getNrsc5Table
public static int[] getNrsc5Table()
Gets a copy of the CRC16-NRSC-5 table.- Returns:
- a copy of the CRC16-NRSC-5 table.
-
ibmSdlc
public static Crc16 ibmSdlc()
Creates a new CRC16-IBM-SDLC Checksum.- The init value is
0xFFFF. - The XorOut value is
0xFFFF.
Also known as:
- CRC-16/IBM-SDLC
- CRC-16/ISO-HDLC
- CRC-16/ISO-IEC-14443-3-B
- CRC-16/X-25
- CRC-B
- X-25
- Returns:
- a new CRC16-IBM-SDLC Checksum.
- The init value is
-
maxim
public static Crc16 maxim()
Creates a new instance for CRC16-MAXIM Checksum.CRC-16 checksum implementation based on polynomial
x<sup>16</spu> + x^15 + x^2 + 1 (0x8005).- The init value is
0xFFFF. - The XorOut value is
0xFFFF.
Also known as:
- CRC-16/MAXIM-DOW
- Returns:
- a new CRC16-MAXIM Checksum.
- The init value is
-
mcrf4xx
public static Crc16 mcrf4xx()
Creates a new instance for CRC16-MCRF4XX Checksum.- The init value is
0xFFFF. - The XorOut value is
0x0000.
- Returns:
- a new CRC16-MCRF4XX Checksum.
- The init value is
-
modbus
public static Crc16 modbus()
Creates a new instance for CRC16-MODBUS Checksum.CRC-16 checksum implementation based on polynomial
x<sup>16</spu> + x^15 + x^2 + 1 (0x8005).- The init value is
0xFFFF. - The XorOut value is
0x0000.
Also known as:
- CRC-16/MODBUST
- MODBUST
- Returns:
- a new CRC16-MODBUS Checksum.
- The init value is
-
nrsc5
public static Crc16 nrsc5()
Creates a new instance for CRC16-NRSC-5 Checksum.- The init value is
0xFFFF. - The XorOut value is
0x0000.
- Returns:
- a new CRC16-NRSC-5 Checksum.
- The init value is
-
usb
public static Crc16 usb()
Creates a new instance for CRC16-USB Checksum.- The init value is
0xFFFF. - The XorOut value is
0xFFFF.
- Returns:
- a new CRC16-USB Checksum.
- The init value is
-
getValue
public long getValue()
- Specified by:
getValuein interfacejava.util.zip.Checksum
-
reset
public void reset()
- Specified by:
resetin interfacejava.util.zip.Checksum
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
update
public void update(byte[] b, int off, int len)- Specified by:
updatein interfacejava.util.zip.Checksum
-
update
public void update(int b)
- Specified by:
updatein interfacejava.util.zip.Checksum
-
-