Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(de)compressing files using NIO

Tags:

java

io

zip

nio

In the many examples online, files are (de)compressed in java using a coded buffer. With NIO, however, there is no need to choose a good buffer size. I found examples for files and sockets, but is there an NIO channel for compressed input (e.g. GZIPInputStream), so you can just use transferFrom in stead of creating the byte[] buffer yourself?

like image 693
tb189 Avatar asked Dec 03 '25 16:12

tb189


1 Answers

No, specialized ZIP channel does not exist yet... I think that you can do the following. Use NIO to read from any channel you want to Buffer. Then retrieve bytes you have just read from buffer to byte array, wrap the array using ByteArrayInputStream and pass it to ZIPInputStream.

like image 102
AlexR Avatar answered Dec 05 '25 06:12

AlexR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!