コード例 #1
0
ファイル: RMWebAppFilter.cs プロジェクト: orf53975/hadoop.net
 private string AppendOrReplaceParamter(string uri, string newQuery)
 {
     if (uri.Contains(YarnWebParams.NextRefreshInterval + "="))
     {
         return(uri.ReplaceAll(YarnWebParams.NextRefreshInterval + "=[^&]+", newQuery));
     }
     try
     {
         URI    oldUri      = new URI(uri);
         string appendQuery = oldUri.GetQuery();
         if (appendQuery == null)
         {
             appendQuery = newQuery;
         }
         else
         {
             appendQuery += "&" + newQuery;
         }
         URI newUri = new URI(oldUri.GetScheme(), oldUri.GetAuthority(), oldUri.GetPath(),
                              appendQuery, oldUri.GetFragment());
         return(newUri.ToString());
     }
     catch (URISyntaxException)
     {
         return(null);
     }
 }
コード例 #2
0
        /// <summary>Resolve the uri's hostname and add the default port if not in the uri</summary>
        /// <param name="uri">to resolve</param>
        /// <param name="defaultPort">if none is given</param>
        /// <returns>URI</returns>
        public static URI GetCanonicalUri(URI uri, int defaultPort)
        {
            // skip if there is no authority, ie. "file" scheme or relative uri
            string host = uri.GetHost();

            if (host == null)
            {
                return(uri);
            }
            string fqHost = CanonicalizeHost(host);
            int    port   = uri.GetPort();

            // short out if already canonical with a port
            if (host.Equals(fqHost) && port != -1)
            {
                return(uri);
            }
            // reconstruct the uri with the canonical host and port
            try
            {
                uri = new URI(uri.GetScheme(), uri.GetUserInfo(), fqHost, (port == -1) ? defaultPort
                                         : port, uri.GetPath(), uri.GetQuery(), uri.GetFragment());
            }
            catch (URISyntaxException e)
            {
                throw new ArgumentException(e);
            }
            return(uri);
        }
コード例 #3
0
 private static URI RemoveAuthority(URI uri)
 {
     try
     {
         uri = new URI(uri.GetScheme(), string.Empty, uri.GetPath(), uri.GetQuery(), uri.GetFragment
                           ());
     }
     catch (URISyntaxException e)
     {
         throw new ArgumentException(e.GetLocalizedMessage());
     }
     return(uri);
 }
コード例 #4
0
ファイル: ProxyUriUtils.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Get a proxied URI for the original URI.</summary>
 /// <param name="originalUri">
 /// the original URI to go through the proxy, or null if
 /// a default path "/" can be used.
 /// </param>
 /// <param name="proxyUri">the URI of the proxy itself, scheme, host and port are used.
 ///     </param>
 /// <param name="id">the id of the application</param>
 /// <returns>the proxied URI</returns>
 public static URI GetProxyUri(URI originalUri, URI proxyUri, ApplicationId id)
 {
     try
     {
         string path = GetPath(id, originalUri == null ? "/" : originalUri.GetPath());
         return(new URI(proxyUri.GetScheme(), proxyUri.GetAuthority(), path, originalUri ==
                        null ? null : originalUri.GetQuery(), originalUri == null ? null : originalUri.
                        GetFragment()));
     }
     catch (URISyntaxException e)
     {
         throw new RuntimeException("Could not proxify " + originalUri, e);
     }
 }
コード例 #5
0
        /// <summary>Convert a nested URI to decode the underlying path.</summary>
        /// <remarks>
        /// Convert a nested URI to decode the underlying path. The translation takes
        /// the authority and parses it into the underlying scheme and authority.
        /// For example, "myscheme://hdfs@nn/my/path" is converted to
        /// "hdfs://nn/my/path".
        /// </remarks>
        /// <param name="nestedUri">the URI from the nested URI</param>
        /// <returns>the unnested path</returns>
        public static Path UnnestUri(URI nestedUri)
        {
            string[]      parts  = nestedUri.GetAuthority().Split("@", 2);
            StringBuilder result = new StringBuilder(parts[0]);

            result.Append("://");
            if (parts.Length == 2)
            {
                result.Append(parts[1]);
            }
            result.Append(nestedUri.GetPath());
            if (nestedUri.GetQuery() != null)
            {
                result.Append("?");
                result.Append(nestedUri.GetQuery());
            }
            if (nestedUri.GetFragment() != null)
            {
                result.Append("#");
                result.Append(nestedUri.GetFragment());
            }
            return(new Path(result.ToString()));
        }
