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(); 
    } 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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; 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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];
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:name
            OutputStream entityStream) throws IOException {
        try { 
            final Marshaller m = getMarshaller(type, 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);
        } 
    } 
 
    /** 
     * Marshal an instance of a JAXB type. 
     * <p> 
     * Implementing classes may override this method. 
     * 
     * @param t            the instance of the JAXB type. 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:name
  public void setContent(String message) {
    setContent(message.getBytes());
  } 
 
  public void setEncoding(Charset charset) {
    response.setCharacterEncoding(charset.name());
  } 
 
  public void sendRedirect(String to) {
    response.setContentLength(0);
    try { 
      response.sendRedirect(to);
    } catch (IOException e) {
      throw new WebDriverException(e);
    } 
  } 
 
  public void end() { 
    try { 
      response.flushBuffer();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:newDecoder
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:name
	} 
 
	@Override 
	public String getAsText() {
		Charset value = (Charset) getValue();
		return (value != null ? value.name() : "");
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:name
    ple.init(baos);
  } 
 
  @Test
  public void charset() throws IOException {
    ple.setCharset(utf8Charset);
    init(baos);
    String msg = "\u03b1";
    ILoggingEvent event = makeLoggingEvent(msg);
    ple.doEncode(event);
    ple.close();
    assertEquals(msg, new String(baos.toByteArray(), utf8Charset.name()));
  } 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Charset Questions & Answers:

See Code Examples for Java 8 Charset Methods: