Skip to Content
Author's profile photo Raghu Vamseedhar Reddy Kadipi Reddy

Preserve file names of input Zip file – using Java Mapping.

Requirement: –

Input Zip file has Order123.txt and Order123.JPG files in it i.e. combination of text(csv, xml) and binary(image, pdf) files. Input Zip file should be unzipped and file names should be preserved i.e., output folder should have Order123.txt (with or without transformation) and Order123.JPN.

Solution: –


Design: –

Create dummy Data Type, Message Type and Outbound/Inbound Service Interfaces.



Parametrized Java Mapping: –

public class UnZipParticularFile extends AbstractTransformation { 
    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { 
        try { 
   inputstream = transformationInput.getInputPayload().getInputStream(); 
   outputstream = transformationOutput.getOutputPayload().getOutputStream(); 
            String fileNameP = transformationInput.getInputParameters().getString("FileNameP"); // Get Parameter. 
            // A. Unzip and write required file to output. 
   zis = new; 
            while ((ze = zis.getNextEntry()) != null) {
                //You can use String class methods like endsWith, toLowerCase, contains, matches. Update entry in Interface Determination of ICO accordingly.
                if (ze.getName().matches(fileNameP)) { //ze.getName() is File Name. 
                    int len; 
                    byte b[] = new byte[2048]; 
                    while ((len =, 0, 2048)) != -1) { 
                        outputstream.write(b, 0, len); 
            // B. Set target File Name and Folder. 
            java.util.Map mapParameters = transformationInput.getInputHeader().getAll(); 
            mapParameters.put(DynamicConfigurationKey.create("", StreamTransformationConstants.DYNAMIC_CONFIGURATION), ""); 
            DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); 
            conf.put(DynamicConfigurationKey.create("", "FileName"), ze.getName()); //ze.getName() is File Name. You can add Date prefix or some-other string according to requirement. 
            conf.put(DynamicConfigurationKey.create("", "Directory"), "/usr/sap/interfaces/MWS/out");  //You can have different fixed folder or dynamic folder according to requirement.
        } catch (Exception exception) { 
            throw new StreamTransformationException(exception.toString()); 

Configuration: –

Remove SWCV as input is binary file (Zip file).



If transformation is required for text file, create new Operational Mapping and add Message Map after Java Map.


Result: –

Input Zip file is unzipped and output file names are same as input file names.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      Hi Raghu

      Just a suggestion for enhancement.

      I think the matches() method is case sensitive. You might want to consider translating both the actual filename and the parameter value to the same upper/lower case (using temp variables) to compare.


      Eng Swee

      Author's profile photo Raghu Vamseedhar Reddy Kadipi Reddy
      Raghu Vamseedhar Reddy Kadipi Reddy
      Blog Post Author


      Thank you for suggestion. I have added comment in code about using other methods of String class.

      @ Readers,

      boolean matches(String regex), method of String class takes regular expression as an input. This is the reason for .*txt (not *.txt), period matches a characters.

      Author's profile photo Former Member
      Former Member

      Hi Raghu,

      conf.put(DynamicConfigurationKey.create("", "Directory"), "/usr/sap/interfaces/MWS/out"); //You can have different fixed folder or dynamic folder according to requirement.

      You said that we can have diferent fixed folder for this scenario.

      Can you please say the command for that one.

      Thanks & Regards,


      Author's profile photo Shawn Tan
      Shawn Tan

      Hi Raghu,

      I've tried your code but it seems like it is not working if i have 2 xml files in the same zipped folder. Somehow i only get only 1 output file after it was unzip. Can you please help me as i have the similar requirement? Thanks.