aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-16 10:55:06 +0200
committerDavid Gageot <david@gageot.net>2012-07-16 10:55:23 +0200
commit20fdc6307577de2cce22d6c24ba64c9d382400ff (patch)
tree4df9ed8ba5d6525e48018767fb3db4b30c215a2c
parent8174c0b7e067391c3284d75eff2a396c56415f6f (diff)
downloadsonarqube-20fdc6307577de2cce22d6c24ba64c9d382400ff.tar.gz
sonarqube-20fdc6307577de2cce22d6c24ba64c9d382400ff.zip
Don't use hardcoded charsets
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java6
2 files changed, 6 insertions, 4 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
index 158dac6bbca..a35feabb679 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.bootstrap;
+import com.google.common.base.Charsets;
+
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.CharUtils;
@@ -89,7 +91,7 @@ public class ArtifactDownloader implements BatchComponent {
String url = baseUrl + "/deploy/plugins/index.txt";
try {
LOG.debug("Downloading index of plugins");
- String indexContent = httpDownloader.downloadPlainText(new URI(url), "UTF-8");
+ String indexContent = httpDownloader.downloadPlainText(new URI(url), Charsets.UTF_8);
String[] rows = StringUtils.split(indexContent, CharUtils.LF);
List<RemotePlugin> remoteLocations = Lists.newArrayList();
for (String row : rows) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
index 94e7c80e26f..d46558fabe9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
@@ -155,12 +155,12 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
}
}
- public String downloadPlainText(URI uri, String encoding) {
+ public String downloadPlainText(URI uri, Charset charset) {
InputStream input = null;
try {
HttpURLConnection connection = newHttpConnection(uri);
input = connection.getInputStream();
- return IOUtils.toString(input, encoding);
+ return IOUtils.toString(input, charset.name());
} catch (Exception e) {
throw new SonarException("Fail to download the file: " + uri + " (" + getProxySynthesis(uri) + ")", e);
@@ -182,7 +182,7 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
@Override
String readString(URI uri, Charset charset) {
- return downloadPlainText(uri, charset.name());
+ return downloadPlainText(uri, charset);
}
private HttpURLConnection newHttpConnection(URI uri) throws IOException {