Search in sources :

Example 1 with GetCallListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.

the class AbstractFritzBoxFirmware method getCallList.

public List getCallList() throws GetCallListException, IOException {
    if (!this.isInitialized())
        throw new GetCallListException("Could not get call list from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getCallListAsStream();
    } 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();
        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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 2 with GetCallListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.

the class FritzOS559Firmware method getCallListAsStream.

private InputStream getCallListAsStream() throws GetCallListException, IOException {
    long start = System.currentTimeMillis();
    this.m_logger.info("Starting retrieving call list...");
    // The list should be updated now
    // Get the csv file for processing
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/foncalls_list.lua?csv=&sid=" + this.m_sid;
    URL url;
    URLConnection urlConn;
    try {
        this.m_logger.info("Calling FritzBox URL: " + urlstr);
        url = new URL(urlstr);
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetCallListException("Invalid URL: " + urlstr);
    }
    urlConn = url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setUseCaches(false);
    // urlConn.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8");
    // Sending postdata to the fritz box
    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e2) {
        this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
    }
    try {
        // Get response data from the box
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
        Stream.copy(urlConn.getInputStream(), bos);
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toString("utf-8").getBytes("utf-8"));
        // this.m_logger.info(bos.toString());
        this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
        urlConn.getInputStream().close();
        return bin;
    } catch (IOException e1) {
        this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        throw new GetCallListException(e1.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 3 with GetCallListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.

the class FritzOS559Firmware method getCallList.

public List getCallList() throws GetCallListException, IOException {
    if (!this.isInitialized())
        throw new GetCallListException("Could not get call list from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getCallListAsStream();
    } catch (IOException e) {
        throw new GetCallListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    InputStreamReader inr = new InputStreamReader(in, "utf-8");
    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 (this.m_logger.isLoggable(Level.FINE))
            this.m_logger.log(Level.FINE, line);
        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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 4 with GetCallListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.

the class FritzOSFirmware method getCallListAsStream.

private InputStream getCallListAsStream() throws GetCallListException, IOException {
    long start = System.currentTimeMillis();
    this.m_logger.info("Starting retrieving call list...");
    // The list should be updated now
    // Get the csv file for processing
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/foncalls_list.lua?csv=&sid=" + this.m_sid;
    URL url;
    URLConnection urlConn;
    try {
        this.m_logger.info("Calling FritzBox URL: " + urlstr);
        url = new URL(urlstr);
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetCallListException("Invalid URL: " + urlstr);
    }
    urlConn = url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setUseCaches(false);
    // urlConn.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8");
    // Sending postdata to the fritz box
    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e2) {
        this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
    }
    try {
        // Get response data from the box
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
        Stream.copy(urlConn.getInputStream(), bos);
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toString("utf-8").getBytes("utf-8"));
        // this.m_logger.info(bos.toString());
        this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
        urlConn.getInputStream().close();
        return bin;
    } catch (IOException e1) {
        this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        throw new GetCallListException(e1.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GetCallListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallListException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 5 with GetCallListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetCallListException in project janrufmonitor by tbrandt77.

the class FritzOSFirmware method getCallList.

public List getCallList() throws GetCallListException, IOException {
    if (!this.isInitialized())
        throw new GetCallListException("Could not get call list from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getCallListAsStream();
    } catch (IOException e) {
        throw new GetCallListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    InputStreamReader inr = new InputStreamReader(in, "utf-8");
    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 (this.m_logger.isLoggable(Level.FINE))
            this.m_logger.log(Level.FINE, line);
        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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) 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