Solved

zip multiple tar files --servlet

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Loop 6 61
servlet example 11 40
tomcat startup error 5 64
Glassfish admin console not working 1 12
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

773 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