Пример #1
0
        /// <summary>
        /// Compare two files, ignore trailing zeros at the end, for edits log the
        /// trailing zeros do not make any difference, throw exception is the files are
        /// not same
        /// </summary>
        /// <param name="filenameSmall">first file to compare (doesn't have to be smaller)</param>
        /// <param name="filenameLarge">second file to compare (doesn't have to be larger)</param>
        /// <exception cref="System.IO.IOException"/>
        private bool FilesEqualIgnoreTrailingZeros(string filenameSmall, string filenameLarge
                                                   )
        {
            ByteBuffer small = ByteBuffer.Wrap(DFSTestUtil.LoadFile(filenameSmall));
            ByteBuffer large = ByteBuffer.Wrap(DFSTestUtil.LoadFile(filenameLarge));

            // OEV outputs with the latest layout version, so tweak the old file's
            // contents to have latest version so checkedin binary files don't
            // require frequent updates
            small.Put(3, unchecked ((byte)NameNodeLayoutVersion.CurrentLayoutVersion));
            // now correct if it's otherwise
            if (small.Capacity() > large.Capacity())
            {
                ByteBuffer tmpByteBuffer = small;
                small = large;
                large = tmpByteBuffer;
                string tmpFilename = filenameSmall;
                filenameSmall = filenameLarge;
                filenameLarge = tmpFilename;
            }
            // compare from 0 to capacity of small
            // the rest of the large should be all zeros
            small.Position(0);
            small.Limit(small.Capacity());
            large.Position(0);
            large.Limit(small.Capacity());
            // compares position to limit
            if (!small.Equals(large))
            {
                return(false);
            }
            // everything after limit should be 0xFF
            int i = large.Limit();

            large.Clear();
            for (; i < large.Capacity(); i++)
            {
                if (large.Get(i) != FSEditLogOpCodes.OpInvalid.GetOpCode())
                {
                    return(false);
                }
            }
            return(true);
        }