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;
}
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());
}
}
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;
}
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());
}
}
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;
}
Aggregations