Created
July 10, 2019 21:24
-
-
Save auryn31/b0d0c13867462c03d43f695dfc6bcbc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class CSVStreamResponseOutput : StreamingResponseBody { | |
var dataProvider: DataProvider | |
constructor(dataProvider: DataProvider) { | |
this.dataProvider = dataProvider | |
} | |
/** | |
* writes every line from the dataprovider to the output | |
*/ | |
override fun writeTo(os: OutputStream) { | |
val writer = BufferedWriter(OutputStreamWriter(os)) | |
val countDownLatch = CountDownLatch(1) | |
dataProvider.getDataStream().subscribe({ | |
writer.write(it) | |
writer.write("\n") | |
writer.flush() | |
}, ::println, { | |
os.close() | |
countDownLatch.countDown() | |
}) | |
countDownLatch.await() | |
writer.flush() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment