Example usage for org.apache.commons.io Charsets UTF_8

List of usage examples for org.apache.commons.io Charsets UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for org.apache.commons.io Charsets UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:org.sonar.plugins.gosu.sqale.RemediationEffortExtractor.java

public void toCSV(String remediationFileLocation) {
    File file = new File(remediationFileLocation);
    if (!file.exists() || file.delete()) {
        try {//from   w ww  . j ava  2  s.c om
            Path path = Paths.get(file.getAbsolutePath());
            Files.write(path, getLines(), Charsets.UTF_8);
        } catch (IOException e) {
            throw new IllegalStateException("Unable to create file at this location: " + file.getAbsolutePath(),
                    e);
        }
    } else {
        throw new IllegalStateException("Unable to create file at this location: " + file.getAbsolutePath());
    }
}

From source file:org.sonar.server.db.migrations.v50.FeedFileSourcesTest.java

private void migrate_sources_with_scm_and_coverage_in(String columnName) throws Exception {
    db.prepareDbUnit(getClass(), "before.xml");

    Connection connection = null;
    try {//from   www  .  j a  v a2  s .c o  m
        connection = db.openConnection();

        connection
                .prepareStatement("insert into snapshot_sources " + "(snapshot_id, data, updated_at) "
                        + "values " + "(6, 'class Foo {\r\n  // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')")
                .executeUpdate();

        db.executeUpdateSql("insert into snapshot_sources " + "(snapshot_id, data, updated_at) " + "values "
                + "(7, '', '2014-10-31 16:44:02.000')");

        PreparedStatement revisionStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(1, 6, ?)");
        revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(Charsets.UTF_8));
        revisionStmt.executeUpdate();

        PreparedStatement authorStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(2, 6, ?)");
        authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(Charsets.UTF_8));
        authorStmt.executeUpdate();

        PreparedStatement dateStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(3, 6, ?)");
        dateStmt.setBytes(1,
                "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100"
                        .getBytes(Charsets.UTF_8));
        dateStmt.executeUpdate();

        PreparedStatement utHitsStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(4, 6, ?)");
        utHitsStmt.setBytes(1, "1=1;3=0".getBytes(Charsets.UTF_8));
        utHitsStmt.executeUpdate();

        PreparedStatement utCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(5, 6, ?)");
        utCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8));
        utCondStmt.executeUpdate();

        PreparedStatement utCoveredCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(6, 6, ?)");
        utCoveredCondStmt.setBytes(1, "1=2".getBytes(Charsets.UTF_8));
        utCoveredCondStmt.executeUpdate();

        PreparedStatement itHitsStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(7, 6, ?)");
        itHitsStmt.setBytes(1, "1=2;3=0".getBytes(Charsets.UTF_8));
        itHitsStmt.executeUpdate();

        PreparedStatement itCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(8, 6, ?)");
        itCondStmt.setBytes(1, "1=5".getBytes(Charsets.UTF_8));
        itCondStmt.executeUpdate();

        PreparedStatement itCoveredCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(9, 6, ?)");
        itCoveredCondStmt.setBytes(1, "1=3".getBytes(Charsets.UTF_8));
        itCoveredCondStmt.executeUpdate();

        PreparedStatement overallHitsStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(10, 6, ?)");
        overallHitsStmt.setBytes(1, "1=3;3=0".getBytes(Charsets.UTF_8));
        overallHitsStmt.executeUpdate();

        PreparedStatement overallCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(11, 6, ?)");
        overallCondStmt.setBytes(1, "1=6".getBytes(Charsets.UTF_8));
        overallCondStmt.executeUpdate();

        PreparedStatement overallCoveredCondStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(12, 6, ?)");
        overallCoveredCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8));
        overallCoveredCondStmt.executeUpdate();

        PreparedStatement duplicationDataStmt = connection.prepareStatement("insert into project_measures "
                + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(13, 6, ?)");
        duplicationDataStmt.setBytes(1,
                "<duplications><g><b s=\"1\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"2\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"3\" l=\"1\" r=\"MyProject:src/main/xoo/prj/AnotherFile.xoo\"/></g></duplications>"
                        .getBytes(Charsets.UTF_8));
        duplicationDataStmt.executeUpdate();
    } finally {
        DbUtils.commitAndCloseQuietly(connection);
    }

    migration.execute();

    db.assertDbUnit(getClass(), "after-with-scm.xml", "file_sources");
}

