Java ByteBuffer to Int readUnsignedMedium(ByteBuffer buf)

Here you can find the source of readUnsignedMedium(ByteBuffer buf)

Description

Gets a smart.

License

Apache License

Parameter

Parameter Description
buf The buffer.

Return

The smart.

Declaration

public static int readUnsignedMedium(ByteBuffer buf) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**//w  w  w .  j a  va  2 s  .  c o  m
     * Gets a smart.
     * @param buf The buffer.
     * @return The smart.
     */
    public static int readUnsignedMedium(ByteBuffer buf) {
        int peek = buf.get(buf.position()) & 0xFF;
        if (peek < 128) {
            return buf.get() & 0xFF;
        } else {
            return (buf.getShort() & 0xFFFF) - 32768;
        }
    }
}

Related

  1. readUnsignedByte(ByteBuffer buffer)
  2. readUnsignedInt(ByteBuffer buf)
  3. readUnsignedInt(ByteBuffer buffer)
  4. readUnsignedInt(ByteBuffer buffer, int index)
  5. readUnsignedInt(ByteBuffer byteBuf)
  6. readUnsignedShort(ByteBuffer bb)
  7. readUnsignedShort(ByteBuffer buffer)
  8. readUnsignedTriByte(ByteBuffer buffer)
  9. readUnsignedVarint(ByteBuffer buffer)