I am new to java and am currently trying to update the body of a message that is transported within a camel route (via talend).
So far all is well, I manage to modify this message. However if the file is too large the JVM goes out of memory.
How to reconstruct the message knowing that it must be modified, but only certain lines?
For example I have to change line A, but keep lines B and C intact, and thus rebuild my message.
Knowing that camel does not provide an updateBody () for example and the setOut body creates a new message for me.
Thanks in advance !
InputStream inputStream = exchange.getIn().getBody(InputStream.class);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
String columnToForceToZero = String.valueOf(exchange.getProperty("targetColumn"));
String lineToChange = String.valueOf(exchange.getProperty("targetLine"));
//String Separator = String.valueOf(exchange.getProperty("separator"));
List<String> listColumn = new ArrayList<String>(Arrays.asList(columnToForceToZero.split(",")));
int lengthLineToChange = lineToChange.length();
//String newBody = exchange.getIn().getBody(String.class);
String nouveauBody="";
while( line != null) {
if (lineToChange.equals(line.substring(0,lengthLineToChange))){
List<String> list = new ArrayList<String>(Arrays.asList(line.split("\\|")));
for (int i = 0; i < listColumn.size() ; i++) {
list.set(Integer.parseInt(listColumn.get(i)), context.work_YODA_IN_value_to_force);
}
line = String.join("|", list);
}
nouveauBody = nouveauBody + line +"\n";
line = reader.readLine();
}
exchange.getOut().setBody(nouveauBody);
exchange.getOut().setHeaders(exchange.getIn().getHeaders());
//copy attachements from IN to OUT to propagate them
exchange.getOut().setAttachments(exchange.getIn().getAttachments());