java - Convert ZipOutputStream to FileInputStream -
i have code takes file, zip it, , stores in database
looks
// step 1 - create zip file byte[] buffer = new byte[1024];// 18024 zipoutputstream outzip = new zipoutputstream(new fileoutputstream("file.zip")); outzip.setlevel(deflater.default_compression); fileinputstream in = new fileinputstream(c:\file.hex); outzip.putnextentry(new zipentry("file.hex")); int len; while (( len = in.read(buffer)) > 0) outzip.write(buffer, 0, len); outzip.closeentry(); in.close(); outzip.close(); // step 2 - insert zip file db file = new file("file.zip"); fileinputstream fis = new fileinputstream( file ); the fis object store in db
but avoid filesystem , , not create file.zip. think need convert zipoutputstream fileinputstream directly not find way it.
is there easy way accomplish ?
- i have same problem when extract file, in order read must create 2 different temporary files - file.zip , file.hex
you not have create fileoutputstream @ all. use bytearrayoutputstream instead:
bytearrayoutputstream zipbytes = new bytearrayoutputstream() zipoutputstream outzip = new zipoutputstream(zipbytes); // run code adds zip entries.... zipbytes.getbytes() // returns array of bytes contain zipped information.
Comments
Post a Comment