Example #1
0
  /**
   * Encodes this sector into a {@link ByteBuffer}.
   *
   * @return The encoded buffer.
   */
  public ByteBuffer encode() {
    ByteBuffer buf = ByteBuffer.allocate(SIZE);
    if (id > 65535) {
      buf.putInt(id);
    } else {
      buf.putShort((short) id);
    }
    buf.putShort((short) chunk);
    ByteBufferUtils.putMedium(buf, nextSector);
    buf.put((byte) type);
    buf.put(data);

    return (ByteBuffer) buf.flip();
  }