/// <exception cref="System.IO.IOException"/>
        public override FSDataInputStream Open(Path f, int buffersize)
        {
            f = f.MakeQualified(GetUri(), GetWorkingDirectory());
            string path  = "/data" + ServletUtil.EncodePath(f.ToUri().GetPath());
            string query = AddDelegationTokenParam("ugi=" + GetEncodedUgiParameter());
            Uri    u     = GetNamenodeURL(path, query);

            return(new FSDataInputStream(new HftpFileSystem.RangeHeaderInputStream(connectionFactory
                                                                                   , u)));
        }
        /// <exception cref="System.IO.IOException"/>
        private void TestDataNodeRedirect(Path path)
        {
            // Create the file
            if (hdfs.Exists(path))
            {
                hdfs.Delete(path, true);
            }
            FSDataOutputStream @out = hdfs.Create(path, (short)1);

            @out.WriteBytes("0123456789");
            @out.Close();
            // Get the path's block location so we can determine
            // if we were redirected to the right DN.
            BlockLocation[] locations = hdfs.GetFileBlockLocations(path, 0, 10);
            string          xferAddr  = locations[0].GetNames()[0];
            // Connect to the NN to get redirected
            Uri u = hftpFs.GetNamenodeURL("/data" + ServletUtil.EncodePath(path.ToUri().GetPath
                                                                               ()), "ugi=userx,groupy");
            HttpURLConnection conn = (HttpURLConnection)u.OpenConnection();

            HttpURLConnection.SetFollowRedirects(true);
            conn.Connect();
            conn.GetInputStream();
            bool @checked = false;

            // Find the datanode that has the block according to locations
            // and check that the URL was redirected to this DN's info port
            foreach (DataNode node in cluster.GetDataNodes())
            {
                DatanodeRegistration dnR = DataNodeTestUtils.GetDNRegistrationForBP(node, blockPoolId
                                                                                    );
                if (dnR.GetXferAddr().Equals(xferAddr))
                {
                    @checked = true;
                    NUnit.Framework.Assert.AreEqual(dnR.GetInfoPort(), conn.GetURL().Port);
                }
            }
            NUnit.Framework.Assert.IsTrue("The test never checked that location of " + "the block and hftp desitnation are the same"
                                          , @checked);
        }
            /// <summary>Connect to the name node and get content summary.</summary>
            /// <param name="path">The path</param>
            /// <returns>The content summary for the path.</returns>
            /// <exception cref="System.IO.IOException"/>
            private ContentSummary GetContentSummary(string path)
            {
                HttpURLConnection connection = this._enclosing.OpenConnection("/contentSummary" +
                                                                              ServletUtil.EncodePath(path), "ugi=" + this._enclosing.GetEncodedUgiParameter()
                                                                              );
                InputStream @in = null;

                try
                {
                    @in = connection.GetInputStream();
                    XMLReader xr = XMLReaderFactory.CreateXMLReader();
                    xr.SetContentHandler(this);
                    xr.Parse(new InputSource(@in));
                }
                catch (FileNotFoundException)
                {
                    //the server may not support getContentSummary
                    return(null);
                }
                catch (SAXException saxe)
                {
                    Exception embedded = saxe.GetException();
                    if (embedded != null && embedded is IOException)
                    {
                        throw (IOException)embedded;
                    }
                    throw new IOException("Invalid xml format", saxe);
                }
                finally
                {
                    if (@in != null)
                    {
                        @in.Close();
                    }
                    connection.Disconnect();
                }
                return(this.contentsummary);
            }
            /// <exception cref="System.IO.IOException"/>
            private FileChecksum GetFileChecksum(string f)
            {
                HttpURLConnection connection = this._enclosing.OpenConnection("/fileChecksum" + ServletUtil
                                                                              .EncodePath(f), "ugi=" + this._enclosing.GetEncodedUgiParameter());

                try
                {
                    XMLReader xr = XMLReaderFactory.CreateXMLReader();
                    xr.SetContentHandler(this);
                    xr.Parse(new InputSource(connection.GetInputStream()));
                }
                catch (SAXException e)
                {
                    Exception embedded = e.GetException();
                    if (embedded != null && embedded is IOException)
                    {
                        throw (IOException)embedded;
                    }
                    throw new IOException("invalid xml directory content", e);
                }
                finally
                {
                    connection.Disconnect();
                }
                return(this.filechecksum);
            }
 /// <exception cref="System.IO.IOException"/>
 private void FetchList(string path, bool recur)
 {
     try
     {
         XMLReader xr = XMLReaderFactory.CreateXMLReader();
         xr.SetContentHandler(this);
         HttpURLConnection connection = this._enclosing.OpenConnection("/listPaths" + ServletUtil
                                                                       .EncodePath(path), "ugi=" + this._enclosing.GetEncodedUgiParameter() + (recur ?
                                                                                                                                               "&recursive=yes" : string.Empty));
         InputStream resp = connection.GetInputStream();
         xr.Parse(new InputSource(resp));
     }
     catch (SAXException e)
     {
         Exception embedded = e.GetException();
         if (embedded != null && embedded is IOException)
         {
             throw (IOException)embedded;
         }
         throw new IOException("invalid xml directory content", e);
     }
 }