diff --git a/java/java-impl/src/com/intellij/jarFinder/SourceSearcher.java b/java/java-impl/src/com/intellij/jarFinder/SourceSearcher.java
index b1d635af8525..ef945aceefbc 100644
--- a/java/java-impl/src/com/intellij/jarFinder/SourceSearcher.java
+++ b/java/java-impl/src/com/intellij/jarFinder/SourceSearcher.java
@@ -16,7 +16,6 @@ import java.net.HttpURLConnection;
* @author Sergey Evdokimov
*/
public abstract class SourceSearcher {
-
/**
* @param indicator
* @param artifactId
diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java
index 0879df6ce464..b66e76de4858 100644
--- a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java
+++ b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java
@@ -7,17 +7,18 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.util.ObjectUtils;
import com.intellij.util.Producer;
import com.intellij.util.containers.Predicate;
-import com.intellij.util.net.HttpConfigurable;
+import com.intellij.util.io.HttpRequests;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
-import java.net.URLConnection;
import java.util.Locale;
import java.util.concurrent.Callable;
@@ -34,28 +35,27 @@ public class DownloadUtil {
* {@code outputFile} isn't modified if an I/O error occurs or {@code contentChecker} is provided and returns false on the downloaded content.
* More formally, the steps are:
*
- * - Download {@code url} to {@code tempFile}. Stop in case of any I/O errors.
- * - Stop if {@code contentChecker} is provided, and it returns false on the downloaded content.
- * - Move {@code tempFile} to {@code outputFile}. On most OS this operation is done atomically.
+ * - Download {@code url} to {@code tempFile}. Stop in case of any I/O errors.
+ * - Stop if {@code contentChecker} is provided, and it returns false on the downloaded content.
+ * - Move {@code tempFile} to {@code outputFile}. On most OS this operation is done atomically.
*
- *
+ *
* Motivation: some web filtering products return pure HTML with HTTP 200 OK status instead of
* the asked content.
*
- * @param indicator progress indicator
- * @param url url to download
- * @param outputFile output file
- * @param tempFile temporary file to download to. This file is deleted on method exit.
+ * @param indicator progress indicator
+ * @param url url to download
+ * @param outputFile output file
+ * @param tempFile temporary file to download to. This file is deleted on method exit.
* @param contentChecker checks whether the downloaded content is OK or not
- * @returns true if no {@code contentChecker} is provided or the provided one returned true
* @throws IOException if an I/O error occurs
+ * @returns true if no {@code contentChecker} is provided or the provided one returned true
*/
public static boolean downloadAtomically(@Nullable ProgressIndicator indicator,
- @NotNull String url,
- @NotNull File outputFile,
- @NotNull File tempFile,
- @Nullable Predicate contentChecker) throws IOException
- {
+ @NotNull String url,
+ @NotNull File outputFile,
+ @NotNull File tempFile,
+ @Nullable Predicate contentChecker) throws IOException {
try {
downloadContentToFile(indicator, url, tempFile);
if (contentChecker != null) {
@@ -66,7 +66,8 @@ public class DownloadUtil {
}
FileUtil.rename(tempFile, outputFile);
return true;
- } finally {
+ }
+ finally {
FileUtil.delete(tempFile);
}
}
@@ -75,14 +76,13 @@ public class DownloadUtil {
* Downloads content of {@code url} to {@code outputFile} atomically.
* {@code outputFile} won't be modified in case of any I/O download errors.
*
- * @param indicator progress indicator
- * @param url url to download
- * @param outputFile output file
+ * @param indicator progress indicator
+ * @param url url to download
+ * @param outputFile output file
*/
public static void downloadAtomically(@Nullable ProgressIndicator indicator,
@NotNull String url,
- @NotNull File outputFile) throws IOException
- {
+ @NotNull File outputFile) throws IOException {
File tempFile = FileUtil.createTempFile("for-actual-downloading-", null);
downloadAtomically(indicator, url, outputFile, tempFile, null);
}
@@ -91,16 +91,15 @@ public class DownloadUtil {
* Downloads content of {@code url} to {@code outputFile} atomically.
* {@code outputFile} won't be modified in case of any I/O download errors.
*
- * @param indicator progress indicator
- * @param url url to download
- * @param outputFile output file
- * @param tempFile temporary file to download to. This file is deleted on method exit.
+ * @param indicator progress indicator
+ * @param url url to download
+ * @param outputFile output file
+ * @param tempFile temporary file to download to. This file is deleted on method exit.
*/
public static void downloadAtomically(@Nullable ProgressIndicator indicator,
@NotNull String url,
@NotNull File outputFile,
- @NotNull File tempFile) throws IOException
- {
+ @NotNull File tempFile) throws IOException {
downloadAtomically(indicator, url, outputFile, tempFile, null);
}
@@ -111,8 +110,7 @@ public class DownloadUtil {
@NotNull String progressTitle,
@NotNull final String actionShortDescription,
@NotNull final Callable supplier,
- @Nullable Producer tryAgainProvider)
- {
+ @Nullable Producer tryAgainProvider) {
int attemptNumber = 1;
while (true) {
final Ref dataRef = Ref.create(null);
@@ -160,44 +158,45 @@ public class DownloadUtil {
OutputStream out = new FileOutputStream(outputFile);
try {
download(progress, url, out);
- } finally {
+ }
+ finally {
out.close();
}
}
- private static void download(@Nullable ProgressIndicator progress,
- @NotNull String location,
- @NotNull OutputStream output) throws IOException {
- String originalText = progress != null ? progress.getText() : null;
+ private static void download(@Nullable final ProgressIndicator progress,
+ @NotNull final String location,
+ @NotNull final OutputStream output) throws IOException {
+ final String originalText = progress != null ? progress.getText() : null;
substituteContentLength(progress, originalText, -1);
if (progress != null) {
progress.setText2("Downloading " + location);
}
- URLConnection urlConnection = HttpConfigurable.getInstance().openConnection(location);
- HttpURLConnection httpURLConnection = ObjectUtils.tryCast(urlConnection, HttpURLConnection.class);
+
try {
- urlConnection.setRequestProperty("User-Agent", ApplicationInfoEx.getInstanceEx().getFullApplicationName());
- urlConnection.connect();
- InputStream in = urlConnection.getInputStream();
- int contentLength = urlConnection.getContentLength();
- substituteContentLength(progress, originalText, contentLength);
- NetUtils.copyStreamContent(progress, in, output, contentLength);
- } catch (IOException e) {
- String errorMessage = "Can not download '" + location + ", headers: " + urlConnection.getHeaderFields();
- if (httpURLConnection != null) {
- errorMessage += "', response code: " + httpURLConnection.getResponseCode()
- + ", response message: " + httpURLConnection.getResponseMessage();
- }
- throw new IOException(errorMessage, e);
+ HttpRequests.request(location)
+ .userAgent(ApplicationInfoEx.getInstanceEx().getFullApplicationName())
+ .connect(new HttpRequests.RequestProcessor