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

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

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

origin: apache/mina

/**
 * @see ByteBuffer#put(byte[])
 */
public IoBuffer put(byte[] src) {
  put(src, 0, src.length);
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#put(int, byte)
 */
public IoBuffer put(int index, byte value) {
  if (index >= limit.getPosition()) {
    throw new IndexOutOfBoundsException();
  }
  Pointer p = getPointerByPosition(index);
  put(p, value);
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#put(ByteBuffer)
 */
public IoBuffer put(ByteBuffer src) {
  if (remaining() < src.remaining()) {
    throw new BufferOverflowException();
  }
  if (isReadOnly()) {
    throw new ReadOnlyBufferException();
  }
  while (src.hasRemaining()) {
    put(src.get());
  }
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#put(byte)
 */
public IoBuffer put(byte b) {
  if (readonly) {
    throw new ReadOnlyBufferException();
  }
  if (position.getPosition() >= limit.getPosition()) {
    throw new BufferUnderflowException();
  }
  put(position, b);
  return this;
}
origin: apache/mina

private IoBuffer putShort(Pointer pointer, short value) {
  if (position.getPosition() > pointer.getPosition()
      || pointer.getPosition() > limit.getPosition() - Short.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  for (int i = 0; i < Short.SIZE; i += Byte.SIZE) {
    put(pointer, (byte) (value >> (bo == ByteOrder.BIG_ENDIAN ? Byte.SIZE - i : i)));
  }
  return this;
}
origin: apache/mina

private IoBuffer putInt(Pointer pointer, int value) {
  if (position.getPosition() > pointer.getPosition()
      || pointer.getPosition() > limit.getPosition() - Integer.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  for (int i = 0; i < Integer.SIZE; i += Byte.SIZE) {
    put(pointer, (byte) (value >> (bo == ByteOrder.BIG_ENDIAN ? (Integer.SIZE - Byte.SIZE) - i : i)));
  }
  return this;
}
origin: apache/mina

private IoBuffer putLong(Pointer pointer, long value) {
  if (position.getPosition() > pointer.getPosition()
      || pointer.getPosition() > limit.getPosition() - Long.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  for (int i = 0; i < Long.SIZE; i += Byte.SIZE) {
    put(pointer, (byte) (value >> (bo == ByteOrder.BIG_ENDIAN ? (Long.SIZE - Byte.SIZE) - i : i)));
  }
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#put(ByteBuffer)
 */
public IoBuffer put(IoBuffer src) {
  if (src == this) { // NOSONAR, checking the instance
    throw new IllegalArgumentException();
  }
  if (remaining() < src.remaining()) {
    throw new BufferOverflowException();
  }
  if (isReadOnly()) {
    throw new ReadOnlyBufferException();
  }
  while (src.hasRemaining()) {
    put(src.get());
  }
  return this;
}
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#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

@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");
      }
    }
  }
}
org.apache.mina.codecIoBufferput

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

Popular in Java

  • Making http requests using okhttp
  • getContentResolver (Context)
  • compareTo (BigDecimal)
  • runOnUiThread (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Reference (javax.naming)
  • Github Copilot alternatives
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