Java ByteBuffer to Long toLong(ByteBuffer buffer)

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

Description

to Long

License

Open Source License

Declaration

public static long toLong(ByteBuffer buffer) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static long toLong(byte[] bytes) {
        return toLong(ByteBuffer.wrap(bytes));
    }/*from  ww  w  .j  av  a2s.  c o  m*/

    public static long toLong(ByteBuffer buffer) {
        return toByteBuffer(buffer, Long.BYTES).getLong();
    }

    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. readUInt64(ByteBuffer bb)
  2. readUInt64(ByteBuffer byteBuffer)
  3. readUInt8(ByteBuffer bb)
  4. readVarLong(ByteBuffer buff)
  5. readVarlong(ByteBuffer buffer)
  6. toLong(ByteBuffer buffer)
  7. toLong(ByteBuffer bytes)
  8. toLong(ByteBuffer value)