Java Convert via ByteBuffer longToBytes(long x, byte[] dest, int offset)

Here you can find the source of longToBytes(long x, byte[] dest, int offset)

Description

long To Bytes

License

Open Source License

Declaration

public static void longToBytes(long x, byte[] dest, int offset) 

Method Source Code

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

import java.nio.ByteBuffer;

import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private static ByteBuffer longbuffer = ByteBuffer.allocate(Long.BYTES);
    private static ReentrantLock bufferLock = new ReentrantLock();

    public static void longToBytes(long x, byte[] dest, int offset) {
        bufferLock.lock();/*from   w w  w. j  a  va 2  s  .  co  m*/
        try {
            longbuffer.clear();
            longbuffer.putLong(0, x);
            System.arraycopy(longbuffer.array(), 0, dest, offset,
                    Long.BYTES);

        } finally {
            bufferLock.unlock();
        }
    }
}

Related

  1. longToBytes(final long value)
  2. longToBytes(long aLong)
  3. longToBytes(long l)
  4. longToBytes(long l, int size)
  5. longToBytes(long x)
  6. longToBytesNoLeadZeroes(long val)
  7. longToFourBytesFlip(long l)
  8. longToHeight(long x)
  9. longToIPv4(Long ip)