Esempio n. 1
0
        /// <summary>Get a BlockReader for the given block.</summary>
        /// <exception cref="System.IO.IOException"/>
        public static BlockReader GetBlockReader(MiniDFSCluster cluster, LocatedBlock testBlock
                                                 , int offset, int lenToRead)
        {
            IPEndPoint    targetAddr = null;
            ExtendedBlock block      = testBlock.GetBlock();

            DatanodeInfo[] nodes = testBlock.GetLocations();
            targetAddr = NetUtils.CreateSocketAddr(nodes[0].GetXferAddr());
            DistributedFileSystem fs = cluster.GetFileSystem();

            return(new BlockReaderFactory(fs.GetClient().GetConf()).SetInetSocketAddress(targetAddr
                                                                                         ).SetBlock(block).SetFileName(targetAddr.ToString() + ":" + block.GetBlockId()).
                   SetBlockToken(testBlock.GetBlockToken()).SetStartOffset(offset).SetLength(lenToRead
                                                                                             ).SetVerifyChecksum(true).SetClientName("BlockReaderTestUtil").SetDatanodeInfo(nodes
                                                                                                                                                                            [0]).SetClientCacheContext(ClientContext.GetFromConf(fs.GetConf())).SetCachingStrategy
                       (CachingStrategy.NewDefaultStrategy()).SetConfiguration(fs.GetConf()).SetAllowShortCircuitLocalReads
                       (true).SetRemotePeerFactory(new _RemotePeerFactory_196(fs)).Build());
        }