on 05-07-2014 1:18 PM
Java map needed for text input file. The 1st line of text file will always come once. The 2nd line,3rd line given in example may have 4th and 5th dynamic lines,but length of characters will be same in the line
text input is like below -
081517693 TEST
03500701 TEST2
03500713 TEST3
text output should be like this -
H 081517693 TEST
D 03500701 TEST2
D 03500713 TEST3
i need exact java code to achieve this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I can understand that you need to this structure so that you can go for content conversion.
Does your file have only one header and multiple detail lines or it can have multiple header and multiple line items like below
H 081517693 TEST
D 03500701 TEST2
D 03500713 TEST3
H 081517456 TEST
D 03500701 TEST2
D 03500713 TEST3
D 03500713 TEST3
Since it's simple file, why don't you read this file and create your target structure directly in java mapping instead of creating intermediate structure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.