Solved

zip multiple tar files --servlet

Posted on 2014-04-29
5
251 Views
Last Modified: 2014-05-07
Hello,
  I have web application that should allow user to download 1 or more files. The files are in tar format . How do I combine/zip all the tars file using java/java servlets

ex.
file1.tar
file2.tar
file 3.tar
and the user select file1.tar and file2.tar

master.gz
  -- this file contain file1.tar and file2.tar

Thanks for your help
0
Comment
Question by:SiemensSEN
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 100 total points
ID: 40031310
How do I combine/zip all the tars file using java/java servlets
You mention that the result should be "master.gz" which sort of implies that that result should be a gzipped tar of the selected files. Are you constrained that the result should use tar? Unfortunately, Java doesn't have in-built functionality for creating 'tar' files (it does have the 'gzip' functionality but not the 'tar'). However it does have the ability to create 'zip' files like native Windows zip files (and most *nix systems have utilities to work on zip files too), so if using zip files is a possibility then let me know and I can give you some code to do that.

Note that from what I can tell that you want, the fact that the input files a 'tar' format makes no difference, you can put any type of file into the resulting 'zip' file.

But if you are forced to needing to produce 'tar' files (or the above assumption is incorrect and you actually need to break open the input 'tar' files and somehow merge all the contents together) then you will need to look into 3rd party libraries that work with the tar format, eg.

http://commons.apache.org/proper/commons-compress/
https://code.google.com/p/jtar/

(I haven't used either so I can't comment personally on which might be more suitable, etc)
0
 

Author Comment

by:SiemensSEN
ID: 40031672
Thanks,
  my mistake...  I need to create an archive file and it could be  in zip format. the zip master file should contain all the selected tar files.

Thanks
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 40031784
A quick and dirty could be

public class TarCat {
    public static void main(String[] args) {
	String[] argv = { "-cvfM" , "tars.zip", "sendy-plus-mine.tar", "sendy-ddl.tar" };
	sun.tools.jar.Main.main(argv);
    }
}

Open in new window

0
 

Author Comment

by:SiemensSEN
ID: 40047720
Thanks,
  I used the java zip package.

java.util.zip.ZipEntry;
java.util.zip.ZipOutputStream;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40048013
Probably better ;)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now