コード例 #1
0
 public virtual void TestCalculateChunkedSumsFail()
 {
     AllocateDirectByteBuffers();
     FillDataAndInvalidChecksums();
     NativeCrc32.CalculateChunkedSums(bytesPerChecksum, checksumType.id, checksums, data
                                      );
 }
コード例 #2
0
ファイル: DataChecksum.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Calculate checksums for the given data.</summary>
 /// <remarks>
 /// Calculate checksums for the given data.
 /// The 'mark' of the ByteBuffer parameters may be modified by this function,
 /// but the position is maintained.
 /// </remarks>
 /// <param name="data">the DirectByteBuffer pointing to the data to checksum.</param>
 /// <param name="checksums">
 /// the DirectByteBuffer into which checksums will be
 /// stored. Enough space must be available in this
 /// buffer to put the checksums.
 /// </param>
 public virtual void CalculateChunkedSums(ByteBuffer data, ByteBuffer checksums)
 {
     if (type.size == 0)
     {
         return;
     }
     if (data.HasArray() && checksums.HasArray())
     {
         CalculateChunkedSums(((byte[])data.Array()), data.ArrayOffset() + data.Position()
                              , data.Remaining(), ((byte[])checksums.Array()), checksums.ArrayOffset() + checksums
                              .Position());
         return;
     }
     if (NativeCrc32.IsAvailable())
     {
         NativeCrc32.CalculateChunkedSums(bytesPerChecksum, type.id, checksums, data);
         return;
     }
     data.Mark();
     checksums.Mark();
     try
     {
         byte[] buf = new byte[bytesPerChecksum];
         while (data.Remaining() > 0)
         {
             int n = Math.Min(data.Remaining(), bytesPerChecksum);
             data.Get(buf, 0, n);
             summer.Reset();
             summer.Update(buf, 0, n);
             checksums.PutInt((int)summer.GetValue());
         }
     }
     finally
     {
         data.Reset();
         checksums.Reset();
     }
 }