Android ByteBuffer Create 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;
/*/*from   w  w  w .  j av  a 2 s  .  c  o  m*/
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * 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. makeByteBuffer(byte[] i_arr)
  2. makeByteBuffer(int size)
  3. makeByteBuffer(int size)
  4. makeByteBuffer(int size)
  5. copyFromStreamToBuffer(ByteBuffer out, DataInputStream in, int length)