public final void encode(final IAMCodec codec, final IAMIndex source) throws IOException, IllegalArgumentException {
		final int mappingCount = source.mappingCount();
		final int listingCount = source.listingCount();

		final IAMINDEXTYPE xmlIndex = new IAMINDEXTYPE();
		xmlIndex.byteOrder = codec.getByteOrder().toString();
		xmlIndex.mappingCount = Integer.toString(mappingCount);
		xmlIndex.listingCount = Integer.toString(listingCount);

		for (int index = 0; index < mappingCount; index++) {
			final IAMMapping mapping = source.mapping(index);
			final int entryCount = mapping.entryCount();
			if (entryCount != 0) {
				final IAMMAPPINGTYPE xmlMapping = new IAMMAPPINGTYPE();
				xmlIndex.mappingOrListing.add(xmlMapping);
				xmlMapping.index = Integer.toString(index);

				for (int i = 0; i < entryCount; i++) {
					final IAMENTRYTYPE xmlEntry = new IAMENTRYTYPE();
					xmlMapping.entry.add(xmlEntry);
					xmlEntry.key = IAMArrayFormat.ARRAY.format(mapping.key(i).toArray());
					xmlEntry.value = IAMArrayFormat.ARRAY.format(mapping.value(i).toArray());
				}

			}
		}

		for (int index = 0; index < listingCount; index++) {
			final IAMListing listing = source.listing(index);

			final int itemCount = listing.itemCount();
			if (itemCount != 0) {
				final IAMLISTINGTYPE xmlListing = new IAMLISTINGTYPE();
				xmlIndex.mappingOrListing.add(xmlListing);
				xmlListing.index = Integer.toString(index);

				for (int i = 0; i < itemCount; i++) {
					final IAMITEMTYPE xmlItem = new IAMITEMTYPE();
					xmlListing.item.add(xmlItem);
					xmlItem.data = IAMArrayFormat.ARRAY.format(listing.item(i).toArray());
				}

			}
		}

		JAXB.marshal(xmlIndex, IO.outputWriterFrom(codec.getTargetData()));
	}