Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

taking long time to process .txt file in java mapping.

Hi Experts,

I have a scenario where PI will pick the .txt file and send as an attachment to ECC through inbound proxy.

Here we have written a java code which is reading the file line by line. The actual file size is more that 13MB. Could you please suggest me any changes required in the below code to speed up the process in PI.

Java Code:

import java.io.InputStream;

import java.io.OutputStream;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.Attachment;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

import com.sap.aii.mapping.api.OutputAttachments;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class setAttachment extends AbstractTransformation

{

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException

  {

  InputStream inputstream = transformationInput.getInputPayload().getInputStream();

  OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

  DynamicConfiguration conf = transformationInput.getDynamicConfiguration();

  DynamicConfigurationKey key = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");

  String filename = "";

  filename = conf.get(key);

  conf.put(key,filename);

  try

  {

  String output = "";

  output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"<ns0:MT_receiver_ECC xmlns:ns0=\"http://www.varian.com/JABIL/inbound\">"+"<FileName>";

  output = output + filename;

  output = output + "</FileName>";

  output = output + "</ns0:MT_receiver_ECC>";

  outputstream.write(output.getBytes("UTF-8"));

  OutputAttachments outputAttachments = transformationOutput.getOutputAttachments();

  byte[] b = new byte[inputstream.available()];

  inputstream.read(b);

  String str = new String(b);

  String out = "";

  boolean text = true;

  while(text)

         {

          if(str.contains("</FileName>"))

          {

          int firstindex = str.indexOf("<FileName>");

                 int lastindex = str.indexOf("</FileName>");

                 out = out + "\n" + str.substring(firstindex+10, lastindex);

                 str = str.substring(lastindex+1);

          }

          else

          text = false;

         }

  byte[] bytes = out.getBytes("UTF-8");

  Attachment newAttachment = outputAttachments.create(filename,"text/plain",bytes);

  outputAttachments.setAttachment(newAttachment);

  }

  catch(Exception e)

  {

  getTrace().addDebugMessage(e.getMessage());

  }

  }

}

Thanks,

Gayathri.

Former Member
Former Member replied

Hi All,

I rectified the code.

Correct statement is below.

Attachment newAttachment = outputAttachments.create(fileName,"Application/xml",bytes);

Thanks,

Gayathri.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question