Solved

zip multiple tar files --servlet

Posted on 2014-04-29
5
255 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

914 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

23 Experts available now in Live!

Get 1:1 Help Now