Tabnine Logo
IoBuffer.position
Code IndexAdd Tabnine to your IDE (free)

How to use
position
method
in
org.apache.mina.codec.IoBuffer

Best Java code snippets using org.apache.mina.codec.IoBuffer.position (Showing top 20 results out of 315)

origin: apache/mina

private IoBuffer() {
  limit(0);
  position(0);
  mark = null;
}
origin: apache/mina

/**
 * @see ByteBuffer#rewind()
 */
public IoBuffer rewind() {
  position(0);
  mark = getPointerByPosition(-1);
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#remaining()
 */
public int remaining() {
  return limit() - position();
}
origin: apache/mina

@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append(getClass().getName());
  sb.append("[pos=");
  sb.append(position());
  sb.append(" lim=");
  sb.append(limit());
  sb.append(" cap=");
  sb.append(capacity());
  sb.append("]");
  return sb.toString();
}
origin: apache/mina

/**
 * @see ByteBuffer#compact()
 */
public IoBuffer compact() {
  for (int i = 0; i < remaining(); i++) {
    put(i, get(i + position.getPosition()));
  }
  position(limit() - position());
  limit(capacity);
  mark = null;
  return this;
}
origin: apache/mina

/**
 * Returns a copy of the current {@link IoBuffer}, with an independent copy
 * of the position, limit and mark.
 * 
 * @return the copied {@link IoBuffer}
 */
public IoBuffer duplicate() {
  IoBuffer buffer = new IoBuffer();
  for (BufferNode node = head; node != null; node = node.getNext()) {
    ByteBuffer byteBuffer = node.getBuffer().duplicate();
    byteBuffer.rewind();
    buffer.enqueue(byteBuffer);
  }
  buffer.position(position());
  buffer.limit(limit());
  buffer.mark = mark != null ? getPointerByPosition(mark.getPosition()) : null;
  buffer.readonly = readonly;
  return buffer;
}
origin: apache/mina

/**
 * Test the position method with a negative value
 */
@Test(expected = IllegalArgumentException.class)
public void testPositionNegativeValue() {
  ByteBuffer bb1 = ByteBuffer.allocate(4);
  bb1.put("0123".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(4);
  bb2.put("4567".getBytes());
  bb2.flip();
  ByteBuffer bb3 = ByteBuffer.allocate(4);
  bb3.put("89".getBytes());
  bb3.flip();
  IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2, bb3);
  ioBuffer.position(-1);
}
origin: apache/mina

/**
 * Test the position method with a value above the buffer size
 */
@Test(expected = IllegalArgumentException.class)
public void testPositionAboveValue() {
  ByteBuffer bb1 = ByteBuffer.allocate(4);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(4);
  bb2.put("3456".getBytes());
  bb2.flip();
  ByteBuffer bb3 = ByteBuffer.allocate(4);
  bb3.put("789".getBytes());
  bb3.flip();
  // The resulting buffer will be seen as "0123456789"
  IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2, bb3);
  ioBuffer.position(11);
}
origin: apache/mina

/**
 * Test the position method over an emptyIoBuffer
 */
@Test
public void testPositionIntEmptyBuffer() {
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.position(0);
}
origin: apache/mina

@Test
public void testInputStreamGetByte() throws IOException {
  String hw = "HelloWorld";
  IoBuffer bb = IoBuffer.wrap(hw.getBytes());
  InputStream is = bb.asInputStream();
  for (int i = 0; i < 10; i++) {
    assertEquals(i, bb.position());
    assertEquals(hw.getBytes()[i], is.read());
  }
  assertEquals(-1, is.read());
}
origin: apache/mina

@Test
public void testInputStreamGetByteArray() throws IOException {
  String hw = "HelloWorld";
  IoBuffer bb = IoBuffer.wrap(hw.getBytes());
  InputStream is = bb.asInputStream();
  byte array[] = new byte[15];
  assertEquals(5, is.read(array, 0, 5));
  assertEquals(5, bb.position());
  assertEquals(5, is.read(array, 5, 10));
  assertEquals(10, bb.position());
  for (int i = 0; i < 10; i++) {
    assertEquals(hw.getBytes()[i], array[i]);
  }
}
origin: apache/mina

/**
 * Test the position method over an emptyIoBuffer
 */
@Test
public void testPositionEmptyBuffer() {
  IoBuffer ioBuffer = IoBuffer.newInstance();
  assertEquals(0, ioBuffer.position());
}
origin: apache/mina

@Override
public OUT decode(IoBuffer input, MutableInt nextBlockSize) {
  OUT output = null;
  if (nextBlockSize.getValue() == null) {
    nextBlockSize.setValue(sizeDecoder.decode(input));
  }
  if (nextBlockSize.isDefined() && (input.remaining() >= nextBlockSize.getValue())) {
    IoBuffer buffer = input.slice();
    buffer.limit(buffer.position() + nextBlockSize.getValue());
    output = payloadDecoder.decode(buffer);
    nextBlockSize.reset();
  }
  return output;
}
origin: apache/mina

