- Timestamp:
- 2017-09-08T23:34:46+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r12620 r12794 122 122 } 123 123 URL url = new URL(pi.downloadlink); 124 synchronized (this) { 125 downloadConnection = HttpClient.create(url).setAccept(PLUGIN_MIME_TYPES); 126 downloadConnection.connect(); 127 } 128 try (InputStream in = downloadConnection.getResponse().getContent()) { 129 Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); 124 Logging.debug("Download plugin {0} from {1}...", pi.name, url); 125 if ("https".equals(url.getProtocol()) || "http".equals(url.getProtocol())) { 126 synchronized (this) { 127 downloadConnection = HttpClient.create(url).setAccept(PLUGIN_MIME_TYPES); 128 downloadConnection.connect(); 129 } 130 try (InputStream in = downloadConnection.getResponse().getContent()) { 131 Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); 132 } 133 } else { 134 // this is an alternative for e.g. file:// URLs where HttpClient doesn't work 135 try (InputStream in = url.openConnection().getInputStream()) { 136 Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); 137 } 130 138 } 131 139 } catch (MalformedURLException e) { -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r12620 r12794 11 11 import java.io.IOException; 12 12 import java.io.InputStream; 13 import java.io.InputStreamReader; 13 14 import java.io.PrintWriter; 14 15 import java.net.MalformedURLException; … … 155 156 monitor.indeterminateSubTask(tr("Downloading plugin list from ''{0}''", printsite)); 156 157 157 URL url = new URL(site); 158 connection = HttpClient.create(url).useCache(false); 159 final HttpClient.Response response = connection.connect(); 160 content = response.fetchContent(); 161 if (response.getResponseCode() != 200) { 162 throw new IOException(tr("Unsuccessful HTTP request")); 163 } 164 return content; 158 final URL url = new URL(site); 159 if ("https".equals(url.getProtocol()) || "http".equals(url.getProtocol())) { 160 connection = HttpClient.create(url).useCache(false); 161 final HttpClient.Response response = connection.connect(); 162 content = response.fetchContent(); 163 if (response.getResponseCode() != 200) { 164 throw new IOException(tr("Unsuccessful HTTP request")); 165 } 166 return content; 167 } else { 168 // e.g. when downloading from a file:// URL, we can't use HttpClient 169 try (InputStreamReader in = new InputStreamReader(url.openConnection().getInputStream(), StandardCharsets.UTF_8)) { 170 final StringBuilder sb = new StringBuilder(); 171 final char[] buffer = new char[8192]; 172 int numChars; 173 while ((numChars = in.read(buffer)) >= 0) { 174 sb.append(buffer, 0, numChars); 175 if (canceled) { 176 return null; 177 } 178 } 179 return sb.toString(); 180 } 181 } 182 165 183 } catch (MalformedURLException e) { 166 184 if (canceled) return null;
Note:
See TracChangeset
for help on using the changeset viewer.