示例#1
0
        /// <summary>
        /// Converts a <code>FileChecksum</code> object into a JSON array
        /// object.
        /// </summary>
        /// <param name="checksum">file checksum.</param>
        /// <returns>The JSON representation of the file checksum.</returns>
        private static IDictionary FileChecksumToJSON(FileChecksum checksum)
        {
            IDictionary json = new LinkedHashMap();

            json[HttpFSFileSystem.ChecksumAlgorithmJson] = checksum.GetAlgorithmName();
            json[HttpFSFileSystem.ChecksumBytesJson]     = StringUtils.ByteToHexString(checksum.GetBytes
                                                                                           ());
            json[HttpFSFileSystem.ChecksumLengthJson] = checksum.GetLength();
            IDictionary response = new LinkedHashMap();

            response[HttpFSFileSystem.FileChecksumJson] = json;
            return(response);
        }
示例#2
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessPath(PathData item)
            {
                if (item.stat.IsDirectory())
                {
                    throw new PathIsDirectoryException(item.ToString());
                }
                FileChecksum checksum = item.fs.GetFileChecksum(item.path);

                if (checksum == null)
                {
                    @out.Printf("%s\tNONE\t%n", item.ToString());
                }
                else
                {
                    string checksumString = StringUtils.ByteToHexString(checksum.GetBytes(), 0, checksum
                                                                        .GetLength());
                    @out.Printf("%s\t%s\t%s%n", item.ToString(), checksum.GetAlgorithmName(), checksumString
                                );
                }
            }
示例#3
0
 /// <exception cref="System.Exception"/>
 private void TestChecksum()
 {
     if (!IsLocalFS())
     {
         FileSystem fs = FileSystem.Get(GetProxiedFSConf());
         fs.Mkdirs(GetProxiedFSTestDir());
         Path         path = new Path(GetProxiedFSTestDir(), "foo.txt");
         OutputStream os   = fs.Create(path);
         os.Write(1);
         os.Close();
         FileChecksum hdfsChecksum = fs.GetFileChecksum(path);
         fs.Close();
         fs = GetHttpFSFileSystem();
         FileChecksum httpChecksum = fs.GetFileChecksum(path);
         fs.Close();
         NUnit.Framework.Assert.AreEqual(httpChecksum.GetAlgorithmName(), hdfsChecksum.GetAlgorithmName
                                             ());
         NUnit.Framework.Assert.AreEqual(httpChecksum.GetLength(), hdfsChecksum.GetLength(
                                             ));
         Assert.AssertArrayEquals(httpChecksum.GetBytes(), hdfsChecksum.GetBytes());
     }
 }