class FirmwareImage implements Chunk.Chunkable {

    public byte[] block(int index) {

        if (index >= blockCount()) {
            throw new ArrayIndexOutOfBoundsException("Invalid block index " + index);
        }

        byte[] theBlock = new byte[FW_BLOCK_SIZE + 2];

        // Copy the UINT16 block index into the array (2 bytes)
        byte[] rawIndex = intToTwoBytes(index, Constants.CC2540_BYTE_ORDER);
        System.arraycopy(rawIndex, 0, theBlock, 0, 2);

        // Copy the block data into the array (16 bytes)
        int blockStart = index * FW_BLOCK_SIZE;
        int length = FW_BLOCK_SIZE;
        while (blockStart + length > data().length) { length--; }
        System.arraycopy(data(), blockStart, theBlock, 2, length);

        return theBlock;
    }

    public  FirmwareImage(byte[] rawData, String filename);

}