Skip to content

Instantly share code, notes, and snippets.

@jameskleeh
Last active July 20, 2017 15:27
Show Gist options
  • Save jameskleeh/05077c4c8552d8cb1663fbac9bc674f2 to your computer and use it in GitHub Desktop.
Save jameskleeh/05077c4c8552d8cb1663fbac9bc674f2 to your computer and use it in GitHub Desktop.
Grails write to response output stream safely
def outputStream = response.outputStream
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "filename=\"${name}\"")
try {
outputStream << <Your byte array here>
} catch (IOException e){
null
} finally {
if (outputStream != null){
try {
outputStream.close()
} catch (IOException e) {
null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment