Java ByteBuffer to Double toDouble(ByteBuffer buffer)

Here you can find the source of toDouble(ByteBuffer buffer)

Description

to Double

License

Open Source License

Declaration

public static double toDouble(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static double toDouble(byte[] bytes) {
        return toDouble(ByteBuffer.wrap(bytes));
    }//from   ww w  .j a va 2  s. c  o  m

    public static double toDouble(ByteBuffer buffer) {
        return toByteBuffer(buffer, Double.BYTES).getDouble();
    }

    protected static ByteBuffer toByteBuffer(ByteBuffer buffer, int length) {
        if (length > buffer.remaining()) {
            return (ByteBuffer) ((ByteBuffer) ByteBuffer.allocate(length).position(length - buffer.remaining()))
                    .put(buffer.array()).rewind();
        } else {
            return buffer;
        }
    }
}

Related

  1. readDouble(ByteBuffer buffer)
  2. readDouble(ByteBuffer buffer)
  3. toDouble(ByteBuffer bytes)
  4. toDouble(ByteBuffer value)