javazip4j

zip4j, extract a password protected file from an inputstream (blob inputstream which is a zip file)


I have a database that contains blobs and a password protected zip inside this database, using the standard File object approach i traditionally see

        File zipFile = new File("C:\\file.zip");        
        net.lingala.zip4j.core.ZipFile table = new net.lingala.zip4j.core.ZipFile(zipFile);                    
        if (table.isEncrypted())
            table.setPassword(password);           

        net.lingala.zip4j.model.FileHeader entry = table.getFileHeader("file_inside_the_zip.txt");
        return table.getInputStream(entry); //Decrypted inputsteam!

my question is, how do i implement something like this without the use of temporary files, and purely obtaining an inputstream of the blob alone, so far i have something like this

InputStream zipStream = getFileFromDataBase("stuff.zip");
//This point forward I have to save zipStream as a temporary file and use the traditional code above

Solution

  • I believe it is not possible via zip4j as it is very centered around files.

    Have a look at this one: http://blog.alutam.com/2012/03/31/new-library-for-reading-and-writing-zip-files-in-java/