Example usage for java.nio ByteBuffer putLong

List of usage examples for java.nio ByteBuffer putLong

Introduction

In this page you can find the example usage for java.nio ByteBuffer putLong.

Prototype

public abstract ByteBuffer putLong(long value);

Source Link

Document

Writes the given long to the current position and increases the position by 8.

Usage

From source file:org.apache.hama.monitor.fd.UDPSensor.java

/**
 * The heartbeat function, signifying its existence.
 *///ww  w .  j  a  v  a2s  .c o m
@Override
public void heartbeat() throws IOException {
    ByteBuffer heartbeat = ByteBuffer.allocate(8);
    heartbeat.clear();
    heartbeat.putLong(sequence.incrementAndGet());
    heartbeat.flip();
    channel.send(heartbeat, new InetSocketAddress(this.host, this.port));
    if (LOG.isDebugEnabled()) {
        LOG.debug("Heartbeat sequence " + sequence.get() + " is sent to " + this.host + ":" + this.port);
    }
}

From source file:org.apache.hadoop.hdfs.hoss.db.PathStore.java

/**
 * //ww  w .j a va  2  s.  com
 * @param pathId
 * @param objId:the index-th block in fileblockstore
 * @param offset
 * @return
 */
public PathPosition put(long objId, long pathId, long offset) {
    String path = getFixedPath(pathId);
    //set the block index in the fileblockstore
    final WriteBuffer wbuf = fbs.set((int) objId);
    final ByteBuffer buf = wbuf.buf();
    StringSerializer.fromStringToBuffer(buf, path, PATHWIDTH);
    buf.putLong(offset);
    buf.flip();
    wbuf.save();
    PathPosition pp = new PathPosition(path, offset);
    return pp;
}

From source file:com.jivesoftware.os.rcvs.api.keys.SymetricalHashableKeyTest.java

License:asdf

public byte[] longBytes(long x) {
    ByteBuffer buffer = ByteBuffer.allocate(8);
    buffer.putLong(x);
    return buffer.array();
}

From source file:com.knewton.mapreduce.example.StudentEventMapperTest.java

/**
 * Test the end time range filters in the mapper.
 *//*from  w  ww  .  j  a  v  a  2 s  . c  om*/
@Test
public void testEndRangeStudentEvents() throws Exception {
    conf.set(PropertyConstants.END_DATE.txt, "2013-03-28T23:03:02.394Z");
    underTest.setup(mockedContext);

    // send event outside of time range

    // Mar.29.2013.03:07:21.0.0
    DateTime dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    long eventId = dt.getMillis();
    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    Cell column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext, never()).write(any(LongWritable.class), any(StudentEventWritable.class));

    // send event inside of time range

    // Mar.28.2013.19:53:38.0.0
    dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    eventId = dt.getMillis();
    randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext).write(any(LongWritable.class), any(StudentEventWritable.class));
}

From source file:com.openteach.diamond.network.waverider.command.Command.java

/**
 * ByteBuffer/*w w w  . j a  va  2  s.co m*/
 * @return
 */
public ByteBuffer marshall() {
    int length = getSize();
    ByteBuffer buffer = ByteBuffer.allocate(length);
    buffer.putLong(type);
    buffer.putInt(length);
    buffer.put(payLoad);
    buffer.flip();
    payLoad.clear();
    return buffer;
}

From source file:com.knewton.mapreduce.example.StudentEventMapperTest.java

/**
 * Test the start time range filters in the mapper.
 *//* ww w  .  j  a  v a2 s. com*/
@Test
public void testMapWithStartRangeStudentEvents() throws Exception {
    conf.set(PropertyConstants.START_DATE.txt, "2013-03-28T23:03:02.394Z");
    underTest.setup(mockedContext);

    // send event outside of time range

    // Mar.28.2013.19:53:38.0.0
    DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    long eventId = dt.getMillis();

    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    Cell column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));

    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext, never()).write(any(LongWritable.class), any(StudentEventWritable.class));

    // send event inside of time range

    // Mar.29.2013.03:07:21.0.0
    dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    eventId = dt.getMillis();

    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext).write(any(LongWritable.class), any(StudentEventWritable.class));
}

