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

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

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

origin: apache/mina

private IoBuffer() {
  limit(0);
  position(0);
  mark = null;
}
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#position(int)
 */
public void position(int newPosition) {
  if (newPosition > limit() || newPosition < 0) {
    throw new IllegalArgumentException();
  }
  if (mark != null && mark.getPosition() > newPosition) {
    mark = null;
  }
  this.position.setPosition(newPosition);
}
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 over a buffer
 */
@Test
public void testPositionBuffer() {
  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);
  // Iterate and check the position
  for (int i = 0; i < ioBuffer.limit(); i++) {
    assertEquals(i, ioBuffer.position());
    ioBuffer.get();
  }
}
origin: apache/mina

@Test
public void testGet() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(5);
  bb2.put("345".getBytes());
  bb2.flip();
  ByteBuffer bb3 = ByteBuffer.allocate(5);
  bb3.put("6789".getBytes());
  bb3.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2).add(bb3);
  ioBuffer.position(2);
  ioBuffer.limit(8);
  byte block[] = new byte[6];
  ioBuffer.get(block);
  byte seg[] = "234567".getBytes();
  for (int i = 0; i < 6; i++) {
    assertEquals(seg[i], block[i]);
  }
}
origin: apache/mina

/**
 * Test the clear() method
 */
@Test
public void testClearEmptyBuffer() {
  ByteBuffer bb1 = ByteBuffer.allocate(4);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(4);
  bb2.put("345".getBytes());
  bb2.flip();
  IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2);
  assertEquals(6, ioBuffer.limit());
  // Move forward a bit
  ioBuffer.get();
  ioBuffer.get();
  ioBuffer.limit(3);
  // Clear
  ioBuffer.clear();
  // We should be back to the origin
  assertEquals(0, ioBuffer.position());
  // The limit must back to the available size
  assertEquals(6, ioBuffer.limit());
}
origin: apache/mina

@Test
public void testCompact() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(5);
  bb2.put("345".getBytes());
  bb2.flip();
  ByteBuffer bb3 = ByteBuffer.allocate(5);
  bb3.put("6789".getBytes());
  bb3.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2).add(bb3);
  ioBuffer.position(2);
  ioBuffer.limit(8);
  ioBuffer.compact();
  assertEquals(ioBuffer.capacity(), ioBuffer.limit());
  assertEquals(6, ioBuffer.position());
  byte seg[] = "234567".getBytes();
  for (int i = 0; i < 6; i++) {
    assertEquals(seg[i], ioBuffer.get(i));
  }
}
origin: apache/mina

/**
 * Test the flip() method
 */
@Test
public void testFlip() {
  ByteBuffer bb1 = ByteBuffer.allocate(4);
  bb1.put("0123".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(4);
  bb2.put("4567".getBytes());
  bb2.flip();
  IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2);
  // Move forward a bit
  ioBuffer.get();
  ioBuffer.get();
  // Clear
  ioBuffer.clear();
  // We should be back to the origin
  assertEquals(0, ioBuffer.position());
  assertEquals(8, ioBuffer.limit());
}
origin: apache/mina

@Test
public void testSlice() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(5);
  bb2.put("345".getBytes());
  bb2.flip();
  ByteBuffer bb3 = ByteBuffer.allocate(5);
  bb3.put("6789".getBytes());
  bb3.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2).add(bb3);
  ioBuffer.position(2);
  ioBuffer.limit(8);
  IoBuffer slice = ioBuffer.slice();
  assertEquals(6, slice.remaining());
  assertEquals(0, slice.position());
  assertEquals(6, slice.limit());
  byte seg[] = "234567".getBytes();
  for (int i = 0; i < 6; i++) {
    assertEquals(seg[i], slice.get(i));
  }
}
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 testExtendedValues() {
  for (int value : new int[] { 0, 1, 127, 128, 65536, 198649, Integer.MAX_VALUE }) {
    ByteBuffer buffer = encoder.encode(value);
    for (int i = 1; i < 5; i++) {
      int size = buffer.remaining() + i;
      IoBuffer extendedBuffer = IoBuffer.wrap(ByteBuffer.allocate(size));
      int start = extendedBuffer.position();
      extendedBuffer.put(buffer.slice());
      extendedBuffer.position(start);
      extendedBuffer.limit(start + size);
      try {
        decoder.decode(extendedBuffer);
        assertEquals(i, extendedBuffer.remaining());
      } catch (ProtocolDecoderException e) {
        fail("Should not throw exception");
      }
    }
  }
}
origin: apache/mina

/**
 * Test the get() method on a IoBuffer containing one ByteBuffer with 0
 * bytes
 */
@Test
public void testGetOneBuffer0Bytes() {
  ByteBuffer bb = ByteBuffer.allocate(0);
  IoBuffer ioBuffer = IoBuffer.wrap(bb);
  assertEquals(0, ioBuffer.position());
  assertEquals(0, ioBuffer.limit());
  try {
    assertFalse(ioBuffer.hasRemaining());
    ioBuffer.get();
    fail();
  } catch (BufferUnderflowException bufe) {
    // expected
    assertEquals(0, ioBuffer.position());
  }
}
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 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());
}
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());
}
org.apache.mina.codecIoBufferlimit

Javadoc

The maximal position in the IoBuffer

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,
  • order,
  • position,
  • put,
  • putChar,
  • putDouble

Popular in Java

  • Reading from database using SQL prepared statement
  • setScale (BigDecimal)
  • requestLocationUpdates (LocationManager)
  • scheduleAtFixedRate (Timer)
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JButton (javax.swing)
  • JLabel (javax.swing)
  • Best IntelliJ plugins
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