Code example for ByteBuffer

Methods: asReadOnlyBuffer, get, remaining

0
    return buffer.getInt(buffer.position() + (index * 4));
  } 
 
  public ByteBuffer getBuffer()
  { 
    return buffer.asReadOnlyBuffer();
  } 
 
  @Override 
  public int compareTo(IntBufferIndexedInts o)
  { 
    return buffer.compareTo(o.getBuffer());
  } 
 
  @Override 
  public Iterator<Integer> iterator()
  { 
    return new IndexedIntsIterator(this);
  } 
 
  private static class IntBufferIndexedIntsObjectStrategy implements ObjectStrategy<IntBufferIndexedInts> 
  { 
    @Override 
    public Class<? extends IntBufferIndexedInts> getClazz()
    { 
      return IntBufferIndexedInts.class; 
    } 
 
    @Override 
    public IntBufferIndexedInts fromByteBuffer(ByteBuffer buffer, int numBytes)
    { 
      buffer.limit(buffer.position() + numBytes);
      return new IntBufferIndexedInts(buffer);
    } 
 
    @Override 
    public byte[] toBytes(IntBufferIndexedInts val)
    { 
      ByteBuffer buffer = val.getBuffer();
      byte[] bytes = new byte[buffer.remaining()];
      buffer.get(bytes);
 
      return bytes;
    } 
 
    @Override