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

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

Introduction

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

Prototype

int BYTES

To view the source code for com.google.common.primitives Longs BYTES.

Click Source Link

Document

The number of bytes required to represent a primitive long value.

Usage

From source file:org.apache.kudu.Type.java

/**
 * Gives the size in bytes for a given DataType, as per the pb specification
 * @param type pb type/*from   w w  w . j  av  a2  s. c om*/
 * @return size in bytes
 */
static int getTypeSize(DataType type) {
    switch (type) {
    case STRING:
    case BINARY:
        return 8 + 8; // offset then string length
    case BOOL:
    case INT8:
        return 1;
    case INT16:
        return Shorts.BYTES;
    case INT32:
    case FLOAT:
        return Ints.BYTES;
    case INT64:
    case DOUBLE:
    case UNIXTIME_MICROS:
        return Longs.BYTES;
    default:
        throw new IllegalArgumentException("The provided data type doesn't map" + " to know any known one.");
    }
}

From source file:io.druid.query.aggregation.last.DoubleLastBufferAggregator.java

@Override
public long getLong(ByteBuffer buf, int position) {
    return (long) buf.getDouble(position + Longs.BYTES);
}

From source file:alluxio.network.protocol.RPCBlockReadRequest.java

@Override
public int getEncodedLength() {
    // 5 longs (mBLockId, mOffset, mLength, mLockId, mSessionId)
    return Longs.BYTES * 5;
}

From source file:io.druid.segment.data.LongsLongEncodingWriter.java

@Override
public int getBlockSize(int bytesPerBlock) {
    return bytesPerBlock / Longs.BYTES;
}

From source file:alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest.java

@Override
public int getEncodedLength() {
    // 4 longs (mBLockId, mOffset, mLength, mSessionId) and 1 boolean (boolean takes 1 byte in
    // netty)./*from w w  w .  j  av a  2 s.  c  om*/
    return Longs.BYTES * 4 + 1;
}

From source file:co.cask.cdap.data2.transaction.queue.coprocessor.hbase94.DequeueFilter.java

@Override
public boolean filterRowKey(byte[] buffer, int offset, int length) {
    // last 4 bytes in a row key
    counter = Bytes.toInt(buffer, offset + length - 4, Ints.BYTES);
    // row key is queue_name + writePointer + counter
    writePointer = Bytes.toLong(buffer, offset + queueNamePrefixLength, Longs.BYTES);

    // If writes later than the reader pointer, abort the loop, as entries that comes later are all uncommitted.
    // this is probably not needed due to the limit of the scan to the stop row, but to be safe...
    if (writePointer > transaction.getReadPointer()) {
        stopScan = true;/*from   ww  w .ja  v  a  2 s  .com*/
        return true;
    }

    // If the write is in the excluded list, ignore it.
    if (transaction.isExcluded(writePointer)) {
        return true;
    }

    return false;
}

From source file:co.cask.cdap.data2.transaction.queue.QueueEntryRow.java

/**
 * @param stateValue value of the state column
 * @return write pointer of the latest change of the state value
 *///from  w  w w  .  java 2  s  .c  o m
public static long getStateWritePointer(byte[] stateValue) {
    return Bytes.toLong(stateValue, 0, Longs.BYTES);
}

From source file:co.cask.cdap.data2.transaction.queue.coprocessor.hbase10cdh.DequeueFilter.java

@Override
public boolean filterRowKey(byte[] buffer, int offset, int length) {
    // last 4 bytes in a row key
    counter = Bytes.toInt(buffer, offset + length - Ints.BYTES, Ints.BYTES);
    // row key is queue_name + writePointer + counter
    writePointer = Bytes.toLong(buffer, offset + length - Longs.BYTES - Ints.BYTES, Longs.BYTES);

    // If writes later than the reader pointer, abort the loop, as entries that comes later are all uncommitted.
    // this is probably not needed due to the limit of the scan to the stop row, but to be safe...
    if (writePointer > transaction.getReadPointer()) {
        stopScan = true;//  w  w w  .j  av a2  s. c om
        return true;
    }

    // If the write is in the excluded list, ignore it.
    if (transaction.isExcluded(writePointer)) {
        return true;
    }

    return false;
}

From source file:io.druid.query.aggregation.CountAggregatorFactory.java

@Override
public int getMaxIntermediateSize() {
    return Longs.BYTES;
}

From source file:org.apache.hadoop.hdfs.util.BestEffortLongFile.java

private void lazyOpen() throws IOException {
    if (ch != null) {
        return;// w ww  .ja va  2 s .  c  o m
    }

    // Load current value.
    byte[] data = null;
    try {
        data = Files.toByteArray(file);
    } catch (FileNotFoundException fnfe) {
        // Expected - this will use default value.
    }

    if (data != null && data.length != 0) {
        if (data.length != Longs.BYTES) {
            throw new IOException("File " + file + " had invalid length: " + data.length);
        }
        value = Longs.fromByteArray(data);
    } else {
        value = defaultVal;
    }

    // Now open file for future writes.
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    try {
        ch = raf.getChannel();
    } finally {
        if (ch == null) {
            IOUtils.closeStream(raf);
        }
    }
}