Code example for CharsetDecoder

Methods: decode

0
        //Read the string 
        stream.readFully(buf.array(), 0, len);
 
        //Decode it with correct encoding 
        try { 
            decoder.decode(buf, charBuffer, false);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            Log.e(TAG, "Failed to decode buffer: " + buf);
        } 
 
        //Set where the current string ends, it is the position we are at after decoding into the buffer 
        charBuffer.limit(charBuffer.position());
 
        //Reset buffer back to the mark(the start of the buffer) so we can convert to string 
        charBuffer.reset();
 
        return charBuffer.toString();
 
    }