@Test public void testBulkOps() throws Exception { for (DataChecksum.Type type : CHECKSUM_TYPES) { System.err.println( "---- beginning tests with checksum type " + type + "----"); DataChecksum checksum = DataChecksum.newDataChecksum( type, BYTES_PER_CHUNK); for (boolean useDirect : new boolean[]{false, true}) { doBulkTest(checksum, 1023, useDirect); doBulkTest(checksum, 1024, useDirect); doBulkTest(checksum, 1025, useDirect); } } }
public static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ) { if ( bytesPerChecksum <= 0 ) { return null; } switch ( type ) { case NULL : return new DataChecksum(type, new ChecksumNull(), bytesPerChecksum ); case CRC32 : return new DataChecksum(type, newCrc32(), bytesPerChecksum ); case CRC32C: return new DataChecksum(type, new PureJavaCrc32C(), bytesPerChecksum); default: return null; } }
DataChecksum implements Checksum { public static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ) { if ( bytesPerChecksum <= 0 ) { return null; } switch ( type ) { case NULL : return new DataChecksum(type, new ChecksumNull(), bytesPerChecksum ); case CRC32 : return new DataChecksum(type, newCrc32(), bytesPerChecksum ); case CRC32C: return new DataChecksum(type, new PureJavaCrc32C(), bytesPerChecksum); default: return null; } } }
DataChecksum implements Checksum { public static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ) { if ( bytesPerChecksum <= 0 ) { return null; } switch ( type ) { case NULL : return new DataChecksum(type, new ChecksumNull(), bytesPerChecksum ); case CRC32 : return new DataChecksum(type, newCrc32(), bytesPerChecksum ); case CRC32C: return new DataChecksum(type, new PureJavaCrc32C(), bytesPerChecksum); default: return null; } } private  DataChecksum( Type type, Checksum checksum, int chunkSize ); }
DataChecksum implements Checksum { public static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ) { if ( bytesPerChecksum <= 0 ) { return null; } switch ( type ) { case NULL : return new DataChecksum(type, new ChecksumNull(), bytesPerChecksum ); case CRC32 : return new DataChecksum(type, newCrc32(), bytesPerChecksum ); case CRC32C: return new DataChecksum(type, new PureJavaCrc32C(), bytesPerChecksum); default: return null; } } private  DataChecksum( Type type, Checksum checksum, int chunkSize ); static Checksum newCrc32(); static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ); static DataChecksum newDataChecksum( byte bytes[], int offset ); static DataChecksum newDataChecksum( DataInputStream in ); void writeHeader( DataOutputStream out ); byte[] getHeader(); int writeValue( DataOutputStream out, boolean reset ); int writeValue( byte[] buf, int offset, boolean reset ); boolean compare( byte buf[], int offset ); Type getChecksumType(); int getChecksumSize(); int getBytesPerChecksum(); int getNumBytesInSum(); static int getChecksumHeaderSize(); @Override long getValue(); @Override void reset(); @Override void update( byte[] b, int off, int len ); @Override void update( int b ); void verifyChunkedSums(ByteBuffer data, ByteBuffer checksums,
      String fileName, long basePos); void calculateChunkedSums(ByteBuffer data, ByteBuffer checksums); void calculateChunkedSums(
      byte[] data, int dataOffset, int dataLength,
      byte[] sums, int sumsOffset); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); }
DataChecksum implements Checksum { public static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ) { if ( bytesPerChecksum <= 0 ) { return null; } switch ( type ) { case NULL : return new DataChecksum(type, new ChecksumNull(), bytesPerChecksum ); case CRC32 : return new DataChecksum(type, newCrc32(), bytesPerChecksum ); case CRC32C: return new DataChecksum(type, new PureJavaCrc32C(), bytesPerChecksum); default: return null; } } private  DataChecksum( Type type, Checksum checksum, int chunkSize ); static Checksum newCrc32(); static DataChecksum newDataChecksum(Type type, int bytesPerChecksum ); static DataChecksum newDataChecksum( byte bytes[], int offset ); static DataChecksum newDataChecksum( DataInputStream in ); void writeHeader( DataOutputStream out ); byte[] getHeader(); int writeValue( DataOutputStream out, boolean reset ); int writeValue( byte[] buf, int offset, boolean reset ); boolean compare( byte buf[], int offset ); Type getChecksumType(); int getChecksumSize(); int getBytesPerChecksum(); int getNumBytesInSum(); static int getChecksumHeaderSize(); @Override long getValue(); @Override void reset(); @Override void update( byte[] b, int off, int len ); @Override void update( int b ); void verifyChunkedSums(ByteBuffer data, ByteBuffer checksums,
      String fileName, long basePos); void calculateChunkedSums(ByteBuffer data, ByteBuffer checksums); void calculateChunkedSums(
      byte[] data, int dataOffset, int dataLength,
      byte[] sums, int sumsOffset); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); static final int HEADER_LEN; static final int CHECKSUM_NULL; static final int CHECKSUM_CRC32; static final int CHECKSUM_CRC32C; static final int CHECKSUM_DEFAULT; static final int CHECKSUM_MIXED; static final int SIZE_OF_INTEGER; }