Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder.encode()


        }

        CharsetEncoder encoder = charSet.newEncoder();
        ByteBuffer byteBuffer = null;
        try {
            byteBuffer = encoder.encode(charBuffer);
        } catch(CharacterCodingException cce) {
            throw cce;
        } catch(Throwable t) {
            CharacterCodingException e = new CharacterCodingException();
            e.initCause(t);
View Full Code Here


                throw new IllegalArgumentException("MALFORMED");
            return Arrays.copyOf(ba, blen);
        }
        ByteBuffer bb = ByteBuffer.wrap(ba);
        CharBuffer cb = CharBuffer.wrap(ca);
        CoderResult cr = ce.encode(cb, bb, true);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
        cr = ce.flush(bb);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
View Full Code Here

    public void writeLengthPrefixedUTF(final String string) throws TypedBytesFormatException
    {
        try
        {
            CharsetEncoder encoder = UTF8.newEncoder();
            java.nio.ByteBuffer encodedString = encoder.encode(CharBuffer.wrap(string));

            writeShortImpl((short) encodedString.limit());
            while(encodedString.hasRemaining())
            {
                _data.writeByte(encodedString.get());
View Full Code Here

    {
        checkWritable();
        try
        {
            CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
            java.nio.ByteBuffer encodedString = encoder.encode(CharBuffer.wrap(string));
           
            _data.putShort((short)encodedString.limit());
            _data.put(encodedString);
            _changedData = true;
            //_data.putString(string, Charset.forName("UTF-8").newEncoder());
View Full Code Here

    Charset charset = Charset.forName(selectEncode.getSelectedItem().toString());
    CharsetDecoder decoder = charset.newDecoder();
    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) {
View Full Code Here

    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    }
    ByteBuffer bytes =
      encoder.encode(CharBuffer.wrap(string.toCharArray()));
    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPORT);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    }
    return bytes;
View Full Code Here

    public void writeLengthPrefixedUTF(final String string) throws JMSException
    {
        try
        {
            CharsetEncoder encoder = UTF8.newEncoder();
            java.nio.ByteBuffer encodedString = encoder.encode(CharBuffer.wrap(string));

            writeShortImpl((short) encodedString.limit());
            while(encodedString.hasRemaining())
            {
                _data.writeByte(encodedString.get());
View Full Code Here

    CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
    CharBuffer in1 = CharBuffer.wrap("\ud800");
    CharBuffer in2 = CharBuffer.wrap("\udc00");
    ByteBuffer out = ByteBuffer.allocate(4);
    encoder.reset();
    CoderResult result = encoder.encode(in1, out, false);
    assertEquals(4, out.remaining());
    assertTrue(result.isUnderflow());
    result = encoder.encode(in2, out, true);
    assertEquals(4, out.remaining());
    assertTrue(result.isMalformed());
View Full Code Here

    ByteBuffer out = ByteBuffer.allocate(4);
    encoder.reset();
    CoderResult result = encoder.encode(in1, out, false);
    assertEquals(4, out.remaining());
    assertTrue(result.isUnderflow());
    result = encoder.encode(in2, out, true);
    assertEquals(4, out.remaining());
    assertTrue(result.isMalformed());
  }
}
View Full Code Here

        us.limit(us.position());
        us.position(0);
        bs.limit(bs.position());
        bs.position(0);
       
        result = encoder.encode(us, bs, true);
        if (!result.isMalformed()) {
            errln("Malform error while encoding UTF32 charset (4) should have occurred.");
        }
       
        us.clear();
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.