Java ByteBuffer Write writeCDouble(ByteBuffer buffer, double value)

Here you can find the source of writeCDouble(ByteBuffer buffer, double value)

Description

write C Double

License

Apache License

Declaration

public static void writeCDouble(ByteBuffer buffer, double value) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static void writeCDouble(ByteBuffer buffer, double value) {
        writeCLong(buffer, Double.doubleToLongBits(value));
    }/*from   w w w.j a v a  2  s  . co m*/

    public static void writeCLong(ByteBuffer buffer, long anInt) {
        // -128 = short byte, -127 == 4 byte
        if (anInt > -126 && 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 if (anInt >= Integer.MIN_VALUE && anInt <= Integer.MAX_VALUE) {
            buffer.put((byte) -127);
            buffer.putInt((int) anInt);
        } else {
            buffer.put((byte) -126);
            buffer.putLong(anInt);
        }
    }
}

Related

  1. writeByteBuffer(ByteBuffer bbuf, String filename)
  2. writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)
  3. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  4. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  5. writeByteString(ByteBuffer byteBuffer, String value)
  6. writeCharacterString(ByteBuffer buf, byte[] bytes)
  7. writeCInt(ByteBuffer buffer, int anInt)
  8. writeColorTable(ByteBuffer out, int numColors)
  9. writeDouble(ByteBuffer buffer, double d)