OpenNMS API 1.2.9

## org.opennms.protocols.ip
Class OC16ChecksumProducer

    java.lang.Object
      org.opennms.protocols.ip.OC16ChecksumProducer

public final class OC16ChecksumProducer
extends java.lang.Object

Produces a one's compliment 16-bit checksum from data that is "added" to the sum. The producer handles objects from 8-bits to 64-bit values.

Author:
  Brian Weaver

Field Summary
`private int` `m_cksum`
`private boolean` `m_finalized`

Constructor Summary
`OC16ChecksumProducer()` Default constructor.

Method Summary
`void` `add(byte b)` Adds the specified 8-bit value to the checksum.
`void` `add(byte a, byte b)` Adds the specified 8-bit values to the checksum.
`void` `add(int i)` Adds the specified 32-bit value to the checksum.
`void` `add(long l)` Adds the specified 64-bit value to the checksum.
`void` `add(short s)` Adds the specified 16-bit value to the checksum total.
`private static int` `byteToInt(byte b)` Converts a 8-bit value to a 32-bit integer value.
`private void` `finalizeSum()` Finalizes the result by adding the carried out bits back into the checksum.
`short` `getChecksum()` Returns the current checksum value that has been computed for the object.
`void` `reset()` Resets the object to a zero state.
`private static int` `shortToInt(short s)` Converts a 16-bit value to a 32-bit value.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### m_cksum

    private int m_cksum

### m_finalized

    private boolean m_finalized

Constructor Detail

### OC16ChecksumProducer

    public OC16ChecksumProducer()

  Default constructor.

Method Detail

### byteToInt

    private static int byteToInt(byte b)

  Converts a 8-bit value to a 32-bit integer value. The conversion is done in a unsigned fashion.

  Parameters:
    `b` - The 8-bit value to convert
  Returns:
    The converted 32-bit value

### shortToInt

    private static int shortToInt(short s)

  Converts a 16-bit value to a 32-bit value. The conversion is done in an unsigned fashion.

  Parameters:
    `s` - The 16-bit value to convert
  Returns:
    The converted 32-bit value

### finalizeSum

    private void finalizeSum()

  Finalizes the result by adding the carried out bits back into the checksum.

### add

    public void add(byte b)

  Adds the specified 8-bit value to the checksum. Since the checksum must be in 16-bits, the byte is copied to the upper 8-bits of the 16-bit value. The lower 8-bits are set to zero.

  Parameters:
    `b` - The 8-bit value to add to the checksum.

### add

    public void add(byte a,
                    byte b)

  Adds the specified 8-bit values to the checksum. The checksum is performed using 16-bit values, thus the first byte is places into the high 8-bits of the word. The second byte is placed into the lower 8-bits of the 16-bit word. Then the result is added to the 16-bit checksum.

  Parameters:
    `a` - The high order 8-bits
    `b` - The low order 8-bits

### add

    public void add(short s)

  Adds the specified 16-bit value to the checksum total.

  Parameters:
    `s` - The 16-bit value to add

### add

    public void add(int i)

  Adds the specified 32-bit value to the checksum. The 32-bit value is broken into two 16-bit values for the purpose of computing the checksum.

  Parameters:
    `i` - The 32-bit value.

### add

    public void add(long l)

  Adds the specified 64-bit value to the checksum. The 64-bit value is split into 4 16-bit quantities and added to the checksum.

  Parameters:
    `l` - The 64-bit value to add

### reset

    public void reset()

  Resets the object to a zero state.

### getChecksum

    public short getChecksum()

  Returns the current checksum value that has been computed for the object.

  Returns:
    The 16-bit ones compliment checksum

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.