Using unzip from unix in java-code ...

Hi people,
i have problem, i want to use the command unzip from unix, to unzip a zip-file, the commend unzip must invoke from java-code. Can someone help me. I use the zip-api, but i have 100Mb zip-file, it needs very long time to unzip the zip-file.
thanks for your help ...

ok, not sure how much improvement this will give in general, but its given a reliable 25% speed increase on my mini tests
using the nio libraries will also get you a lot further, and is the way to go if you are very keen on speed
asjf
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.swing.*;
public class Unzipper {
     private Unzipper() {}
     private static byte[] buffer = new byte[16384];
     public static void unzip(File file, Component parentComponent,     File outputDir) throws ZipException, IOException {
          unzip(new ZipFile(file), parentComponent, outputDir);
     public static void unzip(File file, int mode, Component parentComponent, File outputDir) throws IOException {
          unzip(new ZipFile(file, mode), parentComponent, outputDir);
     public static void unzip(String name, Component parentComponent, File outputDir)     throws IOException {
          unzip(new ZipFile(name), parentComponent, outputDir);
     public static void unzip(ZipFile zip, Component parentComponent, File outputDir)     throws IOException {
          if ( zip == null) {
               throw new NullPointerException("outputDir is null");
          int size = zip.size();
          if (size > 0) {
               if (outputDir == null) {
                    throw new NullPointerException("outputDir is null");
               if (!outputDir.exists()) {
                    outputDir.mkdirs();
               ProgressMonitor monitor =
               new ProgressMonitor(parentComponent,
               "Unpacking " + zip.getName() + "...", "", 0, size);
               monitor.setMillisToDecideToPopup(0);
               monitor.setMillisToPopup(0);
               Enumeration entries = zip.entries();
               for ( int i = 0; entries.hasMoreElements(); ) {
                    ZipEntry entry = (ZipEntry) entries.nextElement();
                    /*if (entry.getMethod() == ZipEntry.DEFLATED)
                    System.out.println(" Inflating: "+entry.getName());
                    else
                    System.out.println(" Extracting: "+entry.getName());*/
                    monitor.setNote(entry.getName());
                    File File = new File(outputDir, entry.getName());
                    File.getParentFile().mkdirs();
                    if (!entry.isDirectory()) {
                         InputStream in = null;
                         OutputStream out = null;
                         try {
                              in = zip.getInputStream(entry);
                              out = new FileOutputStream(File);
                              for (int n = 0; (n = in.read(buffer)) > -1; )
                                   out.write(buffer, 0, n);
                              monitor.setProgress(++i);
                         } finally {
                              if (out != null) {
                                   try {
                                        out.close();
                                   } catch (IOException e) {
     public static void main(String[] args) throws ZipException, IOException
          if (args.length !=2) {
               System.err.println("Usage: java Unzipper <zip file> <output dir>");
               System.exit(1);
          long start = -System.currentTimeMillis();
          unzip(args[0], null, new File(args[1]));
          System.out.println(start+System.currentTimeMillis());
          System.exit(0);

Similar Messages

  • Invoke the command unzip from unix in java-code ...

    Hi people,
    i have problem, i want to use the command unzip from unix, to unzip a zip-file, the commend unzip must invoke from java-code. Can someone help me. I use the zip-api, but i have 100Mb zip-file, it needs very long time to unzip the zip-file.
    thanks for your help ...

    use Runtime.exec() to call your unix "unzip" command from java, if its much faster.

  • Get parameter from URL in Java code

    Hello everyone,
    I've got strange problem. I have one JSF page with two controls:
    - InputText
    - Button
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <af:document title="view12.jsf" id="d1">
    <af:messages id="m1"/>
    <af:form id="f1">
    <af:inputText label="Label 1" id="it98" value="#{param.test}" editable="always"/>
    <af:commandButton actionListener="#{bindings.przekierowanie.execute}" text="przekierowanie"
    disabled="#{!bindings.przekierowanie.enabled}" id="cb1"/>
    </af:form>
    </af:document>
    </f:view>
    And I want to initialize the InputText with parameter from URL (param name is test - value="#{param.test}"). In JSF page everything is fine. But after clicking button I have to read the value from InputText in Java Code, so I have URL:
    http://127.0.0.1:7101/Application6-ViewController-context-root/faces/view12.jsf?test=asd
    and my Java code which is executed after clicking button is:
    public String przekierowanie() {
    Map <String,String> map=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String tttValue=map.get("test");
    System.err.println("test:" + tttValue);
         return null;
    but this doesn't work... Everytime I get null when I click the button. Could you tell me why and How to obtain this value, from InputTex in my java function?

    Hi,
    If you have a parameter in URL named as "product", you can get its value like:
    import javax.faces.context.FacesContext;
    import javax.servlet.http.HttpServletRequest;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpServletRequest httpRequest =
    (HttpServletRequest)facesContext.getExternalContext().getRequest();
    String product = httpRequest.getParameter("product");

  • Preventing JAXB xjc from re-generating java code of import ed schemas...

    Hi, I am using XJC to generate java code from xsd.
    However the xsd I run it on often has imports to another xsd that will be in a jar along with its java classes already existing.
    This jar is on the calsspath too.
    XJC however not only generates java code for existing xsd, but also for every import it has.
    And also for every import each of those imported xsd's might have.
    So if it were a long import chain A->B->C->D it generates code for all.
    How can i get it to generate code for only A and assume all the remaing code can be found on the jars in the classpath.
    The A.xsd also has a catalog file associated with it that has every namespace reference pointing to the correct xsd locations within jars.
    So it even has B->C mapping and C->D mapping. This was needed or else XJC didnt even generate anything at all and complained it could not reach C from B and so on.
    Catalog file solved that problem but not the fact that it keeps regnerating code.
    Thanks
    Edited by: Priyajeet on Dec 9, 2008 1:36 PM

    Problem solved.
    The xjc compiler reads file name in a case-sensitive fashion, even on windows.
    So, common.xsd and Common.xsd are seen as two distinct files.
    This was the cause of the compilation errors, since feature1 imported the schema using the filename Common.xsd, whereas the other schemas imported common using common.xsd
    I hope this could help.
    Salvatore

  • How to use .properties files in Webdynpro Java code?

    Hi all,
      I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but  I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
    Thans and Best regards
    Deyang

    Hi,
    1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
    2) load property:
         final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
         final Properties properties = new Properties();
         try
              properties.load(is);
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    Regatds Maxim R.

  • BPM 10.3 Studio how to use PAPI from stand alone java client

    Would you help me ...., the search for the relevant information in this forum or documentation has not helped!
    I'm running the BPM process via studio and trying to call it from the standalone java program.(According documentation
    I need ... fuegopapi-client.jar and directory.xml )
    Well, of course I could find somewhere directory.xml but it is not the right one .. What are the values(related to directory Service) which are needed to run this
    java code agains the process started from the studio... ? So what I should do...? to setup and configure in BPM10.3 Studio to be able to run this code agains the
    BPM process ...?
    thanks a lot
    Tomas
    ..otherwise the java code look like this ...
    public static void main(String[] args) {
    /////////////////// API Initialization ///////////////////
    Properties configuration = new Properties();
    configuration.setProperty(ProcessService.DIRECTORY_ID, "default");
    configuration.setProperty(ProcessService.DIRECTORY_PROPERTIES_FILE, "directory.xml");
    configuration.setProperty(ProcessService.WORKING_FOLDER, "c:\tmp");
    try {
    ProcessService processService = ProcessService.create(configuration);
    /////////////////// Establish a session ///////////////////
    ProcessServiceSession session = processService.createSession("test", "test", "localhost");
    /////////////////// Operate with PAPI ///////////////////
    for (String processId : session.processesGetIds()) {
    System.out.println("\n Process: " + processId);
    for (InstanceInfo instance : session.processGetInstances(processId)) {
    System.out.println(" -> " + instance.getId());
    /////////////////// Close the session ///////////////////
    session.close();
    /////////////////// Release API Resources ///////////////////
    processService.close();
    } catch (CommunicationException e) {
    System.out.println("Could not connect to Directory Service");
    e.printStackTrace();
    } catch (OperationException e) {
    System.out.println("Could not perform the requested operation");
    e.printStackTrace();
    }

    Would you help me ...., the search for the relevant information in this forum or documentation has not helped!
    I'm running the BPM process via studio and trying to call it from the standalone java program.(According documentation
    I need ... fuegopapi-client.jar and directory.xml )
    Well, of course I could find somewhere directory.xml but it is not the right one .. What are the values(related to directory Service) which are needed to run this
    java code agains the process started from the studio... ? So what I should do...? to setup and configure in BPM10.3 Studio to be able to run this code agains the
    BPM process ...?
    thanks a lot
    Tomas
    ..otherwise the java code look like this ...
    public static void main(String[] args) {
    /////////////////// API Initialization ///////////////////
    Properties configuration = new Properties();
    configuration.setProperty(ProcessService.DIRECTORY_ID, "default");
    configuration.setProperty(ProcessService.DIRECTORY_PROPERTIES_FILE, "directory.xml");
    configuration.setProperty(ProcessService.WORKING_FOLDER, "c:\tmp");
    try {
    ProcessService processService = ProcessService.create(configuration);
    /////////////////// Establish a session ///////////////////
    ProcessServiceSession session = processService.createSession("test", "test", "localhost");
    /////////////////// Operate with PAPI ///////////////////
    for (String processId : session.processesGetIds()) {
    System.out.println("\n Process: " + processId);
    for (InstanceInfo instance : session.processGetInstances(processId)) {
    System.out.println(" -> " + instance.getId());
    /////////////////// Close the session ///////////////////
    session.close();
    /////////////////// Release API Resources ///////////////////
    processService.close();
    } catch (CommunicationException e) {
    System.out.println("Could not connect to Directory Service");
    e.printStackTrace();
    } catch (OperationException e) {
    System.out.println("Could not perform the requested operation");
    e.printStackTrace();
    }

  • Should I use Process/Mapper or Pure Java Code for XI Adapter?

    Hi Friends,
    I'm developing a XI Adapter which including sending http request and also data transform, I prefer to implement all the functions by Java Code.
    But In NetWeaver XI Server, I find there are tools for creating process and mappers, they also can implement the same functions as Java Code.
    So what's your consideration on implementing a function by process or Java code?
    Thanks in advance.
    Best Regards,
    Jason

    Hello Jason.
    It is a huge job to create your on adapter and I would recommend you to use the default installed adapters whenever possible. Included in the default installed adapters are to name a few; HTTP, FTP, File, SOAP, RFC and IDOC.
    Which kind of messages are you transferring with XI? If it's simple XML structures I would recommend you to use Graphical Message Mappings or XSL. If your structures are a bit more complex or if your are transferring byte-structure files I would recommend you to use Java Mappings.
    Best Regards,
    Jacob

  • What are the simple to use COM library in your java code

    Hi,
    what are the simple to use COM library in your java code

    PhHein wrote:
    [javax/comm|http://java.sun.com/products/javacomm/reference/api/javax/comm/package-summary.html]
    No, he wants to use Windows COM objects!
    @OP
    It's not easy. You can try j-integra or ezjcom, which I tried years ago and was not too happy, but maybe
    they improved or they are just fine for your needs. $$$ involved!
    If you want to do it by yourself, it won't be easy at all, I promise, but it can be done with JNI or JNA.
    If your interactions are very few and simple, maybe some workarounds could be found.

  • Printing a password protected PDF file using acroread from Unix?

    We installed v8.1.3 acroread on the server but we are unable to print a password protected PDF file from command line in Unix? <br /><br />cat  <passprotected>.PDF | /usr/bin/acroread -toPostScript | lp -dprinter<br /><br />we get the following error<br /><br />"lp: Error - stdin is empty, so no job has been sent."<br /><br />Please advice <br /><br />Thank you in advance.<br />MSUDHAN.

    Hello,<br /><br />If the pdf file has a doc open password or if printing is disallowed you will not be able to print it using the commandline.<br /><br />Any other pdf can be printed using the same command :<br />cat a.pdf | acroread -toPostScript | lp -d <printer><br /><br />Regards,<br /> Rishi

  • Instantiating COM objects from within the java code in WLS

    is there a way to use COM objects from servlets or ejb's,
    with JVM, not with JView.
    thanks,
    ali.

    Sun has released a beta product - its a COM bridge that you can use
    to connect a Java2 JVM to a COM object with. I havent tried it yet
    but I probably will soon.
    Brad
    "Michael Girdley" <[email protected]> wrote in message news:39b86deb$[email protected]..
    >
    >
    No, at the current time we only support COM integration when using the
    Microsoft JVM. The Jintegra product from Linar is good.
    Thanks,
    Michael
    Michael Girdley
    BEA Systems Inc
    "Ali Ozgun" <[email protected]> wrote in message
    news:[email protected]..
    is there a way to use COM objects from servlets or ejb's,
    with JVM, not with JView.
    thanks,
    ali.

  • Using c files in a java code

    i have a c util which i need to use in a java application do anyone has a clue?

    check out the spec for JNI (java native interface)
    You may save time tho just re-implementing in java

  • Dynamic navigation from inside the java code within the project

    I want to create dynamic navigation in my project.
    On my first page I need to get to a second servlet page by the use of dynamic coding. In normal servlets I would use response.redirect() but I cant here in the creator world and I am stuck on this point.
    Any ideas or directions on how to proceed?
    I know how to use the navigation XML file and know how to modify the file in question.

    Well I sort of worked out what had to be done, and the references that everyone gave me was amazing and I am thankful...
    The JNI does anyone have JNI experience???
    Has anyone got the JNI functionally working within this IDE??

  • Java code to connect to unix box(putty)

    i'm having a great problem regarding accessing the putty box from java code.
    I need to read some log files from unix through java code.In my client program when i'm giving hostname and port=22...ssh terminal is getting detected,but i'm confused how to open that unix box by giving the username and password.and how am i goin to embed unix command in it.The entire job i've to do through java code.
    please help!!..Thanks
    Message was edited by:
    liz310
    Message was edited by:
    liz310

    thanks a lot guys for ur time...but i tried in every way..i'm getting hell lot of errors..please help..its really urgent
    /*this is my code:*/
    import com.jcraft.jsch.*;
    import com.jcraft.jsch.Channel;
    import com.jcraft.jsch.JSch;
    import com.jcraft.jsch.JSchException;
    import com.jcraft.jsch.Session;
    import com.jcraft.jsch.UserInfo;
    import java.io.*;
    public class shell_test {
    public static void main(String args[])
    String user="user15";
    String host="punlin040";
    String cmd="ls -l";
    JSch jsch = new JSch();
    try{
    Session session=jsch.getSession(user,host,22);
    session.setPassword("user15");
    //UserInfo usrInfo=new MyUserInfo();
    //session.setUserInfo(usrInfo);
    session.connect();
    Channel channel=session.openChannel("exec");
    ((ChannelExec) channel).setCommand(cmd);
    channel.setXForwarding(true);
    channel.connect();
    //code
    channel.setInputStream(System.in);
    // channel.setOutputStream(System.out);
    //((ChannelExec) channel).setErrStream(System.err);
    InputStream in = channel.getInputStream();
    channel.connect();
    byte[] tmp = new byte[1024];
    while (true)
    while (in.available() > 0)
    int i = in.read(tmp, 0, 1024);
    if (i < 0)
    break;
    System.out.print(new String(tmp, 0, i));
    if (channel.isClosed())
    in.close();
    // System.out.println("JSCH: exit-status: " +
    //channel.getExitStatus());
    break;
    try
    Thread.sleep(1000);
    catch (Exception ee)
    channel.disconnect();
    session.disconnect();
    //code
    //ch.setInputStream(System.in);
    //ch.setOutputStream(System.out);
    }catch(Exception e)
    {e.printStackTrace(); }
    /*public static class MyUserInfo implements UserInfo {
    public String getPassword()
    { return "password"; }
    public String getPassphrase()
    { return ""; }
    public boolean promptPassword(String arg0)
    { return true; }
    public boolean promptPassphrase(String arg0)
    { return true; }
    public boolean promptYesNo(String arg0)
    { return true; }
    public void showMessage(String arg0)
    but i'm getting following errors:
    com.jcraft.jsch.JSchException: java.lang.ClassNotFoundException: com.jcraft.jsch
    .jce.Random
    at com.jcraft.jsch.Session.connect(Session.java:160)
    at com.jcraft.jsch.Session.connect(Session.java:145)
    at shell_test.main(shell_test.java:25)
    Caused by: java.lang.ClassNotFoundException: com.jcraft.jsch.jce.Random
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.jcraft.jsch.Session.connect(Session.java:156)
    ... 2 more

  • Can we set a variable used inside the template from the java code.

    Hi everybody,
    I am uploading template,sub template and data xml fle to generate the preview using XDO API's. My main template is calling a sub template so it needs to import the sub template in the main template.since i am uploading my files on a particular server,my subtemplates has been put on different path as specified in the main template.
    so i need to change the subtemplate path dynamically at run time.
    is there any way i can pass this information to my main template at run time.
    one solution could be,my rtf template has a variable 'i' inside it,which is setting the file path to include my subtemplate like this :
    <?xdoxslt:set_variable($_XDOCTX, i ,"import:file:///c:/Temp/htmlmarkup.xsl")?>
    <?xdoxslt:get_variable($_XDOCTX, i )?>
    now is there any way i can set this variable at run time from my external java code.?
    Thanks,
    Anuradha

    Thanks for the response.
    but i still am looking for the solution.
    if both my template and subtemplate are in the same directory then atleast
    <?import:file:../htmlmarkup.xsl?> should work.
    but its not working...i m getting following error:
    FOProcessor setData: C:\subtemplates\projects.xml
    FOProcessor setLocale: en-us
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(XSLT10gR1.java:514)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(XSLT10gR1.java:192)
         at oracle.apps.xdo.common.xml.XSLTWrapper.transform(XSLTWrapper.java:156)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:916)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:869)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:204)
         at oracle.apps.xdo.template.FOProcessor.createFO(FOProcessor.java:1535)
         at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:925)
         at RTF2PDF.runRTFto(RTF2PDF.java:590)
         at RTF2PDF.runXDO(RTF2PDF.java:443)
         at RTF2PDF.main(RTF2PDF.java:237)
    Caused by: java.io.FileNotFoundException: C:\Documents and Settings\fusion\htmlmarkup.xsl (The system cannot find the file specified)
         at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:782)
         at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:564)
         ... 15 more
    please suggest me what to do..

  • Some java code returns a null resultset from 10.2.0.1 DB, but works w/ 9.2

    I am a Java noob guys, but we have java code the calls an Oracle Function. This code is unchanged from what successfully runs against an Oracle 9.2 database returning, in this case, one row from the database. A ref cursor is used. When the same Java code calls the same ref cursor function from a 10.2.0.1 database, a null resultset occurs. The function correctly returns a single row when executed by the same database user via sql-plus. So it must be a java thing. Does the jdbc driver need to be upgraded to correctly run against a 10.2 database? And is this null resultset type of anomaly a potential result of having a wrong version of ojdbc14.jar? Nothing else has changed except pointing the code to the same package and tables in a 10.2 database.
    Thanks in advance for your comments.
    Phil McDermott

    I realize now that this is the wrong forum to post in, but I was linked here from a google search on the issue.
    I downloaded the 10.2.0.1 ojdbc14.jar from oracle, but the problem persists.
    yeesh! now what?

Maybe you are looking for

  • Flex application not working when deployed run from Server

    Hi, I have Flex application which takes a parameter from user, makes a web-service call and returns the message. This application is running perfectly when I launch from IDE. But when I copy the files from bin-release to server and launch it, it give

  • Input tax

    can any body tell how to take input tax in f-43 posting diffrence between input tax and purchase tax do they same if so can create account called inventory rammaterial account and assign the input tax code created in FTXP code with respective acount

  • DAQ write+read analog channels

    Hi, I need some urgent help to solve a simple problem: My job is to write an analog channel to a DAQ device and then to read two analog channels from the same device. These should be done at the 5 KHz rate. For smaller rates I can do it using normal

  • WAR files on managed servers

    I have a question about placing new war files in production. First, why does WebLogic recommend AGAINST using auto-deploy in production? Is it for security or stability and what are those arguements? Second, do I need to move the actual war file to t

  • Opening default Browser from embedded Flash

    The Situation is this: I have a running flash application myapp.swf (Actionscript 2), which runs on a server and requires a parameter ( http://myserver.com/myapp.swf?myparam=value). I now want to create an AIR Wrapper for this application. So I embed