Java 8 Charset - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Charset class.

This code example shows how to use the following methods: name
        this.body = body;
    } 
 
    @Override 
    public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) {
        response.charset(charset)
                .header("Content-Type", contentType + "; charset=" + charset.name())
                .header("Content-Length", body.length())
                .content(body)
                .end(); 
    } 
 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: newEncoder
        final Charset[] charsets = CharsetUtil.values();
        for (int i = 0; i < charsets.length; ++i) {
            final Charset charset = charsets[i];
            byte[] actual = AsciiString.getBytes(new AsciiString(bString), charset);
            assertArrayEquals("failure for " + charset, expected, actual);
        } 
    } 
 
    private static byte[] getBytesWithEncoder(CharSequence value, Charset charset) {
        final CharsetEncoder encoder = CharsetUtil.getEncoder(charset);
        final ByteBuffer nativeBuffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * value.length()));
        encoder.encode(CharBuffer.wrap(value), nativeBuffer, true);
        return nativeBuffer.array();
    } 
} 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: newDecoder
        if (charset == null) {
            throw new NullPointerException("charset");
        } 
 
        Map<Charset, CharsetDecoder> map = InternalThreadLocalMap.get().charsetDecoderCache();
        CharsetDecoder d = map.get(charset);
        if (d != null) {
            d.reset();
            d.onMalformedInput(CodingErrorAction.REPLACE);
            d.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return d;
        } 
 
        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
        d.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, d);
        return d;
    } 
 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: name
            OutputStream entityStream) throws IOException {
        try { 
            final Marshaller m = getMarshaller(t.getDeclaredType(), mediaType);
            final Charset c = getCharset(mediaType);
            if (c != UTF8) {
                m.setProperty(Marshaller.JAXB_ENCODING, c.name());
            } 
            setHeader(m, annotations);
            writeTo(t, mediaType, c, m, entityStream);
        } catch (JAXBException ex) {
            throw new InternalServerErrorException(ex);
        } 
    } 
 
    protected abstract void writeTo(JAXBElement<?> t, MediaType mediaType, Charset c,
                                    Marshaller m, OutputStream entityStream)
            throws JAXBException; 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: name
            "<body>Page number <span id=\"pageNumber\">%s</span>" + 
            "<p><a href=\"../xhtmlTest.html\" target=\"_top\">top</a>" + 
            "</body></html>", segment, segment);
 
        response
            .charset(CHARSET)
            .header("Content-Type", "text/html; charset=" + CHARSET.name())
            .header("Content-Length", body.length())
            .content(body)
            .end(); 
    } 
 
    private String getLastPathPart(String uri) {
      String[] parts;
      try { 
        parts = new URI(uri).getPath().split("/");
      } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
      } 
      return parts[parts.length - 1];
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Charset Questions & Answers:

See Code Examples for Java 8 Charset Methods: