congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
IoBuffer.add
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: apache/mina

/**
 * @see ByteBuffer#wrap(byte[])
 */
public static IoBuffer wrap(byte[]... arrays) {
  IoBuffer ioBuffer = new IoBuffer();
  for (byte[] array : arrays) {
    ioBuffer.add(ByteBuffer.wrap(array));
  }
  return ioBuffer;
}
origin: apache/mina

/**
 * Extends the current IoBuffer capacity.
 * 
 * @param size
 *            the number of bytes to extend the current IoBuffer
 * @return the current {@link IoBuffer}
 */
public IoBuffer extend(int size) {
  ByteBuffer extension = isDirect() ? ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
  add(extension);
  return this;
}
origin: apache/mina

/**
 * Wraps ByteBuffers into a new IoBuffer
 * 
 * @param buffers
 *            the ByteBuffers to wrap
 * @return the new {@link IoBuffer}
 */
public static IoBuffer wrap(ByteBuffer... buffers) {
  IoBuffer ioBuffer = new IoBuffer();
  for (ByteBuffer b : buffers) {
    ioBuffer.add(b);
  }
  return ioBuffer;
}
origin: apache/mina

/**
 * Test the addition of mixed type buffers
 */
@Test
public void testAddMixedTypeBuffers() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocateDirect(5);
  bb2.put("3456".getBytes());
  bb2.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2);
}
origin: apache/mina

/**
 * Test the addition of mixed order buffers
 */
@Test
public void testAddMixedOrderBuffers() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.order(ByteOrder.LITTLE_ENDIAN);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocateDirect(5);
  bb1.order(ByteOrder.BIG_ENDIAN);
  bb2.put("3456".getBytes());
  bb2.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2);
}
origin: apache/mina

  @Test
  public void testEquals() {
    String h = "Hello";
    String w = "World";
    IoBuffer hw1b = IoBuffer.wrap((h + w).getBytes());
    IoBuffer wh1b = IoBuffer.wrap((w + h).getBytes());
    IoBuffer hw2b = IoBuffer.newInstance();
    hw2b.add(ByteBuffer.wrap(h.getBytes()));
    hw2b.add(ByteBuffer.wrap(w.getBytes()));
    assertEquals(hw2b, hw1b);
    Assert.assertThat(wh1b, is(not(hw1b)));
  }
}
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
public void testPut() {
  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);
  byte seq[] = "abcdefghij".getBytes();
  ioBuffer.position(2);
  ioBuffer.put(seq, 3, 3);
  ioBuffer.rewind();
  byte expected[] = "01def56789".getBytes();
  for (int i = 0; i < 6; i++) {
    assertEquals(expected[i], ioBuffer.get(i));
  }
}
origin: apache/mina

/**
 * @see ByteBuffer#slice()
 */
public IoBuffer slice() {
  position.updatePos();
  IoBuffer out = new IoBuffer();
  out.order(order());
  position.getNode().getBuffer().position(position.getPositionInNode());
  if (hasRemaining()) {
    tail.getBuffer().limit(limit.getPositionInNode());
    for (BufferNode node = position.getNode(); node != limit.getNode(); node = node.getNext()) {
      if (node != head) { // NOSONAR, check if instances are the same.
        node.getBuffer().position(0);
      }
      out.add(node.getBuffer());
    }
    if (tail != head) { // NOSONAR, check if instances are the same.
      tail.getBuffer().position(0);
    }
    out.add(tail.getBuffer().slice());
    tail.getBuffer().limit(tail.getBuffer().capacity());
  }
  position.getNode().getBuffer().position(0);
  return out;
}
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
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

/**
 * Test the addition of 3 heap buffers, one being empty
 */
@Test
public void testAddHeapBuffersOneEmpty() {
  ByteBuffer bb1 = ByteBuffer.allocate(5);
  bb1.put("012".getBytes());
  bb1.flip();
  ByteBuffer bb2 = ByteBuffer.allocate(0);
  ByteBuffer bb3 = ByteBuffer.allocate(5);
  bb3.put("3456".getBytes());
  bb3.flip();
  IoBuffer ioBuffer = IoBuffer.newInstance();
  ioBuffer.add(bb1, bb2).add(bb3);
  assertEquals(0, ioBuffer.position());
  assertEquals(7, ioBuffer.limit());
  assertEquals(7, ioBuffer.capacity());
  for (int i = 0; i < 7; i++) {
    assertTrue(ioBuffer.hasRemaining());
    assertEquals("0123456".charAt(i), ioBuffer.get());
  }
  try {
    ioBuffer.get();
    fail();
  } catch (BufferUnderflowException bufe) {
    assertTrue(true);
  }
}
origin: apache/mina

ioBuffer.add(bb1, bb2).add(bb3);
org.apache.mina.codecIoBufferadd

Javadoc

Add one or more ByteBuffer to the current IoBuffer

Popular methods of IoBuffer

  • asInputStream
    Provides an input stream which is actually reading the IoBufferinstance. Further reads on the return
  • get
  • remaining
  • array
  • capacity
  • getChar
  • getDouble
  • getFloat
  • getInt
  • getLong
  • getShort
  • hasRemaining
  • getShort,
  • hasRemaining,
  • isDirect,
  • limit,
  • order,
  • position,
  • put,
  • putChar,
  • putDouble

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • compareTo (BigDecimal)
  • getApplicationContext (Context)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • String (java.lang)
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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