コード例 #6
0
        /// <exception cref="System.Exception"/>
        internal static void RunTestCache(int port)
        {
            Configuration  conf    = new Configuration();
            MiniDFSCluster cluster = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NameNodePort(port).NumDataNodes(2).Build
                              ();
                URI uri = cluster.GetFileSystem().GetUri();
                Log.Info("uri=" + uri);
                {
                    FileSystem fs = FileSystem.Get(uri, new Configuration());
                    CheckPath(cluster, fs);
                    for (int i = 0; i < 100; i++)
                    {
                        NUnit.Framework.Assert.IsTrue(fs == FileSystem.Get(uri, new Configuration()));
                    }
                }
                if (port == NameNode.DefaultPort)
                {
                    //test explicit default port
                    URI uri2 = new URI(uri.GetScheme(), uri.GetUserInfo(), uri.GetHost(), NameNode.DefaultPort
                                       , uri.GetPath(), uri.GetQuery(), uri.GetFragment());
                    Log.Info("uri2=" + uri2);
                    FileSystem fs = FileSystem.Get(uri2, conf);
                    CheckPath(cluster, fs);
                    for (int i = 0; i < 100; i++)
                    {
                        NUnit.Framework.Assert.IsTrue(fs == FileSystem.Get(uri2, new Configuration()));
                    }
                }
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
コード例 #7
0
ファイル: URIUtils.cs プロジェクト: bogdan23a/lavaplayerSharp
        /// <summary>
        /// Removes dot segments according to RFC 3986, section 5.2.4 and
        /// Syntax-Based Normalization according to RFC 3986, section 6.2.2.
        /// </summary>
        /// <remarks>
        /// Removes dot segments according to RFC 3986, section 5.2.4 and
        /// Syntax-Based Normalization according to RFC 3986, section 6.2.2.
        /// </remarks>
        /// <param name="uri">the original URI</param>
        /// <returns>the URI without dot segments</returns>
        private static URI NormalizeSyntax(URI uri)
        {
            if (uri.IsOpaque() || uri.GetAuthority() == null)
            {
                // opaque and file: URIs
                return(uri);
            }
            Args.Check(uri.IsAbsolute(), "Base URI must be absolute");
            string path = uri.GetPath() == null ? string.Empty : uri.GetPath();

            string[]       inputSegments  = path.Split("/");
            Stack <string> outputSegments = new Stack <string>();

            foreach (string inputSegment in inputSegments)
            {
                if ((inputSegment.Length == 0) || (".".Equals(inputSegment)))
                {
                }
                else
                {
                    // Do nothing
                    if ("..".Equals(inputSegment))
                    {
                        if (!outputSegments.IsEmpty())
                        {
                            outputSegments.Pop();
                        }
                    }
                    else
                    {
                        outputSegments.Push(inputSegment);
                    }
                }
            }
            StringBuilder outputBuffer = new StringBuilder();

            foreach (string outputSegment in outputSegments)
            {
                outputBuffer.Append('/').Append(outputSegment);
            }
            if (path.LastIndexOf('/') == path.Length - 1)
            {
                // path.endsWith("/") || path.equals("")
                outputBuffer.Append('/');
            }
            try
            {
                string scheme = uri.GetScheme().ToLower();
                string auth   = uri.GetAuthority().ToLower();
                URI    @ref   = new URI(scheme, auth, outputBuffer.ToString(), null, null);
                if (uri.GetQuery() == null && uri.GetFragment() == null)
                {
                    return(@ref);
                }
                StringBuilder normalized = new StringBuilder(@ref.ToASCIIString());
                if (uri.GetQuery() != null)
                {
                    // query string passed through unchanged
                    normalized.Append('?').Append(uri.GetRawQuery());
                }
                if (uri.GetFragment() != null)
                {
                    // fragment passed through unchanged
                    normalized.Append('#').Append(uri.GetRawFragment());
                }
                return(URI.Create(normalized.ToString()));
            }
            catch (URISyntaxException e)
            {
                throw new ArgumentException(e);
            }
        }