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.drill.exec.store.parquet.decimal.Int64DecimalParquetValueWriter.java

@Override
public void writeValue(RecordConsumer consumer, DrillBuf buffer, int start, int end, int precision) {
    byte[] output;
    int startPos;
    int length = end - start;
    startPos = Longs.BYTES - length;
    output = new byte[Longs.BYTES];
    if (startPos > 0) {
        buffer.getBytes(start, output, startPos, length);
        if (output[startPos] < 0) {
            Arrays.fill(output, 0, output.length - length, (byte) -1);
        }// w w  w .j av  a 2s  .c o m
    } else {
        // in this case value from FIXED_LEN_BYTE_ARRAY or BINARY field was taken, ignore leading bytes
        buffer.getBytes(start - startPos, output, 0, length + startPos);
    }
    consumer.addLong(Longs.fromByteArray(output));
}

From source file:com.metamx.druid.aggregation.HistogramBufferAggregator.java

public HistogramBufferAggregator(FloatMetricSelector selector, float[] breaks) {
    this.selector = selector;
    this.breaks = breaks;
    this.minOffset = Longs.BYTES * (breaks.length + 1);
    this.maxOffset = this.minOffset + Floats.BYTES;
}

From source file:com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService.java

private static <T> long byteSize(Map<Cell, T> values) {
    long sizeInBytes = 0;
    for (Entry<Cell, T> valueEntry : values.entrySet()) {
        sizeInBytes += Cells.getApproxSizeOfCell(valueEntry.getKey());
        T value = valueEntry.getValue();
        if (value instanceof byte[]) {
            sizeInBytes += ((byte[]) value).length;
        } else if (value instanceof Long) {
            sizeInBytes += Longs.BYTES;
        }//from w  w w .j av  a 2  s  .c  o  m
    }
    return sizeInBytes;
}

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

@Override
public void init(ByteBuffer buf, int position) {
    buf.putLong(position, Long.MIN_VALUE);
    buf.putLong(position + Longs.BYTES, 0);
}

From source file:co.cask.cdap.api.dataset.lib.PartitionConsumerState.java

public static PartitionConsumerState fromBytes(byte[] bytes) {
    Preconditions.checkArgument((bytes.length - 1) % Longs.BYTES == 0,
            "bytes does not have length divisible by Longs.BYTES");
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    byte serializationFormatVersion = bb.get();
    Preconditions.checkArgument(serializationFormatVersion == 0, "Unsupported serialization format: {}",
            serializationFormatVersion);
    long startVersion = bb.getLong();
    List<Long> versionsToCheck = Lists.newArrayList();
    while (bb.hasRemaining()) {
        versionsToCheck.add(bb.getLong());
    }/*from   www  .ja  v  a 2  s  .com*/
    return new PartitionConsumerState(startVersion, versionsToCheck);
}

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

@Override
public int getNumBytes(int values) {
    return values * Longs.BYTES;
}

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

@Override
public void init(ByteBuffer buf, int position) {
    buf.putLong(position, Long.MIN_VALUE);
    buf.putDouble(position + Longs.BYTES, 0);
}

From source file:io.druid.query.aggregation.first.DoubleFirstBufferAggregator.java

@Override
public void init(ByteBuffer buf, int position) {
    buf.putLong(position, Long.MAX_VALUE);
    buf.putDouble(position + Longs.BYTES, 0);
}

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

@Override
protected void encode(ChannelHandlerContext ctx, RPCMessage in, List<Object> out) throws Exception {
    RPCRequest.Type type = in.getType();

    long bodyBytes = 0;
    DataBuffer payload = null;/*from   w  w  w .ja  v  a 2s .  c o m*/

    if (in.hasPayload()) {
        payload = in.getPayloadDataBuffer();
        bodyBytes = payload.getLength();
    }

    int lengthBytes = Longs.BYTES;
    int typeBytes = type.getEncodedLength();
    int messageBytes = in.getEncodedLength();

    int headerBytes = lengthBytes + typeBytes + messageBytes;
    long frameBytes = headerBytes + bodyBytes;

    // Write the header info into a buffer.
    // The format is: [frame length][message type][message][(optional) data]
    ByteBuf buffer = ctx.alloc().buffer();
    buffer.writeLong(frameBytes);
    type.encode(buffer);
    in.encode(buffer);

    // Output the header buffer.
    out.add(buffer);

    if (payload != null && bodyBytes > 0) {
        Object output = payload.getNettyOutput();
        Preconditions.checkArgument(output instanceof ByteBuf || output instanceof FileRegion,
                "The payload must be a ByteBuf or a FileRegion.");
        out.add(output);
    }
}

From source file:io.druid.query.aggregation.first.LongFirstBufferAggregator.java

@Override
public void init(ByteBuffer buf, int position) {
    buf.putLong(position, Long.MAX_VALUE);
    buf.putLong(position + Longs.BYTES, 0);
}