/** * Returns a protective copy of the data block. * * @see #getDataSize */ final byte[] getDataBlock() { final int size = getDataSize(); assert UShort.check(size); if (0 == size) return EMPTY; final byte[] data = new byte[size]; writeTo(data, 0); return data; }
/** * Serializes a list of Extra Fields of {@link #getExtraLength} bytes to the * byte array {@code data} at the zero based offset {@code off}. * Upon return, this collection shall not access {@code data} * subsequently. * * @param data The byte array to write the list of Extra Fields to. * @param off The zero based offset in the byte array where the first byte * of the list of Extra Fields is written to. * @throws IndexOutOfBoundsException If the byte array * {@code data} does not hold at least {@link #getExtraLength} * bytes at the zero based offset {@code off}. * @see #getExtraLength */ void writeTo(final byte[] data, int off) throws IndexOutOfBoundsException { for (final ExtraField ef : extra.values()) { writeShort(ef.getHeaderId(), data, off); off += 2; writeShort(ef.getDataSize(), data, off); off += 2; ef.writeTo(data, off); off += ef.getDataSize(); } } }