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:co.cask.cdap.api.dataset.lib.PartitionConsumerState.java

public byte[] toBytes() {
    int numLongs = 1 + versionsToCheck.size();
    // first byte for serialization format version
    ByteBuffer bb = ByteBuffer.allocate(1 + Longs.BYTES * numLongs);
    // currently, serialization format is 0
    bb.put((byte) 0);
    bb.putLong(startVersion);//from   ww  w. j av a2 s. c  o  m
    for (long l : versionsToCheck) {
        bb.putLong(l);
    }
    return bb.array();
}

From source file:com.metamx.druid.query.metadata.SegmentAnalyzer.java

public ColumnAnalysis analyzeLongColumn(Column column) {
    return lengthBasedAnalysis(column, Longs.BYTES);
}

From source file:org.leveldb.util.ByteArrayBuilder.java

public void appendLong(long value) {
    ensureAdditionalCapacity(Longs.BYTES);
    setLong(size, value);
    size += Longs.BYTES;
}

From source file:co.cask.tigon.sql.io.GDATEncoder.java

@Override
public Encoder writeLong(long l) throws IOException {
    sharedByteBuffer.clear();/*w  w w.  j a va  2s  . c o m*/
    sharedByteBuffer.putLong(l);
    sharedByteBuffer.flip();
    buffer.write(sharedByteBuffer.array(), 0, Longs.BYTES);
    return this;
}

From source file:org.echocat.marquardt.common.util.InputStreamUtils.java

private long internalReadLong(@Nonnull @WillNotClose final InputStream inputStream) throws IOException {
    final byte[] bytes = readBytes(inputStream, Longs.BYTES);
    return Longs.fromByteArray(bytes);
}

From source file:org.apache.gobblin.writer.SimpleDataWriter.java

/**
 * Write a source record to the staging file
 *
 * @param record data record to write// w w  w .j a va 2 s.  c  o  m
 * @throws java.io.IOException if there is anything wrong writing the record
 */
@Override
public void write(byte[] record) throws IOException {
    Preconditions.checkNotNull(record);

    byte[] toWrite = record;
    if (this.recordDelimiter.isPresent()) {
        toWrite = Arrays.copyOf(record, record.length + 1);
        toWrite[toWrite.length - 1] = this.recordDelimiter.get();
    }
    if (this.prependSize) {
        long recordSize = toWrite.length;
        ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES);
        buf.putLong(recordSize);
        toWrite = ArrayUtils.addAll(buf.array(), toWrite);
    }
    this.stagingFileOutputStream.write(toWrite);
    this.bytesWritten += toWrite.length;
    this.recordsWritten++;
}

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

@JsonValue
public byte[] toBytes() {
    ByteBuffer buf = ByteBuffer
            .allocate(Ints.BYTES + Floats.BYTES * breaks.length + Longs.BYTES * bins.length + Floats.BYTES * 2);

    buf.putInt(breaks.length);/*www. ja  va  2 s  .  c o m*/
    for (float b : breaks)
        buf.putFloat(b);
    for (long c : bins)
        buf.putLong(c);
    buf.putFloat(min);
    buf.putFloat(max);

    return buf.array();
}

From source file:org.apache.tajo.util.UnsafeComparer.java

@Override
public int compare(byte[] left, byte[] right) {
    int minLength = Math.min(left.length, right.length);
    int minWords = minLength / Longs.BYTES;

    /*//from w  w  w.j  a va 2s. com
     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
     * time is no slower than comparing 4 bytes at a time even on 32-bit.
     * On the other hand, it is substantially faster on 64-bit.
     */
    for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
        long lw = theUnsafe.getLong(left, BYTE_ARRAY_BASE_OFFSET + (long) i);
        long rw = theUnsafe.getLong(right, BYTE_ARRAY_BASE_OFFSET + (long) i);
        long diff = lw ^ rw;

        if (diff != 0) {
            if (!littleEndian) {
                return UnsignedLongs.compare(lw, rw);
            }

            // Use binary search
            int n = 0;
            int y;
            int x = (int) diff;
            if (x == 0) {
                x = (int) (diff >>> 32);
                n = 32;
            }

            y = x << 16;
            if (y == 0) {
                n += 16;
            } else {
                x = y;
            }

            y = x << 8;
            if (y == 0) {
                n += 8;
            }
            return (int) (((lw >>> n) & 0xFFL) - ((rw >>> n) & 0xFFL));
        }
    }

    // The epilogue to cover the last (minLength % 8) elements.
    for (int i = minWords * Longs.BYTES; i < minLength; i++) {
        int result = UnsignedBytes.compare(left[i], right[i]);
        if (result != 0) {
            return result;
        }
    }
    return left.length - right.length;
}

From source file:co.cask.cdap.internal.io.ReflectionDatumWriter.java

private void writeBytes(Object object, Encoder encoder) throws IOException {
    if (object instanceof ByteBuffer) {
        encoder.writeBytes((ByteBuffer) object);
    } else if (object instanceof UUID) {
        UUID uuid = (UUID) object;
        ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES * 2);
        buf.putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits());
        encoder.writeBytes((ByteBuffer) buf.flip());
    } else {//from w  w  w .ja v  a2s  . c o  m
        encoder.writeBytes((byte[]) object);
    }
}

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

/**
 * Creates a decoder that splits up the incoming ByteBuf into new ByteBuf's according to a length
 * field in the input./*from w  w w  . j av  a2 s .  c o m*/
 *
 * The encoding scheme is: [(long) frame length][message payload]
 * The frame length is NOT included in the output ByteBuf.
 *
 * @return the frame decoder for Netty
 */
public static ByteToMessageDecoder createFrameDecoder() {
    // maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip
    return new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, Longs.BYTES, -Longs.BYTES, Longs.BYTES);
}