use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.
the class TR064FritzBoxFirmware method getCallList.
public List getCallList(long lastSyncTimestamp) throws GetCallListException, IOException {
if (!this.isInitialized())
throw new GetCallListException("Could not get call list from FritzBox: FritzBox firmware not initialized.");
InputStream in = null;
try {
if (lastSyncTimestamp == -1L) {
in = FritzBoxTR064Manager.getInstance().getCallList(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"), -1);
} else {
long now = System.currentTimeMillis();
int days = (int) ((now - lastSyncTimestamp) / (1000 * 60 * 60 * 24)) + 1;
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Only retrieve call list for the last x days: " + days);
in = FritzBoxTR064Manager.getInstance().getCallList(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"), (days > 0 ? days : 1));
}
} catch (IOException e) {
throw new GetCallListException(e.getMessage());
}
if (in == null)
return new ArrayList(0);
List result = new ArrayList();
InputStreamReader inr = new InputStreamReader(in, "iso-8859-1");
BufferedReader bufReader = new BufferedReader(inr);
// drop header
String line = bufReader.readLine();
if (// new fw version
line.startsWith("sep="))
// drop header of new fw
bufReader.readLine();
while (bufReader.ready()) {
line = bufReader.readLine();
if (line != null && line.trim().length() > 0)
result.add(line);
}
bufReader.close();
in.close();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Callist from FritzBox succuessfully fetched. List size: " + result.size());
return result;
}
Aggregations