Changeset 5868 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2013-04-15T19:12:01+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r5819 r5868 10 10 import java.awt.datatransfer.Transferable; 11 11 import java.awt.datatransfer.UnsupportedFlavorException; 12 import java.io.BufferedReader; 12 13 import java.io.File; 13 14 import java.io.IOException; 14 15 import java.io.InputStream; 16 import java.io.InputStreamReader; 15 17 import java.io.OutputStream; 16 18 import java.io.Reader; … … 18 20 import java.net.HttpURLConnection; 19 21 import java.net.URL; 22 import java.net.URLConnection; 20 23 import java.security.MessageDigest; 21 24 import java.security.NoSuchAlgorithmException; … … 28 31 import java.util.List; 29 32 33 import org.openstreetmap.josm.Main; 30 34 import org.openstreetmap.josm.data.Version; 31 35 … … 554 558 } 555 559 HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection(); 560 connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString()); 556 561 return connection; 557 562 } 558 563 564 /** 565 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 566 * @param url The url to open 567 * @return An stream for the given URL 568 * @throws IOException if an I/O exception occurs. 569 * @since 5867 570 */ 571 public static InputStream openURL(URL url) throws IOException { 572 URLConnection connection = url.openConnection(); 573 connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString()); 574 connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000); 575 connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000); 576 return connection.getInputStream(); 577 } 578 579 /** 580 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 581 * @param url The url to open 582 * @return An buffered stream reader for the given URL (using UTF-8) 583 * @throws IOException if an I/O exception occurs. 584 * @since 5867 585 */ 586 public static BufferedReader openURLReader(URL url) throws IOException { 587 return new BufferedReader(new InputStreamReader(openURL(url), "utf-8")); 588 } 589 559 590 /** 560 591 * Opens a HTTP connection to the given URL, sets the User-Agent property to JOSM's one and optionnaly disables Keep-Alive. -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r5834 r5868 5 5 import java.io.IOException; 6 6 import java.io.InputStream; 7 import java.io.InputStreamReader;8 7 import java.net.URL; 9 8 … … 36 35 */ 37 36 public String read(String url) throws IOException { 38 BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"));37 BufferedReader in = Utils.openURLReader(new URL(url)); 39 38 try { 40 39 if (url.startsWith(baseurl) && !url.endsWith("?format=txt")) … … 60 59 61 60 private String readLang(URL url) throws IOException { 62 InputStream in = url.openStream();61 BufferedReader in = Utils.openURLReader(url); 63 62 try { 64 return readFromTrac( new BufferedReader(new InputStreamReader(in, "utf-8")));63 return readFromTrac(in); 65 64 } finally { 66 65 in.close(); … … 78 77 } 79 78 80 pr ivateString readFromTrac(BufferedReader in) throws IOException {79 protected String readFromTrac(BufferedReader in) throws IOException { 81 80 boolean inside = false; 82 81 boolean transl = false;
Note:
See TracChangeset
for help on using the changeset viewer.