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:org.bonitasoft.web.designer.model.JacksonObjectMapper.java

public byte[] toJson(Object object) throws IOException {
    // Use UTF8 to accept any character and have platform-independent files.
    return objectMapper.writeValueAsString(object).getBytes(StandardCharsets.UTF_8);
}

From source file:ai.susi.tools.JsonSignature.java

public static void addSignature(Map<String, byte[]> obj, PrivateKey key)
        throws InvalidKeyException, SignatureException {

    removeSignature(obj);//from  ww  w.  j ava2 s.co m

    Signature signature;
    try {
        signature = Signature.getInstance("SHA256withRSA");
    } catch (NoSuchAlgorithmException e) {
        return; //does not happen
    }

    signature.initSign(key);
    signature.update(obj.toString().getBytes(StandardCharsets.UTF_8));

    byte[] sigBytes = signature.sign();

    obj.put(signatureString, Base64.getEncoder().encode(sigBytes));
}

From source file:com.twosigma.beakerx.security.HashedMessageAuthenticationCode.java

public HashedMessageAuthenticationCode(String key) {
    checkNotNull(key);/*from   w w w. j a  va 2 s. c o m*/
    logger.debug("Using signing hmac: {}", key);
    spec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), TYPE);
}

From source file:com.github.khazrak.jdocker.utils.Filters.java

public static String encodeFilters(Map<String, String> filters) {
    ObjectMapper mapper = new ObjectMapper();
    String result = null;//from w  ww. ja va2s.co  m
    ObjectNode objectNode = mapper.createObjectNode();
    if (!filters.keySet().isEmpty()) {
        for (Map.Entry<String, String> s : filters.entrySet()) {
            objectNode.putObject(s.getKey()).put(s.getValue(), true);
        }
    }

    try {
        result = URLEncoder.encode(objectNode.toString(), StandardCharsets.UTF_8.toString());
    } catch (UnsupportedEncodingException e) {
        logger.error("Error encoding filtersMap", e);
    }
    return result;
}

From source file:com.lexicalintelligence.admin.save.SaveRequest.java

public SaveResponse execute() {
    SaveResponse saveResponse;/*from   ww w .j  av a 2  s .com*/
    Reader reader = null;
    try {
        HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath()));
        reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8);
        saveResponse = new SaveResponse(Boolean.valueOf(IOUtils.toString(reader)));
    } catch (Exception e) {
        saveResponse = new SaveResponse(false);
        log.error(e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            log.error(e);
        }
    }
    return saveResponse;
}

From source file:com.hurence.logisland.processor.hbase.io.TestJsonFullRowSerializer.java

@Before
public void setup() {
    final byte[] cell1Fam = FAM1.getBytes(StandardCharsets.UTF_8);
    final byte[] cell1Qual = QUAL1.getBytes(StandardCharsets.UTF_8);
    final byte[] cell1Val = VAL1.getBytes(StandardCharsets.UTF_8);

    final byte[] cell2Fam = FAM2.getBytes(StandardCharsets.UTF_8);
    final byte[] cell2Qual = QUAL2.getBytes(StandardCharsets.UTF_8);
    final byte[] cell2Val = VAL2.getBytes(StandardCharsets.UTF_8);

    final ResultCell cell1 = getResultCell(cell1Fam, cell1Qual, cell1Val, TS1);
    final ResultCell cell2 = getResultCell(cell2Fam, cell2Qual, cell2Val, TS2);

    cells = new ResultCell[] { cell1, cell2 };
}

From source file:com.ariht.maven.plugins.config.ConfigGenerationMojoTest.java

/**
 * Using example inputs in the src/test/resources io show how the plugin
 * combines each template and filter./* www .j a va2 s  .  c o  m*/
 */
