//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static java.io.InputStream getInputStreamFromURL(String paramString1, String paramString2, String paramString3) throws Exception public static Stream getInputStreamFromURL(string paramString1, string paramString2, string paramString3) { URL uRL = new URL(paramString1); URLConnection uRLConnection = uRL.openConnection(); uRLConnection.ConnectTimeout = 4000; uRLConnection.ReadTimeout = 30000; uRLConnection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"); if (!string.ReferenceEquals(paramString2, null)) { uRLConnection.setRequestProperty("Authorization", "Basic " + encode(paramString2 + ":" + paramString3)); } return(uRLConnection.InputStream); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static java.util.Properties getPropertiesURL(String paramString1, String paramString2, String paramString3) throws Exception public static Properties getPropertiesURL(string paramString1, string paramString2, string paramString3) { Properties properties = new Properties(); URL uRL = new URL(paramString1); URLConnection uRLConnection = uRL.openConnection(); uRLConnection.ConnectTimeout = 5000; uRLConnection.ReadTimeout = 5000; uRLConnection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"); if (!string.ReferenceEquals(paramString2, null)) { uRLConnection.setRequestProperty("Authorization", "Basic " + encode(paramString2 + ":" + paramString3)); } Stream inputStream = uRLConnection.InputStream; properties.load(inputStream); inputStream.Close(); return(properties); }
public static string getURL(string paramString1, string paramString2, string paramString3, int paramInt1, int paramInt2) { string str = ""; try { URL uRL = new URL(paramString1); try { URLConnection uRLConnection = uRL.openConnection(); uRLConnection.ConnectTimeout = paramInt1; uRLConnection.ReadTimeout = paramInt2; uRLConnection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"); if (!string.ReferenceEquals(paramString2, null)) { uRLConnection.setRequestProperty("Authorization", "Basic " + encode(paramString2 + ":" + paramString3)); } Stream inputStream = uRLConnection.InputStream; StreamReader bufferedReader = new StreamReader(inputStream); string str1; while (!string.ReferenceEquals((str1 = bufferedReader.ReadLine()), null)) { str = str + str1; } bufferedReader.Close(); inputStream.Close(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); return(""); } } catch (MalformedURLException) { return(paramString1 + " is not a parseable URL"); } return(str); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static LocationSearchResult reverseSearch(org.jdesktop.swingx.mapviewer.GeoPosition paramGeoPosition, int paramInt1, int paramInt2) throws Exception public static LocationSearchResult reverseSearch(GeoPosition paramGeoPosition, int paramInt1, int paramInt2) { LocationSearchResult locationSearchResult = new LocationSearchResult(); locationSearchResult.PlaceList = new List <object>(); string str = StringUtils.replace("http://nominatim.openstreetmap.org/reverse?format=xml&lat={A}&lon={B}&zoom={C}&addressdetails=1", "{A}", "" + paramGeoPosition.Latitude); str = StringUtils.replace(str, "{B}", "" + paramGeoPosition.Longitude); double d = paramInt1 * 19.0D / paramInt2; paramInt1 = (int)(19.0D - d - 0.5D); if (paramInt1 == 0) { paramInt1 = 1; } else if (paramInt1 >= 19) { paramInt1 = 18; } str = StringUtils.replace(str, "{C}", "" + paramInt1); URL uRL = new URL(str); URLConnection uRLConnection = uRL.openConnection(); uRLConnection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"); uRLConnection.ConnectTimeout = 4000; uRLConnection.ReadTimeout = 30000; Stream inputStream = uRLConnection.InputStream; SAXReader sAXReader = new SAXReader(); Document document = sAXReader.read(inputStream); Element element = document.RootElement; locationSearchResult.Query_string = element.attributeValue("query_string"); locationSearchResult.Polygon = (new bool?(element.attributeValue("polygon"))); LocationPlace locationPlace = new LocationPlace(); locationPlace.Lat = "" + paramGeoPosition.Latitude; locationPlace.Lon = "" + paramGeoPosition.Longitude; System.Collections.IEnumerator iterator = element.elementIterator(); while (iterator.MoveNext()) { Element element1 = (Element)iterator.Current; if (element1.Name.Equals("result")) { locationPlace.Place_id = element1.attributeValue("place_id"); locationPlace.Osm_type = element1.attributeValue("osm_type"); locationPlace.Osm_id = element1.attributeValue("osm_type"); locationPlace.Display_name = element1.StringValue; continue; } if (element1.Name.Equals("addressparts")) { System.Collections.IEnumerator iterator1 = element1.elementIterator(); while (iterator1.MoveNext()) { Element element2 = (Element)iterator1.Current; if (element2.Name.Equals("station")) { locationPlace.Station = element2.StringValue; continue; } if (element2.Name.Equals("road")) { locationPlace.Road = element2.StringValue; continue; } if (element2.Name.Equals("suburb")) { locationPlace.Suburb = element2.StringValue; continue; } if (element2.Name.Equals("village")) { locationPlace.Village = element2.StringValue; continue; } if (element2.Name.Equals("city")) { locationPlace.City = element2.StringValue; continue; } if (element2.Name.Equals("postcode")) { locationPlace.Postcode = element2.StringValue; continue; } if (element2.Name.Equals("country")) { locationPlace.Country = element2.StringValue; continue; } if (element2.Name.Equals("country_code")) { locationPlace.Country_code = element2.StringValue; continue; } if (element2.Name.Equals("county")) { locationPlace.County = element2.StringValue; continue; } if (element2.Name.Equals("state")) { locationPlace.State = element2.StringValue; continue; } if (element2.Name.Equals("hamlet")) { locationPlace.Hamlet = element2.StringValue; continue; } if (element2.Name.Equals("town")) { locationPlace.Town = element2.StringValue; continue; } if (element2.Name.Equals("residential")) { locationPlace.Residential = element2.StringValue; continue; } if (element2.Name.Equals("house")) { locationPlace.House = element2.StringValue; continue; } if (element2.Name.Equals("place")) { locationPlace.Place = element2.StringValue; } } } } locationSearchResult.PlaceList.Add(locationPlace); return(locationSearchResult); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static LocationSearchResult search(String paramString, boolean paramBoolean) throws Exception public static LocationSearchResult search(string paramString, bool paramBoolean) { paramString = StringUtils.replaceAll(paramString, " ", "+"); string str = StringUtils.replace("http://nominatim.openstreetmap.org/search?format=xml&q={A}&polygon={B}&addressdetails=1", "{A}", paramString); str = StringUtils.replace(str, "{B}", paramBoolean ? "1" : "0"); URL uRL = new URL(str); URLConnection uRLConnection = uRL.openConnection(); uRLConnection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"); uRLConnection.ConnectTimeout = 4000; uRLConnection.ReadTimeout = 30000; Stream inputStream = uRLConnection.InputStream; SAXReader sAXReader = new SAXReader(); Document document = sAXReader.read(inputStream); LocationSearchResult locationSearchResult = new LocationSearchResult(); Element element = document.RootElement; locationSearchResult.Query_string = element.attributeValue("query_string"); locationSearchResult.Polygon = (new bool?(element.attributeValue("polygon"))); locationSearchResult.Exclude_place_ids = element.attributeValue("exclude_place_ids"); locationSearchResult.More_url = element.attributeValue("more_url"); locationSearchResult.Attribution = element.attributeValue("attribution"); locationSearchResult.PlaceList = new List <object>(); System.Collections.IEnumerator iterator = element.elementIterator(); while (iterator.MoveNext()) { Element element1 = (Element)iterator.Current; LocationPlace locationPlace = new LocationPlace(); locationPlace.Place_id = element1.attributeValue("place_id"); locationPlace.Osm_type = element1.attributeValue("osm_type"); locationPlace.Osm_id = element1.attributeValue("osm_id"); locationPlace.Lat = element1.attributeValue("lat"); locationPlace.Lon = element1.attributeValue("lon"); locationPlace.Place_class = element1.attributeValue("class"); locationPlace.Type = element1.attributeValue("type"); locationPlace.Display_name = element1.attributeValue("display_name"); locationPlace.Icon = element1.attributeValue("icon"); locationPlace.Boundingbox = element1.attributeValue("boundingbox"); if (paramBoolean) { locationPlace.calculatePolygonPoints(element1.attributeValue("polygonpoints")); } System.Collections.IEnumerator iterator1 = element1.elementIterator(); while (iterator1.MoveNext()) { Element element2 = (Element)iterator1.Current; if (element2.Name.Equals("station")) { locationPlace.Station = element2.StringValue; continue; } if (element2.Name.Equals("road")) { locationPlace.Road = element2.StringValue; continue; } if (element2.Name.Equals("suburb")) { locationPlace.Suburb = element2.StringValue; continue; } if (element2.Name.Equals("village")) { locationPlace.Village = element2.StringValue; continue; } if (element2.Name.Equals("city")) { locationPlace.City = element2.StringValue; continue; } if (element2.Name.Equals("postcode")) { locationPlace.Postcode = element2.StringValue; continue; } if (element2.Name.Equals("country")) { locationPlace.Country = element2.StringValue; continue; } if (element2.Name.Equals("country_code")) { locationPlace.Country_code = element2.StringValue; continue; } if (element2.Name.Equals("county")) { locationPlace.County = element2.StringValue; continue; } if (element2.Name.Equals("state")) { locationPlace.State = element2.StringValue; continue; } if (element2.Name.Equals("hamlet")) { locationPlace.Hamlet = element2.StringValue; continue; } if (element2.Name.Equals("town")) { locationPlace.Town = element2.StringValue; continue; } if (element2.Name.Equals("residential")) { locationPlace.Residential = element2.StringValue; continue; } if (element2.Name.Equals("house")) { locationPlace.House = element2.StringValue; continue; } if (element2.Name.Equals("place")) { locationPlace.Place = element2.StringValue; } } locationSearchResult.PlaceList.Add(locationPlace); } return(locationSearchResult); }
public void setRequestProperty(String key, string value) { _conn.setRequestProperty(key, value); }
protected internal virtual Dictionary <string, string> executeSimpleUPnPcommand(string controlUrl, string serviceType, string action, Dictionary <string, string> arguments) { Dictionary <string, string> result = null; StringBuilder body = new StringBuilder(); body.Append(string.Format("<?xml version=\"1.0\"?>\r\n")); body.Append(string.Format("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n")); body.Append(string.Format("<s:Body>\r\n")); body.Append(string.Format(" <u:{0} xmlns:u=\"{1}\">\r\n", action, serviceType)); if (arguments != null) { foreach (string name in arguments.Keys) { string value = arguments[name]; if (string.ReferenceEquals(value, null) || value.Length == 0) { body.Append(string.Format(" <{0} />\r\n", name)); } else { body.Append(string.Format(" <{0}>{1}</{2}>\r\n", name, value, name)); } } } body.Append(string.Format(" </u:{0}>\r\n", action)); body.Append(string.Format("</s:Body>\r\n")); body.Append(string.Format("</s:Envelope>\r\n")); if (log.TraceEnabled) { log.trace(string.Format("Sending UPnP command: {0}", body.ToString())); } sbyte[] bodyBytes = body.ToString().GetBytes(); try { URL url = new URL(controlUrl); URLConnection connection = url.openConnection(); if (connection is HttpURLConnection) { HttpURLConnection httpURLConnection = (HttpURLConnection)connection; httpURLConnection.RequestMethod = "POST"; } connection.setRequestProperty("SOAPAction", string.Format("{0}#{1}", serviceType, action)); connection.setRequestProperty("Content-Type", "text/xml"); connection.setRequestProperty("Content-Length", Convert.ToString(bodyBytes.Length)); connection.DoOutput = true; System.IO.Stream output = connection.OutputStream; output.Write(bodyBytes, 0, bodyBytes.Length); output.Flush(); output.Close(); connection.connect(); System.IO.Stream response = connection.InputStream; StringBuilder content = new StringBuilder(); sbyte[] buffer = new sbyte[1024]; int n; do { n = response.Read(buffer, 0, buffer.Length); if (n > 0) { content.Append(StringHelper.NewString(buffer, 0, n)); } } while (n >= 0); response.Close(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("UPnP command serviceType {0}, action {1}, result: {2}", serviceType, action, content.ToString())); } result = parseSimpleCommandResponse(content.ToString()); //if (log.DebugEnabled) { string errorCode = result["errorCode"]; if (!string.ReferenceEquals(errorCode, null)) { Console.WriteLine(string.Format("UPnP command {0}: errorCode = {1}", action, errorCode)); } } } catch (MalformedURLException e) { Console.WriteLine("executeUPnPcommand", e); } catch (IOException e) { //if (log.DebugEnabled) { Console.WriteLine("executeUPnPcommand", e); } } return(result); }