Converts a long into a byte array.

@param l
a long
@param bo
a ByteOrder
@return byte array
328952
public static byte[] toByteArray(long l, ByteOrder bo) {
    return ByteBuffer.allocate(8).order(bo).putLong(l).array();
  }
19538
public static long bytesToLong(byte[] bytes, int offset) {
        long result = 0x0;
        for (int i = offset; i < offset + 8; ++i) {
            result = result << 8;
            result |= (bytes[i] & 0x00000000000000FFl);
        }
        return result;
    }
1193535
public static final long getLong(InputStream is) throws IOException
   {
      byte[] data = new byte[8];
      is.read(data);
      return getLong(data, 0);
   }
529986
public synchronized PacketBuilder withLong(final long l)
    {
        checkBuilt();
        try
        {
            dataOutputStream.writeLong(l);
        }
        catch (final IOException e)
        {
            logger.error("Unable to add long: {} : {}", e.getClass(), e.getMessage());
        }
        return this;
    }
194843
public static byte[] toBytes(long value) {
        byte[] bytes = new byte[8];
        ByteBuffer buffer = ByteBuffer.wrap(bytes);
        buffer.putLong(value);
        return bytes;
    }
1046996
private long convertToLong(byte[] bin){
        ByteBuffer bb = ByteBuffer.wrap(bin);
        bb.order(ByteOrder.BIG_ENDIAN);
        return bb.getInt();
    }
749980
private static long byteArrayToLong(byte[] ba, int offset) {
		long l = 0;

		for (int i = 0; i < SIZE_OF_LONG; ++i) {
			l |= (ba[offset + SIZE_OF_LONG - 1 - i] & 0xffL) << (i << 3);
		}

		return l;
	}
52007
static long getLong(byte[] buffer, int offset) {
        return (buffer[offset] & 0xffL) << 56 | (buffer[offset + 1] & 0xffL) << 48 | (buffer[offset + 2] & 0xffL) << 40
                | (buffer[offset + 3] & 0xffL) << 32 | (buffer[offset + 4] & 0xffL) << 24
                | (buffer[offset + 5] & 0xffL) << 16 | (buffer[offset + 6] & 0xffL) << 8 | (buffer[offset + 7] & 0xffL);
    }
253717
private byte[] getMMapBytes(long offset)
      throws IOException {
    //Read the first 4 bytes to get the size of the data
    ByteBuffer buf = getDataBuffer(offset);
    int maxLen = (int) Math.min(5, dataSize - offset);

    int size;
    if (buf.remaining() >= maxLen) {
      //Continuous read
      int pos = buf.position();
      size = LongPacker.unpackInt(buf);

      // Used in case of data is spread over multiple buffers
      offset += buf.position() - pos;
    } else {
      //The size of the data is spread over multiple buffers
      int len = maxLen;
      int off = 0;
      sizeBuffer.reset();
      while (len > 0) {
        buf = getDataBuffer(offset + off);
        int count = Math.min(len, buf.remaining());
        buf.get(sizeBuffer.getBuf(), off, count);
        off += count;
        len -= count;
      }
      size = LongPacker.unpackInt(sizeBuffer);
      offset += sizeBuffer.getPos();
      buf = getDataBuffer(offset);
    }

    //Create output bytes
    byte[] res = new byte[size];

    //Check if the data is one buffer
    if (buf.remaining() >= size) {
      //Continuous read
      buf.get(res, 0, size);
    } else {
      int len = size;
      int off = 0;
      while (len > 0) {
        buf = getDataBuffer(offset);
        int count = Math.min(len, buf.remaining());
        buf.get(res, off, count);
        offset += count;
        off += count;
        len -= count;
      }
    }

    return res;
  }
1126481
public static byte[] long2buff(long n) {
        byte[] bs;

        bs = new byte[8];
        bs[0] = (byte) ((n >> 56) & 0xFF);
        bs[1] = (byte) ((n >> 48) & 0xFF);
        bs[2] = (byte) ((n >> 40) & 0xFF);
        bs[3] = (byte) ((n >> 32) & 0xFF);
        bs[4] = (byte) ((n >> 24) & 0xFF);
        bs[5] = (byte) ((n >> 16) & 0xFF);
        bs[6] = (byte) ((n >> 8) & 0xFF);
        bs[7] = (byte) (n & 0xFF);

        return bs;
    }
344966
public static ByteBuf copyLong(long value) {
        ByteBuf buf = buffer(8);
        buf.writeLong(value);
        return buf;
    }
356054
public static byte[] longToBytesNoLeadZeroes(long val) {

        // todo: improve performance by while strip numbers until (long >> 8 == 0)
        if (val == 0)
            return EMPTY_BYTE_ARRAY;

        byte[] data = ByteBuffer.allocate(8).putLong(val).array();

        return stripLeadingZeroes(data);
    }
26252
public static long toLong(byte[] b, int off, boolean littleEndian) {
		if (littleEndian) {
			return (toInt(b, off, LITTLE_ENDIAN) & 0xFFFFFFFFL) |
					((toInt(b, off + 4, LITTLE_ENDIAN) & 0xFFFFFFFFL) << 32);
		}
		return ((toInt(b, off, BIG_ENDIAN) & 0xFFFFFFFFL) << 32) |
				(toInt(b, off + 4, BIG_ENDIAN) & 0xFFFFFFFFL);
	}
575140
public static Optional<Long> readMaybeVLong(ByteBuf bf) {
      if (bf.readableBytes() >= 1) {
         byte b = bf.readByte();

         return read(bf, b, 7, (long) b & 0x7F, 1);
      } else {
         bf.resetReaderIndex();
         return Optional.empty();
      }
   }
1023177
public static byte[] toByteArray(final long l)
        {
        final byte[] bytes = new byte[8];
        bytes[0] = (byte) ((l >>> 56) & 0xff);
        bytes[1] = (byte) ((l >>> 48) & 0xff);
        bytes[2] = (byte) ((l >>> 40) & 0xff);
        bytes[3] = (byte) ((l >>> 32) & 0xff);
        bytes[4] = (byte) ((l >>> 24) & 0xff);
        bytes[5] = (byte) ((l >>> 16) & 0xff);
        bytes[6] = (byte) ((l >>> 8) & 0xff);
        bytes[7] = (byte) ((l >>> 0) & 0xff);
        return bytes;
        }
39532
public static long byteArrayToLongLE( byte[] data ) {
        if (data == null)
            return 0x0;
        long accum = 0;
        int shiftBy = 0;
        for( byte b : data ) {
            accum |= (long) (b & 0xff) << shiftBy;
            shiftBy += 8;
        }
        return accum;
    }
99136
public static long readUnsignedLong(ObjectInput in) throws IOException {
      byte b = in.readByte();
      long i = b & 0x7F;
      for (int shift = 7; (b & 0x80) != 0; shift += 7) {
         b = in.readByte();
         i |= (b & 0x7FL) << shift;
      }
      return i;
   }