Code example for CharsetEncoder

Methods: encode

0
     * @throws CharacterCodingException 
     *             an error encoding data 
     */ 
    private void fillBuffer() throws CharacterCodingException { 
        this.bbuf.compact();
        CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true);
        if (result.isError()) {
            result.throwException();
        } 
        this.bbuf.flip();
    } 
     
    @Override 
    public int read(byte[] b, int off, int len) throws IOException {
        if (b == null) {
            throw new NullPointerException("Byte array is null");
        } 
        if (len < 0 || (off + len) > b.length) {
            throw new IndexOutOfBoundsException("Array Size=" + b.length +
                    ", offset=" + off + ", length=" + len);
        }