int i, j, memIndex;
int limit = (myLimit < 0 ? 0 : myLimit);
String response, line, tmpLine, msgText, originator, dateStr, refNo;
BufferedReader reader;
StringTokenizer tokens;
InboundMessage msg;
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
for (int ml = 0; ml < (getATHandler().getStorageLocations().length() / 2); ml++)
{
if (getATHandler().switchStorageLocation(getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2)))
{
response = getATHandler().listMessages(msgClass);
response = response.replaceAll("\\s+OK\\s+", "\nOK");
reader = new BufferedReader(new StringReader(response));
for (;;)
{
line = reader.readLine();
if (line == null) break;
line = line.trim();
if (line.length() > 0) break;
}
while (true)
{
if (line == null) break;
if (line.length() <= 0 || line.equalsIgnoreCase("OK")) break;
i = line.indexOf(':');
j = line.indexOf(',');
memIndex = 0;
try
{
memIndex = Integer.parseInt(line.substring(i + 1, j).trim());
}
catch (NumberFormatException e)
{
// TODO: What to do here?
Logger.getInstance().logWarn("Incorrect Memory Index number parsed!", e, getGatewayId());
}
tokens = new StringTokenizer(line, ",");
tokens.nextToken();
tokens.nextToken();
tmpLine = "";
if (Character.isDigit(tokens.nextToken().trim().charAt(0)))
{
line = line.replaceAll(",,", ", ,");
tokens = new StringTokenizer(line, ",");
tokens.nextToken();
tokens.nextToken();
tokens.nextToken();
refNo = tokens.nextToken();
tokens.nextToken();
dateStr = tokens.nextToken().replaceAll("\"", "");
cal1.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
cal1.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
dateStr = tokens.nextToken().replaceAll("\"", "");
cal1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
cal1.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
cal1.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
dateStr = tokens.nextToken().replaceAll("\"", "");
cal2.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
cal2.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
cal2.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
dateStr = tokens.nextToken().replaceAll("\"", "");
cal2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
cal2.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
cal2.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
msg = new StatusReportMessage(refNo, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2), cal1.getTime(), cal2.getTime());
msg.setGatewayId(getGatewayId());
Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex(), null, getGatewayId());
msgList.add(msg);
incInboundMessageCount();
}
else
{
line = line.replaceAll(",,", ", ,");
tokens = new StringTokenizer(line, ",");
tokens.nextToken();
tokens.nextToken();
originator = tokens.nextToken().replaceAll("\"", "");
tokens.nextToken();
dateStr = tokens.nextToken().replaceAll("\"", "");
cal1.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
cal1.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
dateStr = tokens.nextToken().replaceAll("\"", "");
cal1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
cal1.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
cal1.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
msgText = "";
while (true)
{
tmpLine = reader.readLine();
if (tmpLine == null) break;
if (tmpLine.startsWith("+CMGL")) break;
if (tmpLine.startsWith("+CMGR")) break;
msgText += (msgText.length() == 0 ? "" : "\n") + tmpLine;
}
msgText = msgText.trim();
msg = new InboundMessage(cal1.getTime(), originator, msgText, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2));
msg.setGatewayId(getGatewayId());
Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex(), null, getGatewayId());
msgList.add(msg);
incInboundMessageCount();
}
while (true)
{