ABAP- JAVA : How to unzip a zip file sent by ABAP

Hello,
We are using JCO to exchange the XML strings (File Sizes can range upto couple of MBs) between ABAP and JAVA. We were earlier using a STRING parameter for XML data exchange. This approach was resulting in huge performance overheads. As per our initial performance investigations, we have identified that time taken for XML exchange using JCO is the major bottlenecks.
Currently we are evaluating Zip - Exchange - Unzip mechanism for XML exchange.
We now try to ZIP the export content using following ABAP code:
      TRY.
          CALL METHOD cl_abap_gzip=>compress_text
            EXPORTING
              text_in  = lv_xmlstring
            IMPORTING
              gzip_out = ev_xmlstring.
This returns an XSTRING (zipped) which is lesser in size as compared to the earlier xml STRING.For zipping the XML String this code works fine. But on java end on using the following code (for unzipping):
public static String unzipStringFromBytes( byte[] bytes ) throws IOException
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    BufferedInputStream bufis = new BufferedInputStream(new InflaterInputStream(bis));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int len;
    while( (len = bufis.read(buf)) > 0 )
      bos.write(buf, 0, len);
    String retval = bos.toString();
    bis.close();
    bufis.close();
    bos.close();
    return retval;
We get the following error:
java.util.zip.DataFormatException: unknown compression method
     at java.util.zip.Inflater.inflateBytes(Native Method)
     at java.util.zip.Inflater.inflate(Inflater.java:215)
Please share java code snippet which we can use in our program to retrieve our initial XML string.
Best Regards,
Aayush

Hi,
i took a sequence '0123456789' and gziped it with your ABAP code snipped.
Result is in HEX:
'33 30 34 32 36 31 35 33 B7 B0 04 00'
Than i took an good old gzip executable and gzipped a text file with the same sequence in compression mode 6(default of ABAP Method).
Result in HEX:
'1F 8B 08 08 BA B1 D1 45 00 0B 31 2E 74 78 74 00'
'33 30 34 32 36 31 35 33 B7 B0 04 00 C6 C7 84 A6'   <-- quiet similar with ABAP gzip data
'0A 00 00 00'
It seems that some gzip headers and trailers are missing from ABAP Processor's output, i don't know why, maybe it will help you to fake the file headers's to your data section: http://www.gzip.org/zlib/rfc-gzip.html
Other topic is your Exception: java.util.zip.Inflater.inflate(Inflater.java:215)
Inflater is used for ZLIB compressed files, try to pass your InputStream to an Object of [java.util.zip.GZIPInputStream] like:
http://www.galileocomputing.de/openbook/javainsel6/javainsel_12_010.htm [Listing 12.29]
Let me know if it works and have fun.....

