Java 8 CharsetDecoder - 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 CharsetDecoder class.

This code example shows how to use the following methods: onMalformedInput, onUnmappableCharacter, reset
        } 
 
        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;
    } 
 
    private CharsetUtil() { } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: decode, flush, maxCharsPerByte, onMalformedInput, onUnmappableCharacter
 
    @SuppressWarnings("ObjectToString") 
    public static String decodeString(ByteBuffer src, Charset charset)
    { 
        CharsetDecoder decoder = getDecoder(charset);
        CharBuffer dst = CharBuffer.allocate((int) ((double) src.remaining() * decoder.maxCharsPerByte()));
        try { 
            CoderResult cr = decoder.decode(src, dst, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            } 
            cr = decoder.flush(dst);
            if (!cr.isUnderflow()) {
                cr.throwException();
            } 
        } 
        catch (CharacterCodingException x) {
            throw new IllegalStateException(x);
        } 
        return dst.flip().toString();

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: onMalformedInput, onUnmappableCharacter
            encoding = Charset.defaultCharset().name();
        } else if (!Charset.isSupported(encoding)) {
            throw new IllegalArgumentException(encoding + " is not supported");
        } 
        decoder = Charset.forName(encoding).newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPLACE);
        decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    } 
 
    /** 
     * Closes this output stream and releases any system resources 
     * associated with this stream. The general contract of <code>close</code> 
     * is that it closes the output stream. A closed stream cannot perform 
     * output operations and cannot be reopened. 
     * <p> 
     * 
     * @exception  IOException  if an I/O error occurs. 
     */ 
    @Override 
    public void close() throws IOException { 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: decode, onMalformedInput, onUnmappableCharacter
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: malformedInputAction, replacement, unmappableCharacterAction
        } 
    } 
 
    public static int setCallbackDecode(long converterHandle, CharsetDecoder decoder) {
        return setCallbackDecode(converterHandle,
                translateCodingErrorAction(decoder.malformedInputAction()),
                translateCodingErrorAction(decoder.unmappableCharacterAction()),
                decoder.replacement().toCharArray());
    } 
    private static native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars);
 
    public static int setCallbackEncode(long converterHandle, CharsetEncoder encoder) {
        return setCallbackEncode(converterHandle,
                translateCodingErrorAction(encoder.malformedInputAction()),
                translateCodingErrorAction(encoder.unmappableCharacterAction()),
                encoder.replacement());
    } 
    private static native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes);
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: decode, onMalformedInput, onUnmappableCharacter
 
	public static CharBuffer decode(String charsetName, ByteBuffer byteBuffer) {
		try { 
			CharsetDecoder charsetDecoder = getCharsetDecoder(charsetName);
 
			return charsetDecoder.decode(byteBuffer);
		} 
		catch (CharacterCodingException cce) {
			throw new Error(cce);
		} 
	} 
 
	public static CharsetDecoder getCharsetDecoder(String charsetName) {
		Charset charset = Charset.forName(charsetName);
 
		CharsetDecoder charsetDecoder = charset.newDecoder();
 
		charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE);
		charsetDecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: decode
Charset charset = Charset.forName(encoding);
    CharsetDecoder decoder = charset.newDecoder();
    CharBuffer cbuf = null;
    try { 
      cbuf = decoder.decode(ByteBuffer.wrap(forwardedContent));
    } catch (CharacterCodingException e) {
      // ignore 
    } 
    return cbuf.toString();
  } 
 
  public void setForwardedContent(byte[] forwardedContent) {
    this.forwardedContent = forwardedContent;
  } 
 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: averageCharsPerByte, onMalformedInput, onUnmappableCharacter, reset
this.channel = channel;
    this.decoder = decoder;
 
    // JDK reports errors, so we do the same. 
    decoder.onMalformedInput(CodingErrorAction.REPORT);
    decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    decoder.reset();
 
    int size = (minBufferCap == -1) ? DEFAULT_BUFFER_CAP : minBufferCap;
 
    // Allocates the buffers and prepares them for reading, because that is the 
    // first operation being done on them. 
    byteBuffer = ByteBuffer.allocate(size);
    byteBuffer.flip();
    charBuffer = CharBuffer.allocate((int) (size * decoder.averageCharsPerByte()));
  } 
 
  public int read(char[] buf, int offset, int count) throws IOException
  { 
    synchronized (lock)
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: onMalformedInput, onUnmappableCharacter
    private CharBuffer out = CharBuffer.allocate(1024);
 
    public WriterOutputStream(Writer out, Charset charset) {
        this.writer = out;
        decoder = charset.newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPLACE);
        decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    } 
 
    public WriterOutputStream(Writer out) {
        this(out,DEFAULT_CHARSET);
    } 
 
    public void write(int b) throws IOException {
        if(buf.remaining()==0)
            decode(false); 
        buf.put((byte)b);
    } 
 
    public void write(byte b[], int off, int len) throws IOException {
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: maxCharsPerByte, onMalformedInput, onUnmappableCharacter, replaceWith
            throw msg.parameterOutOfRange("bufferSize"); 
        } 
        this.writer = writer;
        this.decoder = decoder;
        byteBuffer = ByteBuffer.allocate(bufferSize);
        chars = new char[(int) ((float)bufferSize * decoder.maxCharsPerByte() + 0.5f)];
    } 
 
    /** 
     * Construct a new instance. 
     * 
     * @param writer the writer to decode into 
     * @param charset the character set to use 
     */ 
    public WriterOutputStream(final Writer writer, final Charset charset) {
        this(writer, getDecoder(charset));
    } 
 
    /** 
     * Construct a new instance. 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 CharsetDecoder Questions & Answers:

See Code Examples for Java 8 CharsetDecoder Methods: