Example usage for java.nio.charset StandardCharsets UTF_8

List of usage examples for java.nio.charset StandardCharsets UTF_8

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets UTF_8.

Prototype

Charset UTF_8

To view the source code for java.nio.charset StandardCharsets UTF_8.

Click Source Link

Document

Eight-bit UCS Transformation Format.

Usage

From source file:com.thoughtworks.go.agent.statusapi.AgentStatusHttpdTest.java

@Test
void shouldReturnMethodNotAllowedOnNonGetNonHeadRequests() throws Exception {
    when(session.getMethod()).thenReturn(NanoHTTPD.Method.POST);
    NanoHTTPD.Response response = this.agentStatusHttpd.serve(session);
    assertThat(response.getStatus()).isEqualTo(NanoHTTPD.Response.Status.METHOD_NOT_ALLOWED);
    assertThat(response.getMimeType()).isEqualTo("text/plain; charset=utf-8");
    assertThat(IOUtils.toString(response.getData(), StandardCharsets.UTF_8))
            .isEqualTo("This method is not allowed. Please use GET or HEAD.");
}

From source file:com.haulmont.cuba.core.app.prettytime.CubaPrettyTimeParser.java

@PostConstruct
public void init() {
    StrTokenizer tokenizer = new StrTokenizer(serverConfig.getPrettyTimeProperties());
    try {//w  w w. jav  a2 s . c o m
        for (String fileName : tokenizer.getTokenArray()) {
            InputStream stream = null;

            try {
                stream = resources.getResourceAsStream(fileName);
                if (stream == null) {
                    throw new IllegalStateException("Resource is not found: " + fileName);
                }
                InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                Properties properties = new Properties() {
                    private Set orderedKeySet = new LinkedHashSet();

                    @Override
                    public Set<String> stringPropertyNames() {
                        return orderedKeySet;
                    }

                    @Override
                    public synchronized Object put(Object key, Object value) {
                        orderedKeySet.add(key);
                        return super.put(key, value);
                    }
                };
                properties.load(reader);
                for (String key : properties.stringPropertyNames()) {
                    String value = properties.getProperty(key);
                    replacements.put(key, value);
                }
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.github.runassudo.gtfs.ZipStreamGTFSFile.java

public FlatGTFSFile toFlatFile() throws IOException {
    File destBase = new File(
            new File(GTFSCollection.cacheDir,
                    Hashing.sha256().hashString(parentFile.getName(), StandardCharsets.UTF_8).toString()),
            Hashing.sha256().hashString(zipEntry.getName(), StandardCharsets.UTF_8).toString());

    if (!destBase.exists()) {
        ZipArchiveInputStream gtfsStream = new ZipArchiveInputStream(parentFile.getInputStream(zipEntry));
        ZipArchiveEntry contentEntry;/*from  w ww. java 2 s. com*/
        while ((contentEntry = gtfsStream.getNextZipEntry()) != null) {
            // Copy this file to cache
            File dest = new File(destBase, contentEntry.getName());
            dest.getParentFile().mkdirs();
            FileOutputStream os = new FileOutputStream(dest);
            byte[] buf = new byte[4096];
            int len;
            while ((len = gtfsStream.read(buf)) > 0) {
                os.write(buf, 0, len);
            }
            os.close();
        }
        gtfsStream.close();
    }

    return new FlatGTFSFile(destBase);
}

From source file:ee.ria.xroad.monitor.executablelister.ProcessListerTest.java

/**
 * Before test handler// w  ww  .  ja  v  a 2 s .c  om
 */
@Before
public void setup() throws Exception {

    processOutputString = FileUtils.readFileToString(new File(RESOURCE_PATH + "processlist.txt"),
            StandardCharsets.UTF_8.toString());

    log.info("string=" + processOutputString);
}

From source file:iristk.cfg.ABNFGrammar.java

public ABNFGrammar(String grammarString) throws IOException, GrammarException {
    readInputStream(new ByteArrayInputStream(grammarString.getBytes(StandardCharsets.UTF_8)));
}

From source file:com.atypon.wayf.facade.impl.ClientJsFacadeImpl.java

public void initTemplateFile() {
    if (templateFile == null) {
        try {/* w  w w. j ava 2  s  . c om*/
            templateFile = IOUtils.toString(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_FILE),
                    StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR,
                    "Could not read widget tempalte file", e);
        }
    }
}

From source file:com.linecorp.bot.model.event.CallbackRequestTest.java

private void parse(String resourceName, RequestTester callback) throws IOException {
    try (InputStream resource = getClass().getClassLoader().getResourceAsStream(resourceName)) {
        String json = StreamUtils.copyToString(resource, StandardCharsets.UTF_8);
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.registerModule(new JavaTimeModule())
                .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
        CallbackRequest callbackRequest = objectMapper.readValue(json, CallbackRequest.class);

        callback.call(callbackRequest);/*w w  w.  j a  v a 2s . c  o  m*/
    }
}

From source file:it.analysis.ReportDumpTest.java

/**
 * SONAR-6905//from  w w  w.j  a v  a  2s  .co m
 */
@Test
public void dump_metadata_of_uploaded_report() throws Exception {
    File projectDir = ItUtils.projectDir("shared/xoo-sample");
    orchestrator.executeBuild(SonarScanner.create(projectDir, "sonar.projectKey",
            "dump_metadata_of_uploaded_report", "sonar.projectName", "dump_metadata_of_uploaded_report"));

    File metadata = new File(projectDir, ".sonar/report-task.txt");
    assertThat(metadata).exists().isFile();

    // verify properties
    Properties props = new Properties();
    props.load(new StringReader(FileUtils.readFileToString(metadata, StandardCharsets.UTF_8)));
    assertThat(props).hasSize(6);
    assertThat(props.getProperty("projectKey")).isEqualTo("dump_metadata_of_uploaded_report");
    assertThat(props.getProperty("ceTaskId")).isNotEmpty();
    assertThat(props.getProperty("serverVersion")).isEqualTo(orchestrator.getServer().version().toString());
    verifyUrl(props.getProperty("serverUrl"));
    verifyUrl(props.getProperty("dashboardUrl"));
    verifyUrl(props.getProperty("ceTaskUrl"));
}

From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java

protected Server createServer(int port, String displayName) throws Exception {
    FileUtils.deleteDirectory(new File("target/repo" + displayName));
    System.setProperty("simplerepo.root", "target/repo" + displayName);
    File repoRoot = new File("target/repo" + displayName);
    repoRoot.mkdirs();/*w  ww .ja  v a 2  s . c  o  m*/
    Files.write(new File(repoRoot, "config.properties").toPath(), Arrays.asList("plugins="),
            StandardCharsets.UTF_8);
    Server server = new Server(port);
    FileUtils.copyDirectory(new File("src/main/webapp"), new File("target/server"));
    WebAppContext app = new WebAppContext("target/server", "/simple-repo");
    app.setAttribute("contextName", displayName);
    app.setExtractWAR(true);
    app.getSecurityHandler()
            .setLoginService(new HashLoginService("Test realm", "src/test/resources/realm.properties"));
    app.setDisplayName(displayName);
    server.setHandler(app);
    server.start();
    return server;
}

From source file:com.sg.sg_rest_api.integration.test.SigninFlowTest.java

@Test
public void testSuccessfullSignin() throws IOException {
    SigninDto dto = new SigninDto();
    dto.setEmail(ADMIN_EMAIL);// w  w w . j  a v  a  2  s.com
    dto.setPassword(ADMIN_PASSWORD);
    Response r = given().log().all().contentType(ContentType.JSON.withCharset(StandardCharsets.UTF_8))
            .body(jacksonObjectMapper.writeValueAsString(dto)).when().post(RequestPath.REQUEST_SIGNIN);

    r.then().log().all().statusCode(HttpStatus.SC_OK).contentType(ContentType.JSON)
            .body("status", equalTo(SigninStatus.STATUS_SUCCESS))
            .header(CustomHeaders.X_AUTH_TOKEN, any(String.class));
}