Search in sources :

Example 11 with GetCallListException

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;
}
Also used : GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)11 IOException (java.io.IOException)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 InputStream (java.io.InputStream)5 MalformedURLException (java.net.MalformedURLException)5 URL (java.net.URL)5 URLConnection (java.net.URLConnection)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataOutputStream (java.io.DataOutputStream)2 Message (de.janrufmonitor.exception.Message)1 ICall (de.janrufmonitor.framework.ICall)1 ICallList (de.janrufmonitor.framework.ICallList)1 ICip (de.janrufmonitor.framework.ICip)1 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)1 FritzBoxCallCsv (de.janrufmonitor.fritzbox.FritzBoxCallCsv)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1