try { Arrays.sort(this.ramRecords, 0, this.numRecordsInRam, this.comparator); final File f = newTempFile(); OutputStream os = null; try {
/** * Sort the records in memory, write them to a file, and clear the buffer of records in memory. */ public void spillToDisk() { try { Arrays.parallelSort(this.ramRecords, 0, this.numRecordsInRam, this.comparator); final Path f = newTempFile(); try (OutputStream os = tempStreamFactory.wrapTempOutputStream(Files.newOutputStream(f), Defaults.BUFFER_SIZE)) { this.codec.setOutputStream(os); for (int i = 0; i < this.numRecordsInRam; ++i) { this.codec.encode(ramRecords[i]); // Facilitate GC this.ramRecords[i] = null; } os.flush(); } catch (RuntimeIOException ex) { throw new RuntimeIOException("Problem writing temporary file " + f.toUri() + ". Try setting TMP_DIR to a file system with lots of space.", ex); } this.numRecordsInRam = 0; this.files.add(f); } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * Sort the records in memory, write them to a file, and clear the buffer of records in memory. */ public void spillToDisk() { try { Arrays.parallelSort(this.ramRecords, 0, this.numRecordsInRam, this.comparator); final Path f = newTempFile(); try (OutputStream os = tempStreamFactory.wrapTempOutputStream(Files.newOutputStream(f), Defaults.BUFFER_SIZE)) { this.codec.setOutputStream(os); for (int i = 0; i < this.numRecordsInRam; ++i) { this.codec.encode(ramRecords[i]); // Facilitate GC this.ramRecords[i] = null; } os.flush(); } catch (RuntimeIOException ex) { throw new RuntimeIOException("Problem writing temporary file " + f.toUri() + ". Try setting TMP_DIR to a file system with lots of space.", ex); } this.numRecordsInRam = 0; this.files.add(f); } catch (IOException e) { throw new RuntimeIOException(e); } }