集册 Java实例教程 用于读取和写入的ByteBuffer实用程序

用于读取和写入的ByteBuffer实用程序

欢马劈雪     最近更新时间:2020-01-02 10:19:05

483
用于读取和写入的ByteBuffer实用程序

import java.nio.ByteBuffer;


class Unsigned {

  public static short getUnsignedByte(ByteBuffer bb) {
  /*
  时 代 J a v a 公 众 号 提 供
  */

    return ((short) (bb.get() & 0xff));

  }


  public static void putUnsignedByte(ByteBuffer bb, int value) {

    bb.put((byte) (value & 0xff));

  }


  public static short getUnsignedByte(ByteBuffer bb, int position) {

    return ((short) (bb.get(position) & (short) 0xff));

  }


  public static void putUnsignedByte(ByteBuffer bb, int position, int value) {// 来自 N o w  J a v a  . c o m

    bb.put(position, (byte) (value & 0xff));

  }


  public static int getUnsignedShort(ByteBuffer bb) {

    return (bb.getShort() & 0xffff);

  }


  public static void putUnsignedShort(ByteBuffer bb, int value) {

    bb.putShort((short) (value & 0xffff));

  }


  public static int getUnsignedShort(ByteBuffer bb, int position) {

    return (bb.getShort(position) & 0xffff);

  }


  public static void putUnsignedShort(ByteBuffer bb, int position, int value) {

    bb.putShort(position, (short) (value & 0xffff));

  }


  public static long getUnsignedInt(ByteBuffer bb) {

    return ((long) bb.getInt() & 0xffffffffL);

  }


  public static void putUnsignedInt(ByteBuffer bb, long value) {

    bb.putInt((int) (value & 0xffffffffL));

  }


  public static 
展开阅读全文