presto-hive/src/main/java/io/prestosql/plugin/hive/SortingFileWriter.java/SortingFileWriter/writeTempFile
class SortingFileWriter:    private void writeTempFile(Consumer<TempFileWriter> consumer)
    {
        Path tempFile = getTempFileName();

        try (TempFileWriter writer = new TempFileWriter(types, tempFileSinkFactory.createSink(fileSystem, tempFile))) {
            consumer.accept(writer);
            writer.close();
            tempFiles.add(new TempFile(tempFile, writer.getWrittenBytes()));
        }
        catch (IOException | UncheckedIOException e) {
            cleanupFile(tempFile);
            throw new PrestoException(HIVE_WRITER_DATA_ERROR, "Failed to write temporary file: " + tempFile, e);
        }
    }