Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Unzipping GZ files using Java Script

  1. #1

    Question Unzipping GZ files using Java Script

    All -

    I have used a Java Script transformation to successfuly unzip .zip files on Windows platform. However when I use the same Java Script to unzip .gz files, I received the error 'Error opening zip file'.

    As per Java documentation (java.util package), this code should support .gz format also. But it is not working as expected.

    Here's the piece of code that does the job for .zip files and fails for .gz files.

    var zf = new java.util.zip.ZipFile(filename.getString());
    throw(filename.getString());
    var zipEnum = zf.entries();
    var dir = new java.lang.String(".");
    var directoryname=new java.lang.String(dataHome.getString()+ "\\");
    dir = directoryname.replace('\\','/');
    if(dir.charAt(dir.length()-1) != '/')
    {
    dir += "/";
    }
    while( zipEnum.hasMoreElements())
    {
    var item = zipEnum.nextElement();
    if( item.isDirectory() ) //Directory
    {
    var newdir = File(dir + item.getName());
    newdir.mkdir();
    }
    else //File
    {
    var newfile = dir + item.getName();
    var is = zf.getInputStream(item)
    var fos = new java.io.FileOutputStream(newfile);
    var ch;
    while( (ch = is.read()) != -1 )
    { fos.write(ch); }
    is.close();
    fos.close(); } }
    zf.close();
    }

    I am running this code on Windows platform using Kettle 2.3.0. I do not want to create a shell script to do the job so as to avoid portability issues. I wish to use the Java Script code instead.

    Any help will be highly appreciated.

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    Does filename.getString() return the full path of the file? If not, that's your problem.

    Regards,
    Sven

  3. #3

    Default

    Looking at the log it doesn't seem to pass the filename. I am using 'Get Files' step to extract the filename. In the Java Script I am using filename.getString(). Is there any other way to ensure getting the filename? Please suggest.

    Here's the complete Kettle error log.


    Error log: 2007/09/20 08:08:04 - FTP_INFO - Start of FTP job entry
    2007/09/20 08:08:05 - FTP_INFO - Opened FTP connection to server [ftp.data.com]
    2007/09/20 08:08:05 - FTP_INFO - set Passive ftp connection mode
    2007/09/20 08:08:05 - FTP_INFO - set timeout to 0
    2007/09/20 08:08:05 - FTP_INFO - logged in using xxxx/yyyy
    2007/09/20 08:08:05 - FTP_INFO - Found 2 files in the remote ftp directory
    2007/09/20 08:08:05 - FTP_INFO - set binary transfer mode
    2007/09/20 08:08:05 - FTP_INFO - Getting file [loaddata070918.gz] to directory [c:\data]
    2007/09/20 08:08:05 - FTP - Starting entry [UNZIP_FILES]
    2007/09/20 08:08:05 - Thread[FTP (FTP (Thread-1)),5,main] - exec(3, 0, UNZIP_FILES.0)
    2007/09/20 08:08:05 - UNZIP_FILES - Opening filename : []
    2007/09/20 08:08:05 - UNZIP_FILES - Opening transformation: [UNZIP_FILES] in directory [/data_dir]
    2007/09/20 08:08:05 - UNZIP_FILES - Starting transformation...(file=, name=UNZIP_FILES), repinfo=null
    .............................................................

    2007/09/20 08:08:05 - Get System Info.0 - Signaling 'output done' to 1 output rowsets.
    2007/09/20 08:08:05 - Java Script Value.0 - Value #0 - [filename] is used in the script.
    2007/09/20 08:08:05 - Get System Info.0 - Finished processing (I=0, O=0, R=2, W=2, U=0, E=0
    2007/09/20 08:08:05 - Java Script Value.0 - Value #3 - [VX_NAME] is used in the script.
    2007/09/20 08:08:05 - Java Script Value.0 - This script is using 2 values from the input stream(s)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : Javascript error: org.mozilla.javascript.JavaScriptException: Error JavaException: java.util.zip.ZipException: error in opening zip file (script#43)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : Error stack trace:
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : org.mozilla.javascript.JavaScriptException: Error JavaException: java.util.zip.ZipException: error in opening zip file (script#43)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.gen.c1._c0(script:43)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.gen.c1.call(script)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.gen.c1.call(script)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at org.mozilla.javascript.gen.c1.exec(script)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.addValues(ScriptValues.java:153)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.processRow(ScriptValues.java:208)
    2007/09/20 08:08:06 - Java Script Value.0 - ERROR : at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.run(ScriptValues.java:243)
    2007/09/20 08:08:06 - Java Script Value.0 - Signaling 'output done' to 0 output rowsets.
    2007/09/20 08:08:06 - Java Script Value.0 - Finished processing (I=0, O=0, R=1, W=0, U=0, E=1

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    Try your transformation with a real .zip file... it works for me. Possibly you have either a corrupted .gz file or something else is going one (some kind of gzipping not support by Java e.g.)

    Regards,
    Sven

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.