public void reduce(Shard key, Iterator<IntermediateForm> values,
OutputCollector<Shard, IntermediateForm> output, Reporter reporter)
throws IOException {
String message = key.toString();
IntermediateForm form = null;
while (values.hasNext()) {
IntermediateForm singleDocForm = values.next();
long formSize = form == null ? 0 : form.totalSizeInBytes();
long singleDocFormSize = singleDocForm.totalSizeInBytes();
if (form != null && formSize + singleDocFormSize > maxSizeInBytes) {
closeForm(form, message);
output.collect(key, form);
form = null;