public long WriteRecords(IEnumerable <KeyValuePair <InterKey, List <InterValue> > > sorted_pairs) { Stopwatch watch = new Stopwatch(); watch.Start(); long written_bytes = 0; foreach (var pair in sorted_pairs) { var record_bytes = IntermediateRecord <InterKey, InterValue> .GetIntermediateRecordBytes(pair.Key, pair.Value); foreach (var bytes in record_bytes) { fileStream.Write(bytes, 0, bytes.Length); written_bytes += bytes.Length; } } watch.Stop(); logger.Debug("Spilled {0} records summing to {2} bytes to disk in {1}.", StringFormatter.DigitGrouped(sorted_pairs.Count()), watch.Elapsed, StringFormatter.HumanReadablePostfixs(written_bytes)); //if (written_bytes > int.MaxValue) // throw new InvalidCastException("The intermediate file is very huge!"); return(written_bytes); }