Package java.nio.charset

Examples of java.nio.charset.CharsetDecoder.decode()


    public void testDecodeError() throws CharacterCodingException {
        CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
        ByteBuffer buffer = ByteBuffer.wrap(b);
       
        try {
            decoder.decode(buffer);
            fail("Must throw MalformedInputException");
        } catch (MalformedInputException e) {
            // OK
        }
    }
View Full Code Here


            {
                CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
                ByteBuffer encodedString = _data.slice();
                encodedString.limit(length);
                _data.position(_data.position()+length);
                CharBuffer string = decoder.decode(encodedString.buf());
               
                return string.toString();
            }

View Full Code Here

                    try {
                        byte[] data = new byte[buf.limit()];
                        buf.get(data);
                        CharsetDecoder decoder = ctx.getDecoder();

                        CharBuffer buffer = decoder.decode(ByteBuffer.wrap(data));
                        String str = buffer.toString();
                        writeText(session, str, out);
                    } finally {
                        buf.clear();
                    }
View Full Code Here

    CharsetEncoder encoder = charset.newEncoder();

    try {
        ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(textContent.getText()));

        CharBuffer cbuf = decoder.decode(bbuf);
        textContent.setText(cbuf.toString());
        lblEncode.setText("Change encode complete. Do not forget to save.");
    } catch (CharacterCodingException e) {
        lblEncode.setText(e.getMessage());
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
View Full Code Here

    public String getString(byte[] bytes)
    {
        CharsetDecoder utf8Decoder = UTF_8.newDecoder();
        try
        {
            return utf8Decoder.decode(ByteBuffer.wrap(bytes)).toString();
        }
        catch (CharacterCodingException e)
        {
            throw new MarshalException("invalid UTF8 bytes " + Arrays.toString(bytes));
        }
View Full Code Here

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

        try
        {
            CharBuffer cbuf = csetdecoder.decode( bbuf );

            return cbuf.toString();
        }
        catch( CharacterCodingException e )
        {
View Full Code Here

            try
            {
                bbuf = ByteBuffer.wrap( out.toByteArray() );

                CharBuffer cbuf = l1decoder.decode( bbuf );

                return cbuf.toString();
            }
            catch( CharacterCodingException ex )
            {
View Full Code Here

    if (replace) {
      decoder.onMalformedInput(
          java.nio.charset.CodingErrorAction.REPLACE);
      decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    }
    String str = decoder.decode(utf8).toString();
    // set decoder back to its default value: REPORT
    if (replace) {
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    }
View Full Code Here

    CharsetDecoder decoder2 = Charset.forName("UTF-16").newDecoder();
    decoder2.onMalformedInput(CodingErrorAction.REPORT);
    decoder2.onUnmappableCharacter(CodingErrorAction.REPORT);
    ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
    try {
      decoder2.decode(in);
      fail("Assert 3: MalformedInputException should have thrown");
    } catch (MalformedInputException e) {
      //expected
    }
  }
View Full Code Here

            if (barray.length == offset) {
                bbuff.position(0);
                bbuff.limit(barray.length);
                cbuff.position(0);
                cbuff.limit(carray.length);
                res = decoder.decode(bbuff, cbuff, false);
                if (res.isError()) {
                    throw new IOException("Decoding error: " + res.toString());
                }
                offset = bbuff.remaining();
                switch (offset) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.