aboutsummaryrefslogtreecommitdiff
path: root/dotnet/Mammoth/Couscous/java/net/URL.cs
blob: af6e021485c173f1f8cc45e6f50bfce50ea6ebef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Net;
using Mammoth.Couscous.java.io;

namespace Mammoth.Couscous.java.net {
    internal class URL {
        private readonly string _url;
        
        internal URL(string url) {
            _url = url;
        }
        
        internal InputStream openStream() {
            try {
                var response = WebRequest.Create(_url).GetResponse();
                try {
                    return ToJava.StreamToInputStream(response.GetResponseStream());
                } catch {
                    response.Close();
                    throw;
                }
            } catch (System.UriFormatException) {
                return ToJava.StreamToInputStream(System.IO.File.OpenRead(_url));
            }
        }
    }
}