Similar Messages

  • How to unzip and zip files

    I have a very large number of Karaoke music that plays on my windows pc but some will not play on my Mac. I think i need to unzip & re-zip them to play on my mac but i'm not sure exactly how to do this. any suggestions? Do I need a special program? running os x 10.9.3

    Zip files can be opened with the built in 'Archive Utility' application. Double click any zip file & it will try to unzip it.
    This application is tucked away inside /System/Library/CoreServices/Archive Utility.  If you want to set preferences for it you need to open the location in Finder by using the 'Go Menu > Go to Folder…', enter /System/Library/CoreServices/ for the path & then open the Archive Utility application and look in it's preferences.
    I expect that zipping & rezipping will not do anything useful for you. I suspect that the file format is the issue.
    Unzip some files & post what the Finders 'File > Get info' panel shows, take a screenshot of it with 'cmd+shift+4', then drag the crosshairs to select the area. it will appear on the Desktop for uploading here.
    You may need to find a compatible player or find a way to convert them if the Mac cannot play them.
    P.S. to zip a file(s) select the items & right click, select 'Compress x items' & you will get a zip archive - I don't think it will help you though

  • How to unzip a zip file within another zip file

    I've got code that successfully processes a file within a zip file.
    But now the zip file can also contain other zip files. How can I
    process a zip nested within a zip without actually extracting the
    files? It looks like I need a ZipFile object to be able to take
    advantage of the zip classes for reading zip entries. But the
    ZipFile methods want as an argument an actual file, as opposed
    to some object in memory. I can read the 'inner' zip file into a
    ZipInputStream object, but then how do I make that available for
    processing as a ZipFile? I've searched all over and cannot find
    anything anywhere that talks about working with nested zip files.
    Does anyone have any sample code that does this? Thanks!

    I have successfully done it.
    You cannot have the code - it is proprietary.
    However here are a few pointers:
    o Use ZipStreams rather than ZipFile.
    o ZipStream is just a filter on a stream, so you can have a zipstream open, read a ZipEntry, then ask for a substream for the stuff up to the next ZipEntry. Put a second ZipStream on that substream.
    o As I recall you have to watch out that your inner ZipStream does not do a close. (Everything will get closed.) Instead, there is another ZipStream method that will close without closing all the underlying streams.
    Hope this helps.

  • Unzip a zipped file?

    How can I unzip a zipped file with java ?

    I presume you've read the API of [url http://java.sun.com/j2se/1.4.1/docs/api/java/util/zip/ZipFile.html]ZipFile?

  • How to insert a ZIP file in the message body and display it as icons

    how to attach an ZIP file as an inline attachment. whether its possible in java mail.

    Stop asking the same thing over and over.
    Keep the discussion in your original thread.

  • How to store the zip file in oracle table?

    hi,
    How to store the zip file in oracle table ?
    is it possible to unzip and read the file ?
    Thanks
    Rangan S

    SQL> DESC BLOB_TABLE;
    Name Type Nullable Default Comments
    A INTEGER Y
    B BLOB Y
    SQL> INSERT INTO BLOB_TABLE VALUES(5,BLOB('MWDIR_TST','TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,BLOB('MWDIR_TST','TEST.ZIP'))
    ORA-00904: "BLOB": invalid identifier
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('MWDIR_TST','TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,('MWDIR_TST','TEST.ZIP'))
    ORA-00907: missing right parenthesis
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'))
    ORA-01465: invalid hex number
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'));

  • How to email a .zip file attachment from PC

    Hi,
    Please, let me know how to email a .zip file attachment from Presentation Server.
    Thanks,
    Madhuri.

    Hi,
    try fm SO_DOCUMENT_SEND_API1
    it's well documented (look with SE37)
    and look here:
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
    regards Andreas

  • Problem in unzipping the zip files

    Hi,
    I have created a program to unzip the zip files. But when i try to zip it is creating the zipped files outside the folder where it is to be zipped.
    what is wrong with my code.
    if the zip file is migration.zip
    if the path inside the zip file shows
    and the path inside says this
    /codebase/scripts/
    it would create migration folder and create codebase folder outside the migration folder
    what is wrong with my code
    //Unzip the zip files to the folder with their name
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FilenameFilter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    // Getting the path to find the type of files
    public class zipper implements FilenameFilter{
              String ext;
              public zipper(String ext)
                   this.ext="." + ext;
              public boolean accept(File dir,String name)
                   return name.endsWith(ext);
    public static void main(String args[]) throws IOException
              try
                        String dir = "D:/a/";
                        File f2 = new File(dir);
                        FilenameFilter fn= new zipper("zip");
                        String ss[]=f2.list(fn);
                   for ( int j = 0; j < ss.length; j++)
                        System.out.println(" Extracting ...." + ss[j]) ;
                        String zipFile = dir + ss[j];
                        ZipFile zf = new ZipFile(zipFile);
                        Enumeration entries = zf.entries();
                        String directoryName = zf.getName();
                        directoryName = directoryName.substring(0, (directoryName.indexOf(":" + File.separator) + 2));
                             String folderName = zf.getName();
                             folderName = folderName.substring(0, folderName.lastIndexOf("."));
                             File file1 = new File(folderName);
                             //File file1 = new File(entries.getName());
                             file1.mkdir();
                   while (entries.hasMoreElements())
                             ZipEntry ze = (ZipEntry) entries.nextElement();
                             String path = directoryName + ze.getName() ;
                             String path1 = folderName + ze.getName();
                             //System.out.println(" : " + path);
                             if (ze.getName().endsWith("/"))
                                       File file = new File(path);
                                       file.mkdir();
                                       continue;
                                       //break;
                        BufferedReader bReader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
         StringBuffer fileBuffer = new StringBuffer(" ");
         String line ;
                        while ((line = bReader.readLine()) != null)
                                  fileBuffer.append(line);
                                  fileBuffer.append("\r\n");
                                  //line = line + "\r\n";
                                  //byte[] b = new byte[line.length()];
                                  //b =line.getBytes();
                                  //out.write();
                        String fileData = fileBuffer.toString();
         File f1 = new File(path);
                        f1.createNewFile();
                        //FileOutputStream out = new FileOutputStream(folderName + "/" + ze.getName());
                        FileOutputStream out = new FileOutputStream(path);
                        long size = ze.getSize();
                        byte[] data1 = new byte[fileData.length()];
                        for (int i = 0; i < fileData.length(); i++)
                                  data1[i] = (byte) fileData.charAt(i);
         out.write(data1);
         out.close();
                        bReader.close();                         
                   } catch (Exception e)
                             e.printStackTrace();
    Thanks in Advance
    Avinash

    String path = directoryName + ze.getName();
    String path1 = folderName + File.separator+ ze.getName();
    File f1 = new File(path); // pass path1 instead of path
    f1.createNewFile();
    FileOutputStream out = new FileOutputStream(path); // pass path1 instead of path

  • Problem in Unzipping the zip file

    Hi
    I have created a program to unzip the zip files in the folder named after the zip file
    it is working well well when u try to zip zip files put in a directory
    i.e u create a folder name contents and put files into that and then zip it
    but when u directly create a zip file , without putting in a folder
    it creates the folder and zip the files outside the folder
    Another problem is that with the path
    for e.g. suppose the zip file name is contents and path should show
    contents/filename.txt but there are some other files whose path shows
    res/file.txt. In this case it creates a folder of res and put it outside the
    folder with the name of zip file
    I have pasted my code :
    //Unzip the zip files to the folder with their name
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FilenameFilter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    // Getting the path to find the type of files
    public class zipper implements FilenameFilter{
              String ext;
              public zipper(String ext)
                   this.ext="." + ext;
              public boolean accept(File dir,String name)
                   return name.endsWith(ext);
    public static void main(String args[]) throws IOException
              try
                        String dir = "D:/";
                        File f2 = new File(dir);
                        FilenameFilter fn= new zipper("zip");
                        String ss[]=f2.list(fn);
                   for ( int j = 0; j < ss.length; j++)
                        System.out.println(" Extracting ...." + ss[j]) ;
                        String zipFile = dir + ss[j];
                        ZipFile zf = new ZipFile(zipFile);
                        Enumeration entries = zf.entries();
                        String directoryName = zf.getName();
                        directoryName = directoryName.substring(0, (directoryName.indexOf(":" + File.separator) + 2));
                             String folderName = zf.getName();
                             folderName = folderName.substring(0, folderName.lastIndexOf("."));
                             File file1 = new File(folderName);
                             //File file1 = new File(entries.getName());
                             file1.mkdir();
                   while (entries.hasMoreElements())
                             ZipEntry ze = (ZipEntry) entries.nextElement();
                             String path = directoryName + ze.getName() ;
                             String path1 = folderName + ze.getName();
                             //System.out.println(" : " + path);
                             if (ze.getName().endsWith("/"))
                                       File file = new File(path);
                                       file.mkdir();
                                       continue;
                                       //break;
                        BufferedReader bReader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
         StringBuffer fileBuffer = new StringBuffer(" ");
         String line ;
                        while ((line = bReader.readLine()) != null)
                                  fileBuffer.append(line);
                                  fileBuffer.append("\r\n");
                                  //line = line + "\r\n";
                                  //byte[] b = new byte[line.length()];
                                  //b =line.getBytes();
                                  //out.write();
                        String fileData = fileBuffer.toString();
         File f1 = new File(path);
                        f1.createNewFile();
                        //FileOutputStream out = new FileOutputStream(folderName + "/" + ze.getName());
                        FileOutputStream out = new FileOutputStream(path);
                        long size = ze.getSize();
                        byte[] data1 = new byte[fileData.length()];
                        for (int i = 0; i < fileData.length(); i++)
                                  data1[i] = (byte) fileData.charAt(i);
         out.write(data1);
         out.close();
                        bReader.close();                         
                   } catch (Exception e)
                             e.printStackTrace();
    Thanks in Advance
    Avinash

    String path = directoryName + ze.getName();
    String path1 = folderName + File.separator+ ze.getName();
    File f1 = new File(path); // pass path1 instead of path
    f1.createNewFile();
    FileOutputStream out = new FileOutputStream(path); // pass path1 instead of path

  • Unzip a zip file

    Can someone help me for the following problem,
    Iam downloading a zip file from the server to the client.i want to unzip and execute the .EXE file, which is inside the zip file through the java coding.can any one help me!
    thanking you

    I think you can do all of this using the Java runtime interface which allows you to execute command line commands via Java code (ie, launching an EXE).
    See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    I don't believe there is a component of the Java API that allows you to unzip a zip file. But you could still accomplish this using the winzip command line support. See http://www.winzip.com/wzcline.htm in combination with the Java runtime.

  • Unzip a .zip file programatically??

    Hi all friends,
    I want to unzip a .zip file programatically.For that if any one can give me some code then it will be very help full for me.
    Thanks & Regards
    Bikash

    this thread has some code
    http://forum.java.sun.com/thread.jsp?forum=31&thread=417611
    asjf

  • How to open a zip-file in Bridge for PC?

    How to open a zip-file in Bridge for PC?

    I think it's built in, just double click on it and it should open with Archive Utility. I dunno, maybe Unrar X might work for you>
    JB

  • How to append to zip files

    I would like to know how to append to a zip file, I know how to write a zip file and I can put as many entries in the first time but if I run my program again and try to add a file to the same zip file it erases what was already in it. I use ZipOutputStream(new FileOutputStream), I have tried the FileOutputStream append but it does not seem to work for zip files, I have tried RandomAccessFile on my zip file but that just seems to add the bytes to the file that already in the zip file, and makes the file unopenable, corrupt. If you can help, please tell me how.

    You actually have to open the previous zipped file, read it's entries and their data and then rewrite a new zip file with these entries and their data. You can then delete your first file and rename the new one so the effect is that you have "appended" zip files to the existing archive.
    Here is an example which I pieced together from a larger bit of code that I have. This would need to be in a try/catch but this should give you a start.
    /** This method adds a new file to an existing zip file. It * includes all the zipped entries previously written.
    * @param file The old zip archive
    * @param filename The name of the file to be Added
    * @param data The data to go into the zipped file
    * NOTE: This method will write a new file and data to an archive, to
    * write an existing file, we must first read the data frm the file,
    * then you could call this method.
    public void addToArchive(File file, String filename, String data)
         ZipOutputStream zipOutput = null;
    ZipFile zipFile = null;
    Enumeration zippedFiles = null;
    ZipEntry currEntry = null;
    ZipEntry entry = null;
    zipFile = new ZipFile( file.getAbsolutePath() );
         //get an enumeration of all existing entries
    zippedFiles = zipFile.entries();
         //create your output zip file
    zipOutput = new ZipOutputStream( new FileOutputStream ( new File( "NEW" + file.getAbsolutePath() ) ) );
    //Get all the data out of the previously zipped files and write it to a new ZipEntry to go into a new file archive
    while (zippedFiles.hasMoreElements())
    //Retrieve entry of existing files
    currEntry = (ZipEntry)zippedFiles.nextElement();
    //Read data from existing file
    BufferedReader reader = new BufferedReader( new InputStreamReader( zipFile.getInputStream( currEntry ) ) );
    String currentLine = null;
    StringBuffer buffer = new StringBuffer();
    while( (currentLine = reader.readLine() ) != null )
    buffer.append( currentLine);
    //Commit the data
    zipOutput.putNextEntry(new ZipEntry(currEntry.getName()) ) ;
    zipOutput.write (buffer.toString().getBytes() );
    zipOutput.flush();
    zipOutput.closeEntry();
    //Close the old zip file
    zipFile.close();
    //Write the 'new' file to the archive, commit, and close
    entry = new ZipEntry( newFileEntryName );
    zipOutput.putNextEntry( entry );
    zipOutput.write( data.getBytes() );
    zipOutput.flush();
    zipOutput.closeEntry();
    zipOutput.close();
         //delete the old file and rename the new one
    File toBeDeleted = new File ( file.getAbsolutePath() );
    toBeDeleted.delete();
         File toBeRenamed = new File ( "NEW" + file.getAbsolutePath() );
    toBeRenamed.rename( file );
    Like I said I haven't tested this code as it is here but hopefully it can help. Good luck.

  • How do I open .cwk files sent to me on my iPad that contain graphics

    How do I open .cwk files sent to me on my iPad that contain graphics?

    No.
    Apple works was abandoned many years ago.

  • Unzip the Zip file in ABAP

    Hi
    I want to get the zip file having multiple .dat / .csv files from another server to application server.I want to unzip it and store the individual file to the folder.
    Could you please help me.
    Thanks in advance.
    Amit

    Hi Amit,
    Please check this thread.
    Re: UNZIP file from ABAP
    Hope this will help.
    Regards,
    Ferry Lianto
    Message was edited by: Ferry Lianto

Maybe you are looking for

  • Check list for upgrading from 10g to 11g when there is a schema replication

    Hi We are looking to upgrade one of our production database from 10g to 11g Currently this database has one schema that is replicated to 2 other databases using Oracle streams. The replication is excluing DDLs and excluding several other application

  • Changing measurements in page setup

    I don't know where else to inquire but, somehow my measurement of choice which had been inches has changed in my Photoshop print setup. It is now centimeters. I don't know how to change it. I'm using an Epson 14500 printer. Please help

  • Ipod Nano recall site redirects to a charger recall site is the recall over

    I just found my 1st gen nano and tried to sign in and after signing in it redirects to some page about a charger recall; has the recall ended or is there some type of mistake on the site.

  • [CS5][JSX] How to place a video from an URL

    Hey everyone, I found some great help in this forum in the past, so I hope someone can help me again this time. I'm using Indesign CS5 on a mac. I write in Javascript. What i try to do is dynamically placing a video from a URL. I thought I could do t

  • Can't find iBooks pre-order/purchases section?

    I thought I had pre-ordered a book through iBooks, but when I access my account to verify the pre-order, I don't see anything that will allow my to view my pre-orders.  It said to click on purchases, but I don't see anything titled purchases.  The on