Java Code Examples for java.nio.IntBuffer#mark()

The following examples show how to use java.nio.IntBuffer#mark() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntBitPacking.java    From metrics with Apache License 2.0 6 votes vote down vote up
public void compressChunk(
        IntBuffer src,
        IntOutputStream dst,
        IntFilter filter)
{
    src.mark();
    filter.saveContext();
    int head = 0;
    for (int i = 0; i < this.blockNum; ++i) {
        int n = this.maxBits[i] = countMaxBits(src, this.blockLen, filter);
        head = (head << 8) | n;
    }
    filter.restoreContext();
    src.reset();

    dst.write(head);
    for (int i = 0; i < this.blockNum; ++i) {
        pack(src, dst, this.maxBits[i], this.blockLen, filter);
    }
}
 
Example 2
Source File: EventQueueTest.java    From termd with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuffer() {
  EventQueue queue = new EventQueue(new Keymap());
  assertEquals(0, queue.getBuffer().capacity());
  queue.append('h', 'e', 'l', 'l', 'o');
  IntBuffer buffer = queue.getBuffer();
  buffer.mark();
  assertEquals(5, buffer.capacity());
  assertEquals('h', buffer.get());
  assertEquals('e', buffer.get());
  assertEquals('l', buffer.get());
  assertEquals('l', buffer.get());
  assertEquals('o', buffer.get());
  buffer.reset();
  try {
    buffer.put(0, 'p');
    fail();
  } catch (ReadOnlyBufferException ignore) {
  }
}
 
Example 3
Source File: EventQueueTest.java    From termd with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuffer() {
  EventQueue queue = new EventQueue(new Keymap());
  assertEquals(0, queue.getBuffer().capacity());
  queue.append('h', 'e', 'l', 'l', 'o');
  IntBuffer buffer = queue.getBuffer();
  buffer.mark();
  assertEquals(5, buffer.capacity());
  assertEquals('h', buffer.get());
  assertEquals('e', buffer.get());
  assertEquals('l', buffer.get());
  assertEquals('l', buffer.get());
  assertEquals('o', buffer.get());
  buffer.reset();
  try {
    buffer.put(0, 'p');
    fail();
  } catch (ReadOnlyBufferException ignore) {
  }
}
 
Example 4
Source File: IntDZBP.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Override
protected int decompressLength(IntBuffer src) {
    src.mark();
    final int outLen = (int)src.get();
    src.reset();
    return outLen;
}