*/
package org.sonar.api.server.rule;
-import com.google.common.io.Closeables;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.SMInputFactory;
import org.codehaus.staxmate.in.SMHierarchicCursor;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
* <severity>BLOCKER</severity>
* <cardinality>MULTIPLE</cardinality>
* <status>BETA</status>
+ * <tag>style</tag>
+ * <tag>security</tag>
* <param>
* <key>the-param-key</key>
- * <tag>style</tag>
- * <tag>security</tag>
* <description>
* <![CDATA[the param-description]]>
* </description>
public class RulesDefinitionXmlLoader implements ServerComponent {
public void load(RulesDefinition.NewRepository repo, InputStream input, String encoding) {
- Reader reader = null;
- try {
- reader = new InputStreamReader(input, encoding);
- load(repo, reader);
+ load(repo, input, Charset.forName(encoding));
+ }
+ /**
+ * @since 5.1
+ */
+ public void load(RulesDefinition.NewRepository repo, InputStream input, Charset charset) {
+ try (Reader reader = new InputStreamReader(input, charset)) {
+ load(repo, reader);
} catch (IOException e) {
- throw new IllegalStateException("Fail to load XML file", e);
-
- } finally {
- Closeables.closeQuietly(reader);
+ throw new IllegalStateException("Error while reading XML rules definition for repository " + repo.key(), e);
}
}