Code example for WritableByteChannel

Methods: write

0
    return new IndexedIntsIterator(this);
  } 
 
  public void writeToChannel(WritableByteChannel channel) throws IOException
  { 
    channel.write(ByteBuffer.wrap(new byte[]{version, (byte) numBytes}));
    channel.write(ByteBuffer.wrap(Ints.toByteArray(buffer.remaining())));
    channel.write(buffer.asReadOnlyBuffer());
  } 
 
  public static VSizeIndexedInts readFromByteBuffer(ByteBuffer buffer)
  { 
    byte versionFromBuffer = buffer.get();
 
    if (version == versionFromBuffer) {
      int numBytes = buffer.get();
      int size = buffer.getInt();
      ByteBuffer bufferToUse = buffer.asReadOnlyBuffer();
      bufferToUse.limit(bufferToUse.position() + size);
      buffer.position(bufferToUse.limit());