]> source.dussan.org Git - sonarqube.git/commitdiff
Don't use hardcoded charsets
authorDavid Gageot <david@gageot.net>
Mon, 16 Jul 2012 08:55:06 +0000 (10:55 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 16 Jul 2012 08:55:23 +0000 (10:55 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java

index 158dac6bbcaeb65bdc6a867d7056721a453b7fe9..a35feabb679776160e6942df2e6154ca3a601a9d 100644 (file)
@@ -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) {
index 94e7c80e26f3a9bdf3fa055cff59c218ede7f143..d46558fabe9368c270cf9ed596d2ba221370847d 100644 (file)
@@ -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 {