package org.grouplens.lenskit.util.tablewriter;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.grouplens.lenskit.eval.util.table.TableImpl;

public class MultiplexedTableWriter implements TableWriter {

	private TableLayout layout;
	private List<TableWriter> writers;
	
	public MultiplexedTableWriter(TableLayout layout, List<TableWriter> writers) {
		this.layout = layout;
		this.writers = writers;
	}
	
	public MultiplexedTableWriter(TableLayout layout, TableWriter... writers) {
		this(layout, Arrays.asList(writers));
	}
		
	@Override
	public TableLayout getLayout() {
		return layout;
	}

	@Override
	public void writeRow(Object[] row) throws IOException {
		for (TableWriter w: writers) {
			w.writeRow(row);
		}

	}

	@Override
	public void close() throws IOException {
		for (TableWriter w : writers) {
			w.close();
		}
	}
}
@@ -92,17 +92,20 @@
 il.Array
-s
+List
 ;%0Aimport
@@ -119,22 +119,23 @@
 til.
-List;%0A
+Arrays;
 %0Aimport 
 org.
@@ -134,55 +134,22 @@
 ort 
-org.grouplens.lenskit.e
+ja
 va
-l
 .util.
-table.TableImpl
+List
 ;%0A%0Ap
@@ -789,51 +789,283 @@
 %7B%0A%09%09
-for (TableWriter w : writers) %7B%0A%09%09%09w.close(
+ArrayList%3CIOException%3E closeExceptions = new ArrayList%3CIOException%3E(writers.size());%0A%09%09for (TableWriter w : writers) %7B%0A%09%09%09try %7B%0A%09%09%09%09w.close();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09closeExceptions.add(e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if (!closeExceptions.isEmpty()) %7B%0A%09%09%09throw closeExceptions.get(0
 );%0A%09

Fix closing of multiplexed table writer to close all constituent table writers in presence of exceptions