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:mtsar.csv.TaskCSVTest.java

@Test
public void testCSV() throws IOException {
    try (final PipedInputStream pis = new PipedInputStream()) {
        try (final PipedOutputStream pos = new PipedOutputStream(pis)) {
            TaskCSV.write(tasks, pos);//  w  w w  .j  a v  a  2s.  c o m

            try (final Reader reader = new InputStreamReader(pis, StandardCharsets.UTF_8)) {
                try (final CSVParser csv = new CSVParser(reader, TaskCSV.FORMAT)) {
                    final List<Task> parsed = Lists.newArrayList(TaskCSV.parse(stage, csv));
                    assertThat(parsed).hasSize(2);
                    assertThat(parsed).usingElementComparatorIgnoringFields("dateTime").isEqualTo(tasks);
                }
            }
        }
    }
}

From source file:org.bonitasoft.web.designer.controller.export.steps.HtmlExportStep.java

@Override
public void execute(Zipper zipper, Page page) throws IOException {
    zipper.addDirectoryToZip(Paths.get(resourceLoader.getResource(BACKEND_RESOURCES + "runtime").getURI()),
            RESOURCES);/*from w  w  w . j  a  va 2  s. c o  m*/

    byte[] html = generator.generateHtml(page).getBytes(StandardCharsets.UTF_8);
    zipper.addToZip(html, RESOURCES + "/index.html");
}

From source file:com.byteatebit.nbserver.simple.SimpleNbServerTestUdpService.java

@Override
public void accept(DatagramMessage message) {
    String payload = new String(message.getMessage(), StandardCharsets.UTF_8);
    LOG.info("received datagram message: " + payload);
    if (QUIT_CMD.equals(payload.toLowerCase())) {
        LOG.info("received quit command.  Will close the datagramChannel");
        writeDatagramTask.writeMessage(// w  w w.java  2s  .  com
                new DatagramMessage(message.getSocketAddress(), "goodbye".getBytes(StandardCharsets.UTF_8)),
                () -> {
                    LOG.info("Closing datagramChannel");
                    IOUtils.closeQuietly(datagramChannel);
                }, this::handleException);
        return;
    }
    writeDatagramTask.writeMessage(message, this::messageWritten, this::handleException);
}

From source file:resources.XmlToAnime.java

private static InputStream getInput() {
    String username = "shigato";
    String password = "unlimited0";
    String authString = username + ":" + password;
    byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
    String authStringEnc = new String(authEncBytes);
    InputStream in = null;/*from  w  ww .  jav a2  s.co m*/

    try {
        URL url = new URL(sUrl);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
        urlConnection.setRequestProperty("Accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        urlConnection.setRequestProperty("Accept-Language", "en");
        urlConnection.setRequestProperty("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36");
        in = urlConnection.getInputStream();
        String temp = InputStreamToString.getStringFromInputStream(in);
        temp = Replacer.replaceIllegalCharacters(temp);
        in = new ByteArrayInputStream(temp.getBytes(StandardCharsets.UTF_8));
        System.out.println();

        //            InputStreamReader isr = new InputStreamReader(in);
        //            
        //            int numCharsRead;
        //            char[] charArray = new char[1024];
        //            StringBuilder sb = new StringBuilder();
        //            while ((numCharsRead = isr.read(charArray)) > 0) {
        //                    sb.append(charArray, 0, numCharsRead);
        //            }
        //            String result = sb.toString();
        //            System.out.println(result);

    } catch (IOException e) {

    }
    return in;
}

From source file:com.formkiq.core.service.notification.MailSenderServiceTest.java

/**
 * testAfterPropertiesSet01()./*from  w w w  . jav  a  2  s .  co  m*/
 * expect JavaMailSenderImpl
 * @throws Exception Exception
 */
@Test
public void testAfterPropertiesSet01() throws Exception {
    // given
    final int port = 587;
    String data = "mail.host=smtp.gmail.com\n" + "mail.port=" + port + "\n" + "mail.username=test\n"
            + "mail.password=pass\n" + "mail.smtp.auth=true\n" + "mail.smtp.auth=true\n"
            + "mail.smtp.starttls.enable=true\n" + "mail.smtp.quitwait=false";

    InputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));

    MailSenderService ms = new MailSenderService();

    // when
    ms.afterPropertiesSet(is);

    // then
    assertTrue(ms.getMailSender() instanceof JavaMailSenderImpl);
    JavaMailSenderImpl js = (JavaMailSenderImpl) ms.getMailSender();
    assertEquals("smtp.gmail.com", js.getHost());
    assertEquals(port, js.getPort());
    assertEquals("test", js.getUsername());
    assertEquals("true", js.getJavaMailProperties().getProperty("mail.smtp.starttls.enable"));
    assertEquals("false", js.getJavaMailProperties().getProperty("mail.smtp.quitwait"));
    assertEquals("true", js.getJavaMailProperties().getProperty("mail.smtp.auth"));
}

