org.apache.hadoop.util
Class DataChecksum

java.lang.Object
  extended by org.apache.hadoop.util.DataChecksum
All Implemented Interfaces:
Checksum

public class DataChecksum
extends Object
implements Checksum

This class provides inteface and utilities for processing checksums for DFS data transfers.


Field Summary
static int CHECKSUM_CRC32
           
static int CHECKSUM_NULL
           
static int HEADER_LEN
           
static int SIZE_OF_INTEGER
           
 
Method Summary
 boolean compare(byte[] buf, int offset)
          Compares the checksum located at buf[offset] with the current checksum.
 int getBytesPerChecksum()
           
static int getChecksumHeaderSize()
           
 int getChecksumSize()
           
 int getChecksumType()
           
 byte[] getHeader()
           
 int getNumBytesInSum()
           
 long getValue()
           
static DataChecksum newDataChecksum(byte[] bytes, int offset)
          Creates a DataChecksum from HEADER_LEN bytes from arr[offset].
static DataChecksum newDataChecksum(DataInputStream in)
          This constructucts a DataChecksum by reading HEADER_LEN bytes from input stream in
static DataChecksum newDataChecksum(int type, int bytesPerChecksum)
           
 void reset()
           
 void update(byte[] b, int off, int len)
           
 void update(int b)
           
 void writeHeader(DataOutputStream out)
          Writes the checksum header to the output stream out.
 int writeValue(byte[] buf, int offset, boolean reset)
          Writes the current checksum to a buffer.
 int writeValue(DataOutputStream out, boolean reset)
          Writes the current checksum to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_LEN

public static final int HEADER_LEN
See Also:
Constant Field Values

CHECKSUM_NULL

public static final int CHECKSUM_NULL
See Also:
Constant Field Values

CHECKSUM_CRC32

public static final int CHECKSUM_CRC32
See Also:
Constant Field Values

SIZE_OF_INTEGER

public static final int SIZE_OF_INTEGER
See Also:
Constant Field Values
Method Detail

newDataChecksum

public static DataChecksum newDataChecksum(int type,
                                           int bytesPerChecksum)

newDataChecksum

public static DataChecksum newDataChecksum(byte[] bytes,
                                           int offset)
Creates a DataChecksum from HEADER_LEN bytes from arr[offset].

Returns:
DataChecksum of the type in the array or null in case of an error.

newDataChecksum

public static DataChecksum newDataChecksum(DataInputStream in)
                                    throws IOException
This constructucts a DataChecksum by reading HEADER_LEN bytes from input stream in

Throws:
IOException

writeHeader

public void writeHeader(DataOutputStream out)
                 throws IOException
Writes the checksum header to the output stream out.

Throws:
IOException

getHeader

public byte[] getHeader()

writeValue

public int writeValue(DataOutputStream out,
                      boolean reset)
               throws IOException
Writes the current checksum to the stream. If reset is true, then resets the checksum.

Returns:
number of bytes written. Will be equal to getChecksumSize();
Throws:
IOException

writeValue

public int writeValue(byte[] buf,
                      int offset,
                      boolean reset)
               throws IOException
Writes the current checksum to a buffer. If reset is true, then resets the checksum.

Returns:
number of bytes written. Will be equal to getChecksumSize();
Throws:
IOException

compare

public boolean compare(byte[] buf,
                       int offset)
Compares the checksum located at buf[offset] with the current checksum.

Returns:
true if the checksum matches and false otherwise.

getChecksumType

public int getChecksumType()

getChecksumSize

public int getChecksumSize()

getBytesPerChecksum

public int getBytesPerChecksum()

getNumBytesInSum

public int getNumBytesInSum()

getChecksumHeaderSize

public static int getChecksumHeaderSize()

getValue

public long getValue()
Specified by:
getValue in interface Checksum

reset

public void reset()
Specified by:
reset in interface Checksum

update

public void update(byte[] b,
                   int off,
                   int len)
Specified by:
update in interface Checksum

update

public void update(int b)
Specified by:
update in interface Checksum


Copyright © 2009 The Apache Software Foundation