use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.
the class DatFileCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
FileWriter dbWriter = new FileWriter(db);
BufferedWriter bufWriter = new BufferedWriter(dbWriter);
String aCaller = null;
for (int i = 0; i < this.m_callerList.size(); i++) {
try {
aCaller = new String(Serializer.toByteArray(this.m_callerList.get(i), true));
bufWriter.write(aCaller);
bufWriter.newLine();
} catch (SerializerException e) {
this.m_logger.severe(e.getMessage());
}
}
bufWriter.flush();
bufWriter.close();
dbWriter.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.
the class DatFileCallerImporter method doImport.
public ICallerList doImport() {
m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
Date startDate = new Date();
File db = new File(m_filename);
try {
FileReader dbReader = new FileReader(db);
BufferedReader bufReader = new BufferedReader(dbReader);
ICaller aCaller = null;
while (bufReader.ready()) {
try {
aCaller = Serializer.toCaller(bufReader.readLine().getBytes(), PIMRuntime.getInstance());
if (aCaller == null) {
// file format is corrupted
return this.m_callerList;
}
this.m_callerList.add(aCaller);
} catch (SerializerException e) {
this.m_logger.warning("Caller was skipped: " + e.getMessage());
}
}
bufReader.close();
dbReader.close();
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find caller backup file " + m_filename);
return this.m_callerList;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return this.m_callerList;
}
Date endDate = new Date();
this.m_logger.info("Successfully imported caller file " + m_filename);
this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
return this.m_callerList;
}
use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.
the class DatFileCallExporter method doExport.
public boolean doExport() {
File db = new File(this.m_filename);
try {
FileWriter dbWriter = new FileWriter(db);
BufferedWriter bufWriter = new BufferedWriter(dbWriter);
String aCall = null;
for (int i = 0; i < this.m_callList.size(); i++) {
try {
aCall = new String(Serializer.toByteArray(this.m_callList.get(i)));
bufWriter.write(aCall);
bufWriter.newLine();
} catch (SerializerException e) {
this.m_logger.severe(e.getMessage());
}
}
bufWriter.flush();
bufWriter.close();
dbWriter.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.
the class DatFileCallImporter method doImport.
public ICallList doImport() {
m_callList = PIMRuntime.getInstance().getCallFactory().createCallList();
Date startDate = new Date();
File db = new File(m_filename);
try {
FileReader dbReader = new FileReader(db);
BufferedReader bufReader = new BufferedReader(dbReader);
ICall aCall = null;
boolean isNewDatFormat = false;
String line = null;
Transformator tf = null;
while (bufReader.ready()) {
line = bufReader.readLine();
if (!isNewDatFormat && line != null && line.indexOf("***") > -1) {
if (tf == null)
tf = new Transformator();
} else {
isNewDatFormat = true;
}
try {
aCall = (isNewDatFormat ? Serializer.toCall(line.getBytes(), PIMRuntime.getInstance()) : tf.transform(line));
// 2008/11/07: new call status introduced in 5.0.8
migrateStatus(aCall);
this.m_callList.add(aCall);
} catch (SerializerException e) {
this.m_logger.warning(e.getMessage());
}
}
bufReader.close();
dbReader.close();
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find call backup file " + m_filename);
return this.m_callList;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return this.m_callList;
} catch (NoSuchElementException ex) {
this.m_logger.severe("Invalid format in file " + m_filename);
return this.m_callList;
}
Date endDate = new Date();
this.m_logger.info("Successfully imported call file " + m_filename);
this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
return m_callList;
}
use of de.janrufmonitor.util.io.SerializerException in project janrufmonitor by tbrandt77.
the class AbstractCallDatabaseHandler method updateCallList.
/**
* Updates all calls in the submitted list. The select criterion of teh call is its UUID.
* @param cl
* @throws SQLException
*/
public void updateCallList(ICallList cl) throws SQLException {
if (!isConnected())
try {
this.connect();
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
if (this.containsListAll(cl.size())) {
this.createTables();
this.setCallList(cl);
return;
}
PreparedStatement ps = this.getStatement("UPDATE_CALL");
PreparedStatement psa = this.getStatement("UPDATE_ATTRIBUTE");
ps.clearBatch();
psa.clearBatch();
ICall c = null;
IPhonenumber pn = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
pn = c.getCaller().getPhoneNumber();
try {
this.updateCall(ps, c.getUUID(), c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
this.updateAttributes(psa, c.getUUID(), c.getAttributes());
this.updateAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (i % this.commit_count == 0) {
ps.executeBatch();
ps.clearBatch();
this.m_logger.info("Executed prepared statement: " + ps.toString());
psa.executeBatch();
psa.clearBatch();
this.m_logger.info("Executed prepared statement: " + psa.toString());
}
}
// execute the rest batch content
ps.executeBatch();
psa.executeBatch();
}
Aggregations