From source file:org.sonar.server.debt.DebtModelPluginRepository.java

/**
 * Creates a new {@link java.io.Reader} for the XML file that contains the model contributed by the given plugin.
 *
 * @param pluginKey the key of the plugin that contributes the XML file
 * @return the reader, that must be closed once its use is finished.
 *///  ww w .  j a v  a 2s .com
public Reader createReaderForXMLFile(String pluginKey) {
    ClassLoader classLoader = contributingPluginKeyToClassLoader.get(pluginKey);
    String xmlFilePath = getXMLFilePath(pluginKey);
    return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath), Charsets.UTF_8);
}

From source file:org.sonar.server.rule.ws.CreateAction.java

private void write409(Response response, RuleKey ruleKey) {
    Rule rule = service.getNonNullByKey(ruleKey);

    Response.Stream stream = response.stream();
    stream.setStatus(409);//ww  w. ja v a  2 s .c  om
    stream.setMediaType(MimeTypes.JSON);
    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();
}

From source file:org.sonar.server.source.ws.HashAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    DbSession session = dbClient.openSession(false);
    try {//from w  ww.  ja va 2  s  . co m
        String componentKey = request.mandatoryParam("key");
        UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, componentKey);
        ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
        String lineHashes = fileSourceDao.selectLineHashes(component.uuid(), session);
        if (lineHashes == null) {
            response.noContent();
        } else {
            OutputStream output = response.stream().setMediaType("text/plain").output();
            output.write(lineHashes.getBytes(Charsets.UTF_8));
            output.close();
        }
    } finally {
        session.close();
    }
}

From source file:org.sonar.server.source.ws.RawAction.java

@Override
public void handle(Request request, Response response) {
    String fileKey = request.mandatoryParam("key");
    UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey);
    DbSession session = dbClient.openSession(false);
    try {//ww w .  ja v  a  2  s.co  m
        ComponentDto componentDto = dbClient.componentDao().getByKey(session, fileKey);
        List<String> lines = sourceService.getLinesAsTxt(componentDto.uuid(), null, null);
        response.stream().setMediaType("text/plain");
        IOUtils.writeLines(lines, "\n", response.stream().output(), Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException("Fail to write raw source of file " + fileKey, e);
    } finally {
        session.close();
    }
}

From source file:org.sonar.zaproxy.rule.ZapRuleDefinition.java

private void loadDefaultZAProxyRules(NewRepository repository) {
    xmlLoader.load(repository, getClass().getResourceAsStream(ZapPlugin.RULES_FILE), Charsets.UTF_8);
}

From source file:org.sonarqube.tests.performance.ServerLogs.java

/**
 * 2015.09.29 16:57:45 INFO ce[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
 *//*from   www .j a va2s. c o  m*/
public static Long extractComputationTotalTime(Orchestrator orchestrator) throws IOException {
    File report = orchestrator.getServer().getCeLogs();
    List<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
    return extractComputationTotalTime(logsLines);
}

From source file:org.spongepowered.repoindexer.EntryPoint.java

private static String getIndex(Artifact artifact) throws IOException {

    URL u = new URL(artifact.getRepo().getUrl() + artifact.getGroupId().replace(".", "/") + "/"
            + artifact.getArtifactId().replace(".", "/") + "/" + "maven-metadata.xml");
    System.out.println("Downloading " + u.toExternalForm());
    return IOUtils.toString(u, Charsets.UTF_8);
}

From source file:org.spongepowered.repoindexer.WebHandler.java

public static void createWebpage(File input, File output, String title, List<ResolvedArtifact> artifactList,
        String projectName) {/*from ww  w .j  a v  a 2 s.  c  o  m*/
    try {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(FileUtils.readFileToString(input)), "example");
        //mustache.execute(new PrintWriter(System.out), new MustacheData(title, artifactList)).flush();
        mustache.execute(new FileWriterWithEncoding(output, Charsets.UTF_8),
                new MustacheData(title, artifactList)).flush();

    } catch (Exception e) {
        e.printStackTrace();
    }

}