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

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

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

origin: apache/mina

/**
 * @see ByteBuffer#hasRemaining()
 */
public boolean hasRemaining() {
  return remaining() > 0;
}
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(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#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(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

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

/**
 * @see ByteBuffer#get(byte[], int,int)
 */
public IoBuffer get(byte[] dst, int offset, int length) {
  if (remaining() < length) {
    throw new BufferUnderflowException();
  }
  int remainsToCopy = length;
  int currentOffset = offset;
  while (remainsToCopy > 0) {
    position.updatePos();
    position.getNode().getBuffer().position(position.getPositionInNode());
    ByteBuffer currentBuffer = position.getNode().getBuffer();
    int blocksize = Math.min(remainsToCopy, currentBuffer.remaining());
    position.getNode().getBuffer().get(dst, currentOffset, blocksize);
    currentOffset += blocksize;
    remainsToCopy -= blocksize;
    position.incrementPosition(blocksize);
    position.getNode().getBuffer().position(0);
  }
  return this;
}
origin: apache/mina

/**
 * @see ByteBuffer#put(byte[], int, int)
 */
public IoBuffer put(byte[] src, int offset, int length) {
  if (readonly) {
    throw new ReadOnlyBufferException();
  }
  if (remaining() < length) {
    throw new BufferUnderflowException();
  }
  int remainsToCopy = length;
  int currentOffset = offset;
  position.getNode().getBuffer().position(position.getPositionInNode());
  while (remainsToCopy > 0) {
    position.updatePos();
    ByteBuffer currentBuffer = position.getNode().getBuffer();
    int blocksize = Math.min(remainsToCopy, currentBuffer.remaining());
    position.getNode().getBuffer().put(src, currentOffset, blocksize);
    currentOffset += blocksize;
    remainsToCopy -= blocksize;
    position.incrementPosition(blocksize);
  }
  position.getNode().getBuffer().position(0);
  return this;
}
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

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object ob) {
  if (this == ob) {
    return true;
  }
  if (!(ob instanceof IoBuffer)) {
    return false;
  }
  IoBuffer that = (IoBuffer) ob;
  if (this.remaining() != that.remaining()) {
    return false;
  }
  int p = this.position();
  int q = that.position();
  while (this.hasRemaining() && that.hasRemaining()) {
    if (this.get() != that.get()) {
      this.position(p);
      that.position(q);
      return false;
    }
  }
  this.position(p);
  that.position(q);
  return true;
}
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
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");
      }
    }
  }
}
org.apache.mina.codecIoBufferremaining

Popular methods of IoBuffer

  • asInputStream
    Provides an input stream which is actually reading the IoBufferinstance. Further reads on the return
  • get
  • 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

  • Reactive rest calls using spring rest template
  • getSupportFragmentManager (FragmentActivity)
  • getResourceAsStream (ClassLoader)
  • getSharedPreferences (Context)
  • Kernel (java.awt.image)
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Top Sublime Text 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