Java ByteBuffer Append appendSurrogate(ByteBuffer bb, char c)

Here you can find the source of appendSurrogate(ByteBuffer bb, char c)

Description

Append %Uxxxx to the given byte buffer.

License

Apache License

Parameter

Parameter Description
bb The byte buffer to write to.
c The character to write.

Declaration

static void appendSurrogate(ByteBuffer bb, char c) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**//from  w  w  w .  ja  v  a2 s .co m
     * The hexadecimal digits <code>0,...,9,A,...,F</code> encoded as
     * ASCII bytes.
     */
    private static final byte[] HEX_DIGITS = new byte[] { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
            0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 };

    /**
     * Append <code>%Uxxxx</code> to the given byte buffer.
     * The caller must assure, that <code>bb.remaining()&gt;=6</code>.
     *
     * @param bb The byte buffer to write to.
     * @param c  The character to write.
     */
    static void appendSurrogate(ByteBuffer bb, char c) {

        bb.put((byte) '%');
        bb.put((byte) 'U');

        bb.put(HEX_DIGITS[(c >> 12) & 0x0f]);
        bb.put(HEX_DIGITS[(c >> 8) & 0x0f]);
        bb.put(HEX_DIGITS[(c >> 4) & 0x0f]);
        bb.put(HEX_DIGITS[c & 0x0f]);
    }
}

Related

  1. append(ByteBuffer to, byte[] b, int off, int len)
  2. appendBuffers(ByteBuffer buffer, ByteBuffer buffer1, int incomingBufferSize, int BUFFER_STEP_SIZE)
  3. appendHex(StringBuilder sb, ByteBuffer bb)
  4. appendLong(long value, ByteBuffer buffer)
  5. appendOrRealloc(ByteBuffer dest, ByteBuffer toAppend)
  6. appendToByteBuffer(ByteBuffer bb, byte[] bytes, int len)
  7. appendToEnd(final File file, final ByteBuffer contents)