public virtual void TestVerifyChunkedSumsByteArraySuccess() { AllocateArrayByteBuffers(); FillDataAndValidChecksums(); NativeCrc32.VerifyChunkedSumsByteArray(bytesPerChecksum, checksumType.id, ((byte[] )checksums.Array()), checksums.Position(), ((byte[])data.Array()), data.Position (), data.Remaining(), fileName, BasePosition); }
public virtual void TestVerifyChunkedSumsByteArrayFail() { AllocateArrayByteBuffers(); FillDataAndInvalidChecksums(); exception.Expect(typeof(ChecksumException)); NativeCrc32.VerifyChunkedSumsByteArray(bytesPerChecksum, checksumType.id, ((byte[] )checksums.Array()), checksums.Position(), ((byte[])data.Array()), data.Position (), data.Remaining(), fileName, BasePosition); }
/// <summary>Implementation of chunked verification specifically on byte arrays.</summary> /// <remarks> /// Implementation of chunked verification specifically on byte arrays. This /// is to avoid the copy when dealing with ByteBuffers that have array backing. /// </remarks> /// <exception cref="Org.Apache.Hadoop.FS.ChecksumException"/> private void VerifyChunkedSums(byte[] data, int dataOff, int dataLen, byte[] checksums , int checksumsOff, string fileName, long basePos) { if (type.size == 0) { return; } if (NativeCrc32.IsAvailable()) { NativeCrc32.VerifyChunkedSumsByteArray(bytesPerChecksum, type.id, checksums, checksumsOff , data, dataOff, dataLen, fileName, basePos); return; } int remaining = dataLen; int dataPos = 0; while (remaining > 0) { int n = Math.Min(remaining, bytesPerChecksum); summer.Reset(); summer.Update(data, dataOff + dataPos, n); dataPos += n; remaining -= n; int calculated = (int)summer.GetValue(); int stored = (checksums[checksumsOff] << 24 & unchecked ((int)(0xff000000))) | (checksums [checksumsOff + 1] << 16 & unchecked ((int)(0xff0000))) | (checksums[checksumsOff + 2] << 8 & unchecked ((int)(0xff00))) | checksums[checksumsOff + 3] & unchecked ( (int)(0xff)); checksumsOff += 4; if (calculated != stored) { long errPos = basePos + dataPos - n; throw new ChecksumException("Checksum error: " + fileName + " at " + errPos + " exp: " + stored + " got: " + calculated, errPos); } } }