Example usage for com.google.common.primitives Longs fromBytes

List of usage examples for com.google.common.primitives Longs fromBytes

Introduction

In this page you can find the example usage for com.google.common.primitives Longs fromBytes.

Prototype

public static long fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) 

Source Link

Document

Returns the long value whose byte representation is the given 8 bytes, in big-endian order; equivalent to Longs.fromByteArray(new byte[] {b1, b2, b3, b4, b5, b6, b7, b8})}.

Usage

From source file:org.bimserver.client.CountingLittleEndianDataInputStream.java

/**
 * Reads a {@code long} as specified by {@link DataInputStream#readLong()},
 * except using little-endian byte order.
 *
 * @return the next eight bytes of the input stream, interpreted as a
 *         {@code long} in little-endian byte order
 * @throws IOException//from   w  w w.jav a  2  s  .  com
 *             if an I/O error occurs
 */
@Override
public long readLong() throws IOException {
    byte b1 = readAndCheckByte();
    byte b2 = readAndCheckByte();
    byte b3 = readAndCheckByte();
    byte b4 = readAndCheckByte();
    byte b5 = readAndCheckByte();
    byte b6 = readAndCheckByte();
    byte b7 = readAndCheckByte();
    byte b8 = readAndCheckByte();

    return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
}

From source file:org.apache.hadoop.hive.ql.io.slice.Slice.java

/**
 * Fill the slice with the specified value;
 *///w w  w.  j  a  v  a 2 s.  co m
public void fill(byte value) {
    int offset = 0;
    int length = size;
    long longValue = Longs.fromBytes(value, value, value, value, value, value, value, value);
    while (length >= SizeOf.SIZE_OF_LONG) {
        unsafe.putLong(base, address + offset, longValue);
        offset += SizeOf.SIZE_OF_LONG;
        length -= SizeOf.SIZE_OF_LONG;
    }

    while (length > 0) {
        unsafe.putByte(base, address + offset, value);
        offset++;
        length--;
    }
}

From source file:com.facebook.buck.cxx.platform.ObjectFileScrubbers.java

public static long getLittleEndianLong(ByteBuffer buffer) {
    byte b1 = buffer.get();
    byte b2 = buffer.get();
    byte b3 = buffer.get();
    byte b4 = buffer.get();
    byte b5 = buffer.get();
    byte b6 = buffer.get();
    byte b7 = buffer.get();
    byte b8 = buffer.get();
    return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
}

From source file:com.liaison.javabasics.serialization.BytesUtil.java

/**
 * TODO/*from  w w  w  .  j a va 2  s  .c  o m*/
 * @param bytes TODO
 * @param offset TODO
 * @return TODO
 */
public static Long toLong(final byte[] bytes, final int offset) {
    // TODO: determine constant values programmatically, or make them constant
    if (bytes != null && offset >= 0 && bytes.length >= offset + 8) {
        return Long.valueOf(Longs.fromBytes(bytes[offset + 0], bytes[offset + 1], bytes[offset + 2],
                bytes[offset + 3], bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7]));
    }
    return null;
}

From source file:io.airlift.slice.Slice.java

/**
 * Fill the slice with the specified value;
 *///  www. j a  v a 2s.co  m
public void fill(byte value) {
    int offset = 0;
    int length = size;
    long longValue = Longs.fromBytes(value, value, value, value, value, value, value, value);
    while (length >= SIZE_OF_LONG) {
        unsafe.putLong(base, address + offset, longValue);
        offset += SIZE_OF_LONG;
        length -= SIZE_OF_LONG;
    }

    while (length > 0) {
        unsafe.putByte(base, address + offset, value);
        offset++;
        length--;
    }
}

From source file:io.divolte.server.ShortTermDuplicateMemory.java

private boolean isProbablyDuplicate(final HashCode eventDigest) {
    // Our hashing algorithm produces 8 bytes:
    //  0: slot[0]
    //  1: slot[1]
    //  2: slot[2]
    //  3: slot[3]
    //  4://from   ww  w .j a v  a 2 s  .c o  m
    //  5:
    //  6:
    //  7:
    //  8: signature[0]
    //  9:  ..
    // 10:  ..
    // 11:  ..
    // 12:  ..
    // 13:  ..
    // 14:  ..
    // 15: signature[7]
    final byte[] hashBytes = eventDigest.asBytes();

    // We use the low int for the slot.
    final int slotSelector = Ints.fromBytes(hashBytes[0], hashBytes[1], hashBytes[2], hashBytes[3]);
    // We use the high long for the signature.
    final long signature = Longs.fromBytes(hashBytes[8], hashBytes[9], hashBytes[10], hashBytes[11],
            hashBytes[12], hashBytes[13], hashBytes[14], hashBytes[15]);

    final int slot = (slotSelector & Integer.MAX_VALUE) % memory.length;
    final boolean result = memory[slot] == signature;
    memory[slot] = signature;
    return result;
}

From source file:com.liaison.javabasics.serialization.BytesUtil.java

/**
 * TODO/* w w  w. j a  va2 s .  c  o  m*/
 * @param b1 TODO
 * @param b2 TODO
 * @param b3 TODO
 * @param b4 TODO
 * @param b5 TODO
 * @param b6 TODO
 * @param b7 TODO
 * @param b8 TODO
 * @return TODO
 */
public static long toLong(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) {
    return Longs.fromBytes(b1, b2, b3, b4, b5, b6, b7, b8);
}

From source file:numpy.core.NDArrayUtil.java

static private long readLong(InputStream is, ByteOrder byteOrder) throws IOException {
    byte b1 = readByte(is);
    byte b2 = readByte(is);
    byte b3 = readByte(is);
    byte b4 = readByte(is);
    byte b5 = readByte(is);
    byte b6 = readByte(is);
    byte b7 = readByte(is);
    byte b8 = readByte(is);

    if ((ByteOrder.BIG_ENDIAN).equals(byteOrder)) {
        return Longs.fromBytes(b1, b2, b3, b4, b5, b6, b7, b8);
    } else//w ww . j av  a  2s. c  o m

    if ((ByteOrder.LITTLE_ENDIAN).equals(byteOrder)) {
        return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
    }

    throw new IOException();
}

From source file:com.github.mgunlogson.cuckoofilter4j.BucketAndTag.java

private long longFromHighBytes(byte[] bytes) {
    return Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]);
}

From source file:com.github.mgunlogson.cuckoofilter4j.BucketAndTag.java

private long longFromLowBytes(byte[] bytes) {
    return Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
            bytes[15]);//from  w w  w . j a v a 2  s.c  o  m
}