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:io.opencensus.exporter.trace.jaeger.JaegerExporterHandler.java

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

From source file:io.opencensus.exporter.trace.jaeger.JaegerExporterHandler.java

private long traceIdLow() {
    return Longs.fromBytes(traceIdBuffer[8], traceIdBuffer[9], traceIdBuffer[10], traceIdBuffer[11],
            traceIdBuffer[12], traceIdBuffer[13], traceIdBuffer[14], traceIdBuffer[15]);
}

From source file:com.datatorrent.flume.storage.HDFSStorage.java

/**
 * @param b//from   ww  w.j  a v a2 s.co m
 * @param startIndex
 * @return
 */
long byteArrayToLong(byte[] b, int startIndex) {
    final byte b1 = 0;
    return Longs.fromBytes(b1, b1, b1, b1, b[3 + startIndex], b[2 + startIndex], b[1 + startIndex],
            b[startIndex]);
}

From source file:io.warp10.continuum.geo.GeoIndex.java

/**
 * Load an LKP index previously dumped by dumpLKPIndex
 *//*from w w w  .j a va2s  . c  o m*/
public void loadLKPIndex(File path) throws IOException {

    if (0 != this.depth) {
        return;
    }

    InputStream in = new FileInputStream(path);

    byte[] buf = new byte[128];

    try {
        while (true) {
            // Read id len
            int idlen = in.read();

            if (-1 == idlen) {
                break;
            }

            // Read id
            int len = in.read(buf, 0, idlen);

            if (idlen != len) {
                break;
            }

            String key = new String(buf, 0, len, Charsets.UTF_8);

            // Read number of cells
            int ncells = in.read();

            if (-1 == ncells) {
                break;
            }

            len = in.read(buf, 0, ncells * 8);

            if (ncells * 8 != len) {
                break;
            }

            int offset = 0;

            long[] cells = new long[ncells];

            for (int i = 0; i < ncells; i++) {
                offset = i * 8;
                cells[i] = Longs.fromBytes(buf[offset], buf[offset + 1], buf[offset + 2], buf[offset + 3],
                        buf[offset + 4], buf[offset + 5], buf[offset + 6], buf[offset + 7]);
            }

            synchronized (this.lkpIndex) {
                this.lkpIndex.put(key, cells);
            }
        }
    } finally {
        in.close();
    }
}

From source file:org.apache.druid.data.input.parquet.simple.ParquetGroupConverter.java

/**
 * convert deprecated parquet int96 nanosecond timestamp to a long, based on
 * https://github.com/prestodb/presto/blob/master/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetTimestampUtils.java#L56
 *///from www.j  a v  a2s  .c om
private static long convertInt96BinaryToTimestamp(Binary value) {
    // based on prestodb parquet int96 timestamp conversion
    byte[] bytes = value.getBytes();

    // little endian encoding - need to invert byte order
    long timeOfDayNanos = Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1],
            bytes[0]);
    int julianDay = Ints.fromBytes(bytes[11], bytes[10], bytes[9], bytes[8]);

    long ts = ((julianDay - JULIAN_EPOCH_OFFSET_DAYS) * MILLIS_IN_DAY)
            + (timeOfDayNanos / NANOS_PER_MILLISECOND);
    return ts;
}