Category Archives: 7zip

Android: 7zip a folder using Apache Commons Compress

I have included the following in my .gradle:
compile 'org.apache.commons:commons-compress:1.8'

I want to 7zip a folder. I have tried

SevenZOutputFile sevenZOutput = new SevenZOutputFile(file);
SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(fileToArchive, name);
sevenZOutput.putArchiveEntry(entry);
sevenZOutput.write(contentOfEntry); //this is what I don't understand!!
sevenZOutput.closeArchiveEntry();

I require some help and assistance in accomplishing the above task.

Thanks.

Android: 7zip a folder using Apache Commons Compress

I have included the following in my .gradle:
compile 'org.apache.commons:commons-compress:1.8'

I want to 7zip a folder. I have tried

SevenZOutputFile sevenZOutput = new SevenZOutputFile(file);
SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(fileToArchive, name);
sevenZOutput.putArchiveEntry(entry);
sevenZOutput.write(contentOfEntry); //this is what I don't understand!!
sevenZOutput.closeArchiveEntry();

I require some help and assistance in accomplishing the above task.

Thanks.

How do we enable gzip compression on an Apache server and change default settings(explained)?

I've been reading about compressing our css, js, html etc. files before sending it to the client. A good compressor, and universally supported is gzip. So I'm trying to figure out how to enable it on my Apache server and change its default settings.
So far on the net I found only text to copy and paste in your .htaccess file to enable gzip compression. But I couldn't find anywhere the explanation of that code:

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

So I have a couple of questions about this and other gzip settings:

  1. can you explain what the lines of the above code do? Or is there another way to do so?(explained pls). I'd be grateful even for a link which explains this(which I couldn't find).
  2. do we got to do it in the .htaccess file or is there a config file in which we can set this?
  3. I heard about the factor of gzip compression which goes from 1 to 9 and is set by default to 6. How can we change it? And do we need to change it?
  4. I'd also like to send to the user the header file of my index.php file as soon as I receive the request w/o even looking at the request(using flush). I heard that if gzip is enabled this cannot be done. But nonetheless I see lots of modern websites who flush the header and at the same time use compression. How can I do that?
  5. I also heard that it's good to gzip static files like css and js offline using a better compressor like 7zip or zipfli. How can this be done and how do I then tell the server to pass these files as already compressed and not to bother compressing them?

I know this is quite a bit of questions, but I'm really confused right now about how to make it work and understand how it works. I'm not expecting from you to answer all the question but at least part of them, and please share helpful links where I can find good explanations.
Appreciate any help.

apache commons compress using 7zip

i am trying to use the below code that i got from apache commons compress examples webpage to create a zip file using the sevenZ classes hoping it would be faster to compress than regular java zip. this is what my code looks like

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream("c:/temp/test.txt"));

    SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("c:/temp/7ztest.zip"));
    SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(new File("c:/temp/test.txt"),"blah.txt");
    sevenZOutput.putArchiveEntry(entry);
    byte[] buffer = new byte[1024];
    int len;
    while ((len = instream.read(buffer)) > 0) {sevenZOutput.write(buffer, 0, len);}

    sevenZOutput.closeArchiveEntry();
    sevenZOutput.close();
    instream.close();
    }catch(IOException ioe) {
        System.out.println(ioe.toString());

    }
}

i get this error which looks so unrelated

Exception in thread "main" java.lang.NoClassDefFoundError: org.tukaani.xz.FilterOptions at java.lang.J9VMInternals.verifyImpl(Native Method) at java.lang.J9VMInternals.verify(J9VMInternals.java:93)

i have the apache packages imported

import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry; import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;

but not sure what the org.tukaani.xz.FilterOptions is, it doesnt look like it is part of the apace commons compress. Any thoughts?