com.bigdata.util
Class ChecksumUtility

java.lang.Object
  extended by com.bigdata.util.ChecksumUtility

public class ChecksumUtility
extends Object

Utility class for computing the Adler32 checksum of a buffer. This class is NOT thread-safe.

Version:
$Id: ChecksumUtility.java 4069 2011-01-09 20:58:02Z thompsonbry $
Author:
Bryan Thompson
TODO:
This could stand some review in its API and its usage.

Field Summary
protected  Adler32 chk
          Used to compute the checksums.
static ThreadLocal<ChecksumUtility> threadChk
          ThreadLocal ChecksumUtility factory.
 
Constructor Summary
ChecksumUtility()
           
 
Method Summary
 int checksum(byte[] buf)
           
 int checksum(byte[] buf, int sze)
           
 int checksum(byte[] buf, int off, int sze)
           
 int checksum(ByteBuffer buf)
          Compute the Adler32 checksum of the buffer.
 int checksum(ByteBuffer buf, int pos, int limit)
          Compute the Adler32 checksum of the buffer.
 int checksum(IByteArraySlice slice)
           
protected  int getChecksum()
          Return the Alder checksum, which is a 32bit value.
static ChecksumUtility getCHK()
          Deprecated. Use threadChk and ThreadLocal.get().
protected  void reset()
          Reset the checksum.
protected  void update(ByteBuffer buf)
          Updates the Adler32 checksum from the data in the buffer.
protected  void update(ByteBuffer buf, int pos, int limit)
          Core implementation updates the Adler32 checksum from the data in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadChk

public static final ThreadLocal<ChecksumUtility> threadChk
ThreadLocal ChecksumUtility factory.


chk

protected final Adler32 chk
Used to compute the checksums. Exposed to subclasses so they can update the checksum for additional fields.

Constructor Detail

ChecksumUtility

public ChecksumUtility()
Method Detail

getCHK

public static ChecksumUtility getCHK()
Deprecated. Use threadChk and ThreadLocal.get().

static access to a ThreadLocal Checksum utility

Returns:
the ChecksumUtility

checksum

public int checksum(ByteBuffer buf)
Compute the Adler32 checksum of the buffer. The position, mark, and limit are unchanged by this operation. The operation is optimized when the buffer is backed by an array.

Parameters:
buf - The buffer.
Returns:
The checksum.

checksum

public int checksum(ByteBuffer buf,
                    int pos,
                    int limit)
Compute the Adler32 checksum of the buffer. The position, mark, and limit are unchanged by this operation. The operation is optimized when the buffer is backed by an array.

Parameters:
buf - The buffer.
pos - The starting position.
limit - The limit.
Returns:
The checksum.
TODO:
why pass in the pos/lim when [buf] could incorporate them?

reset

protected void reset()
Reset the checksum.


getChecksum

protected int getChecksum()
Return the Alder checksum, which is a 32bit value.


update

protected void update(ByteBuffer buf)
Updates the Adler32 checksum from the data in the buffer. The position, mark, and limit are unchanged by this operation. The operation is optimized when the buffer is backed by an array.

Parameters:
buf -

update

protected void update(ByteBuffer buf,
                      int pos,
                      int limit)
Core implementation updates the Adler32 checksum from the data in the buffer. The position, mark, and limit are unchanged by this operation. The operation is optimized when the buffer is backed by an array.

Parameters:
buf -
pos -
limit -

checksum

public int checksum(IByteArraySlice slice)

checksum

public int checksum(byte[] buf)

checksum

public int checksum(byte[] buf,
                    int sze)

checksum

public int checksum(byte[] buf,
                    int off,
                    int sze)


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.