Solved

zip multiple tar files --servlet

Posted on 2014-04-29
5
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

759 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