Example #1
0
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/>
            public ChecksumFSInputChecker(ChecksumFs fs, Path file, int bufferSize)
                : base(file, fs.GetFileStatus(file).GetReplication())
            {
                this.datas = fs.GetRawFs().Open(file, bufferSize);
                this.fs    = fs;
                Path sumFile = fs.GetChecksumFile(file);

                try
                {
                    int sumBufferSize = fs.GetSumBufferSize(fs.GetBytesPerSum(), bufferSize);
                    sums = fs.GetRawFs().Open(sumFile, sumBufferSize);
                    byte[] version = new byte[ChecksumVersion.Length];
                    sums.ReadFully(version);
                    if (!Arrays.Equals(version, ChecksumVersion))
                    {
                        throw new IOException("Not a checksum file: " + sumFile);
                    }
                    this.bytesPerSum = sums.ReadInt();
                    Set(fs.verifyChecksum, DataChecksum.NewCrc32(), bytesPerSum, 4);
                }
                catch (FileNotFoundException)
                {
                    // quietly ignore
                    Set(fs.verifyChecksum, null, 1, 0);
                }
                catch (IOException e)
                {
                    // loudly ignore
                    Log.Warn("Problem opening checksum file: " + file + ".  Ignoring exception: ", e);
                    Set(fs.verifyChecksum, null, 1, 0);
                }
            }