Example usage for java.nio ByteBuffer get

List of usage examples for java.nio ByteBuffer get

Introduction

In this page you can find the example usage for java.nio ByteBuffer get.

Prototype

public abstract byte get();

Source Link

Document

Returns the byte at the current position and increases the position by 1.

Usage

From source file:Main.java

public static void print(ByteBuffer bb) {
    while (bb.hasRemaining())
        System.out.print(bb.get() + " ");
    System.out.println();/*from w  w w. j ava2 s  .c om*/
    bb.rewind();
}

From source file:Main.java

public static short getUnsignedByte(final ByteBuffer pByteBuffer) {
    return (short) (pByteBuffer.get() & 0xFF);
}

From source file:Main.java

public static int readInt(ByteBuffer buffer) {
    int id = (buffer.get() & 0xFF) << 24;
    id += (buffer.get() & 0xFF) << 16;
    id += (buffer.get() & 0xFF) << 8;
    id += (buffer.get() & 0xFF);// w  ww.j a v  a 2  s .co m
    return id;
}

From source file:Main.java

static public String getString(ByteBuffer data) {
    int size = data.get();
    if (size == 0) {
        return "";
    } else {//w  w w  .  j a  v a2s. c  o  m
        byte[] bb = new byte[size * 2 - 2];
        data.get(bb);
        data.getShort();
        try {
            return new String(bb, "UTF-16LE");
        } catch (UnsupportedEncodingException e) {
            return "";
        }
    }
}

From source file:Main.java

public static long readVLong(ByteBuffer bb) {
    byte firstByte = bb.get();
    int len = decodeVNumSize(firstByte);
    return readVLong(bb, len, firstByte);
}

From source file:Main.java

public static void showByteOrder(ByteBuffer bb) {
    System.out.println("Byte  Order: " + bb.order());
    while (bb.hasRemaining()) {
        System.out.print(bb.get() + "    ");
    }/*from  w w  w  .j  a v  a  2s .c  o m*/
    System.out.println();
}

From source file:Main.java

public static int readBER32(ByteBuffer input) {
    int size = 0;
    for (int i = 0; i < 4; i++) {
        byte b = input.get();
        size = (size << 7) | (b & 0x7f);
        if (((b & 0xff) >> 7) == 0)
            break;
    }//from  w w w .  ja  v  a 2 s . co m
    return size;
}

From source file:Main.java

/**
 * Merge short value from two byte buffer. First byte of short will be extracted from first byte buffer and second from second
 * one.//from w w w  .  ja  va2  s  .c  o m
 * 
 * @param buffer
 *          to read first part of value
 * @param buffer1
 *          to read second part of value
 * @return merged value
 */
public static short mergeShortFromBuffers(ByteBuffer buffer, ByteBuffer buffer1) {
    short result = 0;
    result = (short) (result | (buffer.get() & MASK));
    result = (short) (result << SIZE_OF_BYTE_IN_BITS);
    result = (short) (result | (buffer1.get() & MASK));
    return result;
}

From source file:Main.java

private static int getUleb128(ByteBuffer buffer) {
    int ret = 0;//from   w ww . ja  v  a 2 s.  com
    int c;
    do {
        ret <<= 7;
        c = buffer.get();
        ret |= c & 0x7f;
    } while ((c & 0x80) > 0);

    return ret;
}

From source file:com.aerohive.nms.engine.admin.task.licensemgr.license.processor2.PacketUtil.java

public static byte[] split(ByteBuffer buf, Header header) {
    header.setPacketType(buf.get());
    header.setLength(buf.getInt());// w w  w .  ja v a2  s  .  c  om
    header.setProtocolVersion(buf.get());
    header.setSecretFlag(buf.get() == CommConst.Secret_Flag_Yes ? true : false);

    byte[] content = new byte[buf.remaining()];
    buf.get(content);

    if (header.isSecretFlag()) {
        byte[] outb = decryptData(content);
        return outb;
    } else {
        return content;
    }
}