Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9236

Re: Java map needed for text input file

$
0
0

Hi

 

Try this code. This will give you the desired output

 

package com.sap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class AddURIPrefix extends AbstractTransformation {  public void transform(TransformationInput arg0, TransformationOutput arg1)  throws StreamTransformationException {  this.execute(arg0.getInputPayload().getInputStream(), arg1  .getOutputPayload().getOutputStream());  }// end of transform  public void execute(InputStream in, OutputStream out)  throws StreamTransformationException {  try {  BufferedReader br = null;  try {  // read this file into InputStream     br = new BufferedReader(new InputStreamReader(in));  int count = 0;     StringBuilder sb = new StringBuilder();     String line;  while ((line = br.readLine()) != null ) {  if( count == 0){  sb.append("H "+line);  sb.append("\n");  }  else{  sb.append("D "+line);  sb.append("\n");  }  count++;  }     out.write(sb.toString().getBytes());     } catch (IOException e) {  e.printStackTrace();  }  } catch (Exception e) {  e.printStackTrace();  }  } // end of execute
}

Viewing all articles
Browse latest Browse all 9236

Trending Articles