Last active
July 20, 2017 15:27
-
-
Save jameskleeh/05077c4c8552d8cb1663fbac9bc674f2 to your computer and use it in GitHub Desktop.
Grails write to response output stream safely
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
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