示例#1
0
  /**
   * Decodes the specified {@link ByteBuffer} into a {@link Sector} object.
   *
   * @param buf The buffer.
   * @return The sector.
   */
  public static Sector decodeExtended(ByteBuffer buf) {
    if (buf.remaining() != SIZE) throw new IllegalArgumentException();

    int id = buf.getInt();
    int chunk = buf.getShort() & 0xFFFF;
    int nextSector = ByteBufferUtils.getMedium(buf);
    int type = buf.get() & 0xFF;
    byte[] data = new byte[EXTENDED_DATA_SIZE];
    buf.get(data);

    return new Sector(type, id, chunk, nextSector, data);
  }
示例#2
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();
  }