[Mono-devel-list] small fix

Atsushi Eno atsushi at ximian.com
Tue Mar 29 17:32:44 EST 2005


Hi again,

So I found the corresponding ChangeLog at r21648

 > * XmlUrlResolver.cs : It downloads network stream content at
 >   GetEntity() call. You can try like below:
 >   for (int i=0;i<100;i++) u.GetEntity(url, null, typeof(Stream));

However it does not make sense since it depends on the connection.
I tried the code below and noticed that it does not download all
the content for each connection but just takes long time to connect.

using System;
using System.IO;
using System.Xml;

public class Test {
	public static void Main (string [] args) {
		XmlUrlResolver r = new XmlUrlResolver ();
		Uri uri = r.ResolveUri (null, args [0]);
		Stream s = null;
		for (int i = 0; i < 100; i++)
			s = (Stream) r.GetEntity (uri, null,
				typeof (Stream));
		Console.ReadLine ();
	}
}

So am going to checkin the fix.

Thanks,
Atsushi Eno

Atsushi Eno wrote:
> Hi Kosta,
> 
> Yes, I think that is the way it should take. However, AFAIR, there
> was an example case that GetEntity() consumed the whole stream up
> and after it the network consumption never happened, or example
> testcase that requires XmlUrlResolver to implement this way.
> Let me find the example.
> 
> Atsushi Eno
> 
> Konstantin Triger wrote:
> 
>> Hello Eno,
>>
>> I looked into XmlUrlResolver and found this code:
>>
>>        // Methods
>>        public override object GetEntity (Uri absoluteUri, string role, 
>> Type ofObjectToReturn)
>>        {
>>            if (ofObjectToReturn == null)
>>                ofObjectToReturn = typeof (Stream);
>>            if (ofObjectToReturn != typeof (Stream))
>>                throw new XmlException ("This object type is not 
>> supported.");
>>
>>            if (absoluteUri.Scheme == "file") {
>>                if (absoluteUri.AbsolutePath == String.Empty)
>>                    throw new ArgumentException ("uri must be 
>> absolute.", "absoluteUri");
>>                return new FileStream (UnescapeRelativeUriBody 
>> (absoluteUri.LocalPath), FileMode.Open, FileAccess.Read, FileShare.Read);
>>            }
>>
>>            // (MS documentation says) parameter role isn't used yet.
>>            Stream s = null;
>>            using (s) {
>>                WebClient wc = new WebClient ();
>>                wc.Credentials = credential;
>>                byte [] data = wc.DownloadData (absoluteUri.ToString ());
>>                wc.Dispose ();
>>                return new MemoryStream (data, 0, data.Length);
>>             }
>>        }
>>
>> Don't you think that the highlighted part should be replcaed with that 
>> following one (here we return the underlying reponse's stream instead 
>> of allocating a new one):
>>
>>            WebRequest req = WebRequest.Create(absoluteUri);
>>            if (credential != null)
>>                req.Credentials = credential;
>>
>>            return req.GetResponse().GetResponseStream();
>>
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 




More information about the Mono-devel-list mailing list