I have the following service for to get values inside a string document, this service is called inside a for, getting the data for every flight and then generate a PDF.
I'm getting the Index 2 out of bounds for length 1 when try to call the service, this is the code:
private Map<String, Object> readFileLsd(String content) {
Map<String, Object> mapResult = new LinkedHashMap<>();
try {
Reader inputString = new StringReader(content);
BufferedReader br = new BufferedReader(inputString);
String line;
String TotalBaggagesCargo = "";
String PASSENGER = "";
String TOTAL_TRAFFIC = "";
String validCharacters = "[\\x00-\\x1F]|[\\x21-\\x2c]|[\\x3B-\\x40]|[\\x5B-\\x60]|[\\x7B-\\xFF]";
while ((line = br.readLine()) != null) {
line = line.replaceAll(validCharacters, "").trim();
if (line.startsWith("LOAD IN COMPARTMENTS")) {
TotalBaggagesCargo = line;
}
if (line.startsWith("PASSENGER/CABIN BAG")) {
PASSENGER = line;
}
if (line.startsWith("TOTAL TRAFFIC LOAD")) {
TOTAL_TRAFFIC = line;
}
}
mapResult.put("TotalBaggagesCargo", TotalBaggagesCargo.trim().replaceAll("\\s+", " ").split(" ")[3]);
mapResult.put("PASSENGER", PASSENGER.trim().replaceAll("\\s+", " ").split(" ")[2]);
mapResult.put("TOTAL_TRAFFIC", TOTAL_TRAFFIC.trim().replaceAll("\\s+", " ").split(" ")[3]);
} catch (Exception e) {
e.printStackTrace();
}
return mapResult;
}