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.Checksum
CRC-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.
-
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.
-
-
-
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
-
-