Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 3523

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>