From source file:com.qwazr.library.archiver.ArchiverTest.java

@Test
public void compressDecompress() throws CompressorException, IOException {
    Assert.assertNotNull(archiver);/*  www  .  ja  v a  2s .c om*/
    Path zipFile = Files.createTempFile("archiverToolTest", ".zip");
    archiver.compress(TEST_STRING, zipFile);
    Assert.assertEquals(TEST_STRING, archiver.decompressString(zipFile));
    Path clearFile = Files.createTempFile("archiverToolTest", ".txt");
    archiver.decompress(zipFile, clearFile);
    Assert.assertEquals(TEST_STRING, IOUtils.readPathAsString(clearFile, StandardCharsets.UTF_8));
}

From source file:integration.util.graylog.ServerHelper.java

public String getNodeId() throws MalformedURLException, URISyntaxException {
    final URI uri = IntegrationTestsConfig.getGlServerURL();
    ObjectMapper mapper = new ObjectMapper();

    try {//from ww w .ja  v  a2 s.co  m
        HttpURLConnection connection = (HttpURLConnection) new URL(uri.toURL(), "/system").openConnection();
        connection.setConnectTimeout(HTTP_TIMEOUT);
        connection.setReadTimeout(HTTP_TIMEOUT);
        connection.setRequestMethod("GET");

        if (uri.getUserInfo() != null) {
            String encodedUserInfo = Base64
                    .encodeBase64String(uri.getUserInfo().getBytes(StandardCharsets.UTF_8));
            connection.setRequestProperty("Authorization", "Basic " + encodedUserInfo);
        }

        InputStream inputStream = connection.getInputStream();
        JsonNode json = mapper.readTree(inputStream);
        return json.get("node_id").toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "00000000-0000-0000-0000-000000000000";
}

From source file:com.aqnote.shared.cryptology.cert.io.PKCSTransformer.java

public static String getCRLFileString(X509CRL x509CRL) throws Exception {
    CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE);
    PEMWriter pemWriter = new PEMWriter(new PrintWriter(cbb.getOutputStream()));
    cbb.getOutputStream().flush();//from   w w  w.jav a 2  s  .c  o m
    cbb.getOutputStream().close();
    pemWriter.writeObject(x509CRL);
    pemWriter.flush();
    pemWriter.close();
    String crlFile = StreamUtil.stream2Bytes(cbb.getInputStream(), StandardCharsets.UTF_8);
    cbb.getInputStream().close();
    cbb.clear();
    return crlFile;
}

From source file:com.ibm.g11n.pipeline.example.CSVFilter.java

@Override
public LanguageBundle parse(InputStream inStream, FilterOptions options)
        throws IOException, ResourceFilterException {
    LanguageBundleBuilder bundleBuilder = new LanguageBundleBuilder(true);
    CSVParser parser = CSVParser.parse(inStream, StandardCharsets.UTF_8,
            CSVFormat.RFC4180.withHeader("key", "value").withSkipHeaderRecord(true));
    for (CSVRecord record : parser) {
        String key = record.get(0);
        String value = record.get(1);
        bundleBuilder.addResourceString(key, value);
    }/*  ww w. j  a v  a 2 s.  com*/
    return bundleBuilder.build();
}

From source file:mtsar.csv.WorkerCSVTest.java

@Test
public void testCSV() throws IOException {
    try (final PipedInputStream pis = new PipedInputStream()) {
        try (final PipedOutputStream pos = new PipedOutputStream(pis)) {
            WorkerCSV.write(workers, pos);

            try (final Reader reader = new InputStreamReader(pis, StandardCharsets.UTF_8)) {
                try (final CSVParser csv = new CSVParser(reader, WorkerCSV.FORMAT)) {
                    final List<Worker> parsed = Lists.newArrayList(WorkerCSV.parse(stage, csv));
                    assertThat(parsed).hasSize(2);
                    assertThat(parsed).usingElementComparatorIgnoringFields("dateTime").isEqualTo(workers);
                }//from  w  w  w  . j a  v  a  2s .  c  o m
            }
        }
    }
}