I would like to perform repeated compression task for CPU profiling without doing any file I/O but strictly reading a byte stream. I want to do this in Java (target of my benchmark).
Does anyone have a suggestion how to do this?
I used Zip API that uses ZipEntry but ZipEntry triggers file I/O.
Any suggestions or code samples are highly appreciated.
I wouldn’t expect it to if you use a
ByteArrayOutputStreamas the underlying output:Likewise wrap your byte array for reading data from in a
ByteArrayInputStream.Of course,
ZipOutputStreamis appropriate if you want to create content using the zip compression format, which is good for (or at least handles 🙂 multiple files. For a single stream of data, you may want to useDeflaterOutputStreamorGZIPOutputStream, again using aByteArrayOutputStreamas the underlying output.