Java ByteBuffer Decode decodeNIO(String encoding, ByteBuffer bbuf)

Here you can find the source of decodeNIO(String encoding, ByteBuffer bbuf)

Description

decode NIO

License

Apache License

Declaration

private static String decodeNIO(String encoding, ByteBuffer bbuf) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;
import java.nio.CharBuffer;

import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;

public class Main {
    private static String decodeNIO(String encoding, ByteBuffer bbuf) {
        Charset cset = Charset.forName(encoding);
        CharsetDecoder csetdecoder = cset.newDecoder();

        csetdecoder.onMalformedInput(CodingErrorAction.REPLACE);
        csetdecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);

        try {/*from   w w  w  .  j ava2s.c o  m*/
            CharBuffer cbuf = csetdecoder.decode(bbuf);

            return cbuf.toString();
        } catch (CharacterCodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. decodeDouble(ByteBuffer bb)
  2. decodeInt(ByteBuffer buffer, int start)
  3. decodeIO(String encoding, ByteBuffer bbuf)
  4. decodeLength(ByteBuffer buf)
  5. decodeLong(ByteBuffer buffer, int start)
  6. decodeNumber(byte firstByte, ByteBuffer buffer)
  7. decodeStoredBits(ByteBuffer bb)
  8. decodeStringSequence(ByteBuffer bb)
  9. decodeThrowing(Charset charset, ByteBuffer in)