Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

zip multiple tar files --servlet

Posted on 2014-04-29
5
Medium Priority
?
282 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 36

Assisted Solution

by:mccarl
mccarl earned 400 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 1600 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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