From source file:org.apache.bookkeeper.stream.SSN.java

/**
 * Serialize the SSN into a string using given <i>version</i>.
 *
 * @param version version used to serialize SSN
 * @return serialized ssn/*from  w w  w .java2  s  .  c  o m*/
 */
public String serialize(byte version) {
    Preconditions.checkArgument(version == CUR_VERSION,
            "Only support version less than or equal to " + CUR_VERSION);
    byte[] data = new byte[LENGTH];
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.put(version);
    bb.putLong(segmentId);
    bb.putLong(entryId);
    bb.putLong(slotId);
    return Base64.encodeBase64String(data);
}

From source file:experts.net.ip6.ULUA.java

/**
 * Generate Global ID according to RFC 4193 Section 3.2.2.
 *
 * @param timeStamp/*  www . j a  va2 s .  co  m*/
 *            64-bit NTP format
 */
public final void generateGlobalID(long timeStamp) {
    ByteBuffer buf = ByteBuffer.allocate(16);

    buf.putLong(timeStamp);
    interfaceID.forEach(buf::putShort);

    byte[] digest = DigestUtils.sha1(buf.array());

    buf = ByteBuffer.allocate(6);
    buf.put(GLOBAL_ID_PREFIX).put(digest, 15, 5);

    globalID = toList(buf);
}

From source file:com.knewton.mapreduce.SSTableColumnMapperTest.java

/**
 * Test the start time range filters in the mapper.
 * //ww w. j av  a 2 s . c o m
 * @throws IOException
 * @throws InterruptedException
 * @throws DecoderException
 */
@Test
public void testStartRangeStudentEvents() throws IOException, InterruptedException, DecoderException {

    // Mar.28.2013.19:53:38.0.0
    DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    long eventId1 = dt.getMillis();
    // Mar.29.2013.03:07:21.0.0
    dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    long eventId5 = dt.getMillis();

    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId1);
    columnName.rewind();
    IColumn column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    Configuration conf = new Configuration();
    conf.set(StudentEventAbstractMapper.START_DATE_PARAMETER_NAME, "2013-03-28T23:03:02.394-04:00");
    DoNothingStudentEventMapper dnsem = new DoNothingStudentEventMapper();
    Mapper<ByteBuffer, IColumn, LongWritable, StudentEventWritable>.Context context = dnsem.new Context(conf,
            new TaskAttemptID(), null, null, null, new DoNothingStatusReporter(), null);
    dnsem.setup(context);
    dnsem.map(RandomStudentEventGenerator.getRandomIdBuffer(), column, context);
    assertNull(dnsem.getRowKey());
    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId5);
    columnName.rewind();
    column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    dnsem.map(randomKey, column, context);
    assertEquals(dnsem.getRowKey(), randomKey);
}

From source file:com.knewton.mapreduce.SSTableColumnMapperTest.java

/**
 * Test the end time range filters in the mapper.
 * /*from w ww  .  j  a va  2  s  .co  m*/
 * @throws IOException
 * @throws InterruptedException
 * @throws DecoderException
 */
@Test
public void testEndRangeStudentEvents() throws IOException, InterruptedException, DecoderException {

    // Mar.28.2013.19:53:38.0.0
    DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    long eventId1 = dt.getMillis();
    // Mar.29.2013.03:07:21.0.0
    dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    long eventId5 = dt.getMillis();

    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId5);
    columnName.rewind();
    IColumn column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    Configuration conf = new Configuration();
    conf.set(StudentEventAbstractMapper.END_DATE_PARAMETER_NAME, "2013-03-28T23:03:02.394-04:00");
    DoNothingStudentEventMapper dnsem = new DoNothingStudentEventMapper();
    Mapper<ByteBuffer, IColumn, LongWritable, StudentEventWritable>.Context context = dnsem.new Context(conf,
            new TaskAttemptID(), null, null, null, new DoNothingStatusReporter(), null);
    dnsem.setup(context);
    dnsem.map(RandomStudentEventGenerator.getRandomIdBuffer(), column, context);
    assertNull(dnsem.getRowKey());
    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId1);
    columnName.rewind();
    column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    dnsem.map(randomKey, column, context);
    assertEquals(dnsem.getRowKey(), randomKey);
}