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

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

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

origin: apache/mina

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

/**
 * @see ByteBuffer#get(int)
 */
public byte get(int index) {
  if (index >= limit.getPosition()) {
    throw new IndexOutOfBoundsException();
  }
  return get(getPointerByPosition(index));
}
origin: apache/mina

private short getShort(Pointer pos) {
  if (pos.getPosition() > capacity - Short.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  if (bo == ByteOrder.BIG_ENDIAN) {
    return (short) ((get(pos) & BYTE_MASK) << Byte.SIZE | (get(pos) & BYTE_MASK));
  } else {
    return (short) ((get(pos) & BYTE_MASK) | (get(pos) & BYTE_MASK) << Byte.SIZE);
  }
}
origin: apache/mina

  @Override
  public Integer decode(IoBuffer input) {
    if (input.remaining() < 4) {
      return null;
    }
    int out = 0;
    for (int i = 0; i < 32; i += 8) {
      out |= (input.get() & 0xff) << (bo == ByteOrder.BIG_ENDIAN ? 24 - i : i);
    }
    return out;
  }
}
origin: apache/mina

@Override
public int read() throws IOException {
  return hasRemaining() ? get() & BYTE_MASK : -1;
}
origin: apache/mina

  @Override
  public int read(byte[] b, int off, int len) throws IOException {
    if (!hasRemaining()) {
      return -1;
    }
    int toRead = Math.min(remaining(), len);
    get(b, off, toRead);
    return toRead;
  }
};
origin: apache/mina

  public <L extends TBase<?, ?>> L get(Class<L> clazz)
      throws InstantiationException, IllegalAccessException,
      TException {
    L object = clazz.newInstance();
    byte array[] = new byte[buffer.remaining()];
    buffer.get(array);
    deserializer.deserialize(object, array);
    return object;
  }
}
origin: apache/mina

/**
 * @see ByteBuffer#get()
 */
public byte get() {
  if (!hasRemaining()) {
    throw new BufferUnderflowException();
  }
  return get(position);
}
origin: apache/mina

private int getInt(Pointer pos) {
  if (pos.getPosition() > capacity - Integer.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  int out = 0;
  for (int i = 0; i < Integer.SIZE; i += Byte.SIZE) {
    out |= (get(pos) & BYTE_MASK) << (bo == ByteOrder.BIG_ENDIAN ? (Integer.SIZE - Byte.SIZE) - i : i);
  }
  return out;
}
origin: apache/mina

private long getLong(Pointer pos) {
  if (pos.getPosition() > capacity - Long.SIZE / Byte.SIZE) {
    throw new BufferUnderflowException();
  }
  long out = 0;
  for (int i = 0; i < Long.SIZE; i += Byte.SIZE) {
    out |= (get(pos) & BYTE_MASK_L) << (bo == ByteOrder.BIG_ENDIAN ? (Long.SIZE - Byte.SIZE) - i : i);
  }
  return out;
}
origin: apache/mina

/**
 * {@inheritDoc}
 */
@Override
public int hashCode() {
  int hash = 0;
  Pointer oldPos = position.duplicate();
  while (hasRemaining()) {
    hash *= 31; // NOSONAR, standard way of hashing
    hash += get();
  }
  position = oldPos;
  return hash;
}
origin: apache/mina

/**
 * {@inheritDoc}
 */
@Override
public OUTPUT decode(IoBuffer input) {
  OUTPUT object;
  try {
    byte array[] = new byte[input.remaining()];
    input.get(array);
    object = clazz.newInstance();
    deserializer.deserialize(object, array);
    return object;
  } catch (TException e) {
    throw new ProtocolDecoderException(e);
  } catch (InstantiationException e) {
    throw new ProtocolDecoderException(e);
  } catch (IllegalAccessException e) {
    throw new ProtocolDecoderException(e);
  }
}
origin: apache/mina

/**
 * Test set position method over a buffer
 */
@Test
public void testSetPositionBuffer() {
  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);
  // Check with random positions
  for (int i : new int[] { 4, 6, 7, 8, 3, 9, 1, 5, 0, 2 }) {
    ioBuffer.position(i);
    assertEquals('0' + i, ioBuffer.get());
  }
}
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

/**
 * @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 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 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

/**
 * @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 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 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());
  }
}
org.apache.mina.codecIoBufferget

Popular methods of IoBuffer

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

Popular in Java

  • Updating database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • getContentResolver (Context)
  • putExtra (Intent)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Notification (javax.management)
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Top Vim 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