@Test
public void testFloat() {
  for (ByteOrder bo : new ByteOrder[] { ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN }) {
    ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(5).order(bo).putFloat(-0.68f).rewind();
    IoBuffer ioBuffer = IoBuffer.wrap(bb).order(bo);
    assertEquals(5, ioBuffer.capacity());
    ioBuffer.extend(3);
    ioBuffer.position(4);
    assertEquals(8, ioBuffer.capacity());
    ioBuffer.putFloat(3.14f);
    ioBuffer.rewind();
    assertEquals(-0.68f, ioBuffer.getFloat(), 0.001f);
    assertEquals(3.14f, ioBuffer.getFloat(), 0.001f);
    ioBuffer.rewind();
    ioBuffer.putFloat(2, -12.34f);
    assertEquals(-12.34f, ioBuffer.getFloat(2), 0.001f);
  }
}
origin: apache/mina

@Test
public void testDouble() {
  for (ByteOrder bo : new ByteOrder[] { ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN }) {
    ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(9).order(bo).putDouble(Math.PI).rewind();
    IoBuffer ioBuffer = IoBuffer.wrap(bb).order(bo);
    assertEquals(9, ioBuffer.capacity());
    ioBuffer.extend(7);
    ioBuffer.position(8);
    assertEquals(16, ioBuffer.capacity());
    ioBuffer.putDouble(-Math.E);
    ioBuffer.rewind();
    assertEquals(Math.PI, ioBuffer.getDouble(), 1E-10);
    assertEquals(-Math.E, ioBuffer.getDouble(), 1E-10);
    ioBuffer.rewind();
    ioBuffer.putDouble(4, 12.34);
    assertEquals(12.34, ioBuffer.getDouble(4), 1E-10);
  }
}
origin: apache/mina

@Test
public void testTruncatedValues() {
  for (int value : new int[] { 0, 1, 127, 128, 65536, 198649, Integer.MAX_VALUE }) {
    IoBuffer buffer = IoBuffer.wrap(encoder.encode(value));
    for (int i = 0; i < buffer.remaining(); i++) {
      IoBuffer partialBuffer = buffer.slice();
      partialBuffer.limit(partialBuffer.position() + i);
      try {
        assertNull(decoder.decode(partialBuffer));
      } catch (ProtocolDecoderException e) {
        fail("Should not throw exception");
      }
    }
  }
}
origin: apache/mina

/**
 * Test the allocation of a new heap IoBuffer with 1024 bytes
 */
@Test
public void testAllocate1024() {
  IoBuffer ioBuffer = IoBuffer.allocate(1024);
  assertFalse(ioBuffer.isDirect());
  assertEquals(1024, ioBuffer.capacity());
  assertEquals(1024, ioBuffer.limit());
  assertEquals(0, ioBuffer.position());
  assertTrue(ioBuffer.hasRemaining());
}
origin: apache/mina

/**
 * Test the allocation of a new heap IoBuffer with no byte in it
 */
@Test
public void testAllocate0() {
  IoBuffer ioBuffer = IoBuffer.allocate(0);
  assertFalse(ioBuffer.isDirect());
  assertEquals(0, ioBuffer.capacity());
  assertEquals(0, ioBuffer.limit());
  assertEquals(0, ioBuffer.position());
  assertFalse(ioBuffer.hasRemaining());
}
origin: apache/mina

/**
 * Test the allocation of a new direct IoBuffer with 1024 bytes
 */
@Test
public void testAllocateDirect1024() {
  IoBuffer ioBuffer = IoBuffer.allocateDirect(1024);
  assertTrue(ioBuffer.isDirect());
  assertEquals(1024, ioBuffer.capacity());
  assertEquals(1024, ioBuffer.limit());
  assertEquals(0, ioBuffer.position());
  assertTrue(ioBuffer.hasRemaining());
}
origin: apache/mina

/**
 * Test the allocation of a new direct IoBuffer with no byte in it
 */
@Test
public void testAllocateDirect0() {
  IoBuffer ioBuffer = IoBuffer.allocateDirect(0);
  assertTrue(ioBuffer.isDirect());
  assertEquals(0, ioBuffer.capacity());
  assertEquals(0, ioBuffer.limit());
  assertEquals(0, ioBuffer.position());
  assertFalse(ioBuffer.hasRemaining());
}
org.apache.mina.codecIoBufferposition

Javadoc

The marked position, for the next reset()

Popular methods of IoBuffer

  • asInputStream
    Provides an input stream which is actually reading the IoBufferinstance. Further reads on the return
  • get
  • remaining
  • add
    Add one or more ByteBuffer to the current IoBuffer
  • array
  • capacity
  • getChar
  • getDouble
  • getFloat
  • getInt
  • getLong
  • getShort
  • getLong,
  • getShort,
  • hasRemaining,
  • isDirect,
  • limit,
  • order,
  • put,
  • putChar,
  • putDouble

Popular in Java

  • Making http requests using okhttp
  • putExtra (Intent)
  • getSystemService (Context)
  • runOnUiThread (Activity)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now