diff --git a/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java b/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
index 40231cb4c5..fcb5858867 100644
|
a
|
b
|
public class PluginDownloadTask extends PleaseWaitRunnable {
|
| 121 | 121 | throw new PluginDownloadException(msg); |
| 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) { |
| 132 | 140 | String msg = tr("Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", |
diff --git a/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java b/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
index 324a33121a..aa3012b083 100644
|
a
|
b
|
import java.io.File;
|
| 10 | 10 | import java.io.FilenameFilter; |
| 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; |
| 15 | 16 | import java.net.URL; |
| … |
… |
public class ReadRemotePluginInformationTask extends PleaseWaitRunnable {
|
| 154 | 155 | monitor.beginTask(""); |
| 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")); |
| | 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 | } |
| 163 | 181 | } |
| 164 | | return content; |
| | 182 | |
| 165 | 183 | } catch (MalformedURLException e) { |
| 166 | 184 | if (canceled) return null; |
| 167 | 185 | Logging.error(e); |