*/
package org.sonar.process.monitor;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public void run() {
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8));
try {
String line;
while ((line = br.readLine()) != null) {
*/
package org.sonar.process;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.text.StrSubstitutor;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
File propertyFile = new File(args[0]);
Properties properties = new Properties();
- FileReader reader = null;
+ Reader reader = null;
try {
- reader = new FileReader(propertyFile);
+ reader = new InputStreamReader(new FileInputStream(propertyFile), Charsets.UTF_8);
properties.load(reader);
} catch (Exception e) {
throw new IllegalStateException("Could not read properties from file: " + args[0], e);
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
+import org.apache.commons.io.Charsets;
import org.picocontainer.Startable;
import org.sonar.api.Plugin;
import org.sonar.api.ServerExtension;
public Reader createReaderForXMLFile(String pluginKey) {
ClassLoader classLoader = contributingPluginKeyToClassLoader.get(pluginKey);
String xmlFilePath = getXMLFilePath(pluginKey);
- return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath));
+ return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath), Charsets.UTF_8);
}
@VisibleForTesting
- Map<String, ClassLoader> getContributingPluginKeyToClassLoader(){
+ Map<String, ClassLoader> getContributingPluginKeyToClassLoader() {
return contributingPluginKeyToClassLoader;
}
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;
+import org.apache.commons.io.Charsets;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.ServerComponent;
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", DEFAULT_INDENT);
- Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes())));
+ Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8))));
StreamResult res = new StreamResult(new ByteArrayOutputStream());
serializer.transform(xmlSource, res);
- return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray());
- } catch (TransformerConfigurationException ignored) {
- // Ignore, raw XML will be returned
+ return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray(), Charsets.UTF_8);
} catch (TransformerException ignored) {
// Ignore, raw XML will be returned
}
*/
package org.sonar.server.qualityprofile;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
}
if (fromProfile.getName().equals(toProfileName.getName())) {
throw new IllegalArgumentException(String.format("Source and target profiles are equal: %s",
- fromProfile.getName(), toProfileName.getName()));
+ fromProfile.getName()));
}
}
private void backup(String profileKey, File backupFile) {
Writer writer = null;
try {
- writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile));
+ writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), Charsets.UTF_8);
backuper.backup(profileKey, writer);
} catch (IOException e) {
throw new IllegalStateException("Fail to open temporary backup file: " + backupFile, e);
private void restore(File backupFile, QProfileName profileName) {
Reader reader = null;
try {
- reader = new InputStreamReader(FileUtils.openInputStream(backupFile));
+ reader = new InputStreamReader(FileUtils.openInputStream(backupFile), Charsets.UTF_8);
backuper.restore(reader, profileName);
} catch (IOException e) {
throw new IllegalStateException("Fail to create temporary backup file: " + backupFile, e);
package org.sonar.server.rule.ws;
import com.google.common.base.Strings;
+import org.apache.commons.io.Charsets;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
Response.Stream stream = response.stream();
stream.setStatus(409);
stream.setMediaType(MimeTypes.JSON);
- JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output())).beginObject().name("rule");
+ JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8)).beginObject().name("rule");
mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */);
json.endObject().close();
}
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.Writer;
/**
* @since 2.11
void writeIndex(File indexFile) throws IOException {
FileUtils.forceMkdir(indexFile.getParentFile());
- FileWriter writer = new FileWriter(indexFile, false);
+ Writer writer = new FileWriter(indexFile, false);
try {
for (PluginMetadata metadata : repository.getMetadata()) {
writer.append(RemotePlugin.create((DefaultPluginMetadata) metadata).marshal());
*/
package org.sonar.server.ws;
+import com.google.common.base.Charsets;
import org.sonar.api.server.ws.Response;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.utils.text.XmlWriter;
}
public String outputAsString() {
- return output.toString();
+ return new String(output.toByteArray(), Charsets.UTF_8);
}
public ServletStream reset() {
@Override
public JsonWriter newJsonWriter() {
stream.setMediaType(MimeTypes.JSON);
- return JsonWriter.of(new OutputStreamWriter(stream.output()));
+ return JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8));
}
@Override
public XmlWriter newXmlWriter() {
stream.setMediaType(MimeTypes.XML);
- return XmlWriter.of(new OutputStreamWriter(stream.output()));
+ return XmlWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8));
}
@Override
*/
package org.sonar.server.ws;
+import com.google.common.base.Charsets;
import org.picocontainer.Startable;
import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
stream.reset();
stream.setStatus(status);
stream.setMediaType(MimeTypes.JSON);
- JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output()));
+ JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8));
try {
json.beginObject();
import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;
+import org.apache.commons.io.Charsets;
import org.sonar.channel.CodeReader;
import java.io.IOException;
InputStream input = null;
try {
input = HtmlRenderer.class.getResourceAsStream(CSS_PATH);
- return new String(ByteStreams.toByteArray(input));
+ return new String(ByteStreams.toByteArray(input), Charsets.UTF_8);
} catch (IOException e) {
throw new SynhtaxHighlightingException("SonarQube Colorizer CSS file not found: " + CSS_PATH, e);
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
+import org.apache.commons.io.Charsets;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
* Creates a vertex from GraphSON using settings supplied in the constructor.
*/
Vertex vertexFromJson(InputStream json) throws ParseException, IOException {
- return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json)));
+ return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8)));
}
/**
* Creates an edge from GraphSON using settings supplied in the constructor.
*/
Edge edgeFromJson(InputStream json, Vertex out, Vertex in) throws IOException, ParseException {
- return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json)), out, in);
+ return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8)), out, in);
}
/**
*/
package org.sonar.api.utils;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new FileReader(file));
+ buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
parse(buffer);
} catch (IOException e) {
public void parse(InputStream stream) {
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new InputStreamReader(stream));
+ buffer = new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8));
parse(buffer);
} catch (IOException e) {
public void parse(String xml) {
try {
- xml = fixUnicodeChar(xml);
- doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ String fixedXml = fixUnicodeChar(xml);
+ doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(Charsets.UTF_8)));
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
- } catch (SAXException e) {
- throw new XmlParserException(CAN_NOT_PARSE_XML + xml, e);
- } catch (IOException e) {
+ } catch (IOException | SAXException e) {
throw new XmlParserException(CAN_NOT_PARSE_XML + xml, e);
}
}
*/
package org.sonar.test.i18n;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
dumpFile.delete();
}
dumpFile.getParentFile().mkdirs();
- FileWriter writer = null;
+ Writer writer = null;
try {
- writer = new FileWriter(dumpFile);
+ writer = new OutputStreamWriter(new FileOutputStream(dumpFile), Charsets.UTF_8);
writer.write(details);
} catch (IOException e) {
throw new IllegalStateException("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'", e);