Java ByteBuffer Write writeCInt(ByteBuffer buffer, int anInt)

Here you can find the source of writeCInt(ByteBuffer buffer, int anInt)

Description

write C Int

License

Apache License

Declaration

public static void writeCInt(ByteBuffer buffer, int anInt) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static void writeCInt(ByteBuffer buffer, int anInt) {
        // -128 = short byte, -127 == 4 byte
        if (anInt > -127 && anInt <= 127) {
            buffer.put((byte) anInt);
        } else if (anInt >= Short.MIN_VALUE && anInt <= Short.MAX_VALUE) {
            buffer.put((byte) -128);
            buffer.putShort((short) anInt);
        } else {// w w w  . j a  va 2s. co  m
            buffer.put((byte) -127);
            buffer.putInt(anInt);
        }
    }
}

Related

  1. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  2. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  3. writeByteString(ByteBuffer byteBuffer, String value)
  4. writeCDouble(ByteBuffer buffer, double value)
  5. writeCharacterString(ByteBuffer buf, byte[] bytes)
  6. writeColorTable(ByteBuffer out, int numColors)
  7. writeDouble(ByteBuffer buffer, double d)
  8. writeDouble(double v, ByteBuffer buffer)
  9. writeEmpty(final ByteBuffer buffer, final int type)