Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
5.1 EE SP4 (5.1.7), 5.2 EE SP2 (5.2.6)
-
All
Description
This improvement adds the utility class com.liferay.portal.kernel.util.StreamUtil for reading and writing output streams. This class will automatically do the following:
1) Ensures streams are closed after reading and writing to them.
2) Wraps the input stream with the proper BufferedInputStream (if it isn't already)
3) Wraps the output stream with the proper BufferedOutputStream (if it isn't already)
4) Use a proper buffer size
5) Ensures the BufferedInputStream, BufferedOutputStream and the while loop are all using the same buffer size
To use this class, you can call
StreamUtil.transfer(inputStream, outputStream)
or
StreamUtil.transfer(inputStream, outputStream, 8192)
where the third parameter is the buffer size. The default buffer size is 8192.
For portal installation which expect to have intensive I/O operations done, StreamUtil can be configured to use NIO. To enable this, set the following in system(-ext).proerpties:
com.liferay.portal.kernel.util.StreamUtil.use.nio=true
API CHANGES:
Class: com.liferay.util.servlet.ServletResponseUtil
Method: cleanUp(InputStream inputStream)
Status: Deprecated
New method: StreamUtil.cleanUp(inputStream)
Method: cleanUp(OutputStream outputStream)
Status: Deprecated
New method: StreamUtil.cleanUp(outputStream)
Method: cleanUp(OutputStream outputStream, InputStream inputStream)
Status: Deprecated
New method: StreamUtil.cleanUp(inputStream, outputStream)