@Test
public void testReadingDirectory() throws MojoExecutionException, MojoFailureException, IOException {
    final ConfigGenerationMojo configGenerationMojo = new ConfigGenerationMojo();

    configGenerationMojo.encoding = StandardCharsets.UTF_8.name();
    configGenerationMojo.templatesBasePath = getAbsolutePath("templates");
    configGenerationMojo.filtersBasePath = getAbsolutePath("filters");
    configGenerationMojo.outputBasePath = getAbsolutePath("../generated-unit-tests-config");
    configGenerationMojo.setLog(new TestsLogger());
    configGenerationMojo.logOutput = true;
    configGenerationMojo.filtersToIgnore = Lists.newArrayList(getAbsolutePath("filters/personal/README"));
    configGenerationMojo.templatesToIgnore = Lists.newLinkedList();
    configGenerationMojo.propertyPrefix = "${";
    configGenerationMojo.propertySuffix = "}";
    configGenerationMojo.failOnMissingProperty = true;
    configGenerationMojo.filterSourcePropertyName = "filter.source";

    final List<String> externalFiltersBasePath = new LinkedList<String>();
    final String externalTestFilters = getAbsolutePath("externalTestFilters");
    externalFiltersBasePath.add(externalTestFilters);
    configGenerationMojo.externalFilterBasePaths = externalFiltersBasePath;
    configGenerationMojo.execute();
}

From source file:com.vaadin.framework8.demo.restjson.RestDataProvider.java

@Override
public Stream<JsonObject> fetchFromBackEnd(Query<JsonObject, Void> query) {
    URL url;/* ww  w  . j  a  va 2 s . co  m*/
    try {
        url = new URL(restApiUrl);
        String jsonData = IOUtils.toString(url, StandardCharsets.UTF_8);
        JsonObject json = Json.parse(jsonData);

        JsonArray results = json.getArray("results");
        return stream(results);
    } catch (IOException e) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error fetching JSON", e);
        // Must return something which matches size, or grid will keep
        // asking and asking...
        return IntStream.range(0, 200).mapToObj(i -> Json.createObject());
    }
}

From source file:com.jivesoftware.os.amza.api.ring.RingHost.java

public static RingHost fromBytes(byte[] bytes) throws Exception {
    if (bytes[0] == 0) {
        int port = UIO.bytesInt(bytes, 1);
        String host = new String(bytes, 1 + 4, bytes.length - (1 + 4), StandardCharsets.UTF_8);
        return new RingHost("", "", host, port);
    } else if (bytes[0] == 1) {
        int i = 1;
        int port = UIO.bytesInt(bytes, i);
        i += 4;/*from   w  w  w.  ja v  a 2 s  .co m*/
        int hostLength = UIO.bytesInt(bytes, i);
        i += 4;
        String host = new String(bytes, i, hostLength, StandardCharsets.UTF_8);
        i += hostLength;
        int rackLength = UIO.bytesInt(bytes, i);
        i += 4;
        String rack = new String(bytes, i, rackLength, StandardCharsets.UTF_8);
        i += rackLength;
        int datacenterLength = UIO.bytesInt(bytes, i);
        i += 4;
        String datacenter = new String(bytes, i, datacenterLength, StandardCharsets.UTF_8);
        return new RingHost(datacenter, rack, host, port);
    }
    LOG.error("Bad RingHost bytes, bytes={}", new Object[] { Arrays.toString(bytes) }, new Throwable());
    return null; // Sorry caller
}

From source file:com.quantiply.avro.AvroToJsonTest.java

@Test
public void testObjectToJson() throws Exception {
    AvroToJson avroToJson = new AvroToJson();
    Thing thing = new Thing();
    ObjectMapper objectMapper = new ObjectMapper();
    byte[] jsonBytes = avroToJson.objectToJson(thing);
    Map<String, String> obj = objectMapper.readValue(jsonBytes, Map.class);
    assertEquals("hi", obj.get("foo"));
    assertEquals("hello", obj.get("bar"));
    String jsonStr = new String(jsonBytes, StandardCharsets.UTF_8);
    assertTrue(jsonStr.contains("\"bar\":\"hello\""));
}