return list.iterator();\r
}\r
\r
+ /**\r
+ * Shuts down this backend\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ try {\r
+ // Close file\r
+ this.storageFile.close();\r
+ } catch (final IOException ex) {\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+ }\r
+\r
/**\r
* Get length of underlaying file\r
*\r
this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));\r
\r
// The string is now a valid CSV string\r
- this.storageFile.writeChars(str);\r
+ this.storageFile.writeBytes(str);\r
+ }\r
+\r
+ /**\r
+ * Adds given contact to list\r
+ * \r
+ * @param contact Contact instance to add\r
+ * @param list List instance\r
+ */\r
+ private void addContactToList (final Contact contact, final List<Contact> list) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("contact={0}", contact));\r
+\r
+ // Is the contact read?\r
+ if (contact instanceof Contact) {\r
+ // Then add it\r
+ boolean added = list.add(contact);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));\r
+\r
+ // Has it been added?\r
+ if (!added) {\r
+ // Not added\r
+ this.getLogger().warn("Contact object has not been added.");\r
+ }\r
+ }\r
}\r
\r
/**\r
// First rewind\r
this.rewind();\r
\r
+ // Get file size and divide it by 140 (possible average length of one line)\r
+ int lines = Math.round(this.length() / 140 + 0.5f);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("lines={0}", lines));\r
+\r
// Instance list\r
// @TODO The maximum length could be guessed from file size?\r
- List<Contact> list = new ArrayList<>();\r
+ List<Contact> list = new ArrayList<>(lines);\r
\r
// Init variables\r
StringTokenizer tokenizer;\r
count++;\r
}\r
\r
- // Is the contact read?\r
- if (contact instanceof Contact) {\r
- // Then add it\r
- assert(list.add(contact));\r
- }\r
+ // Add contact\r
+ this.addContactToList(contact, list);\r
}\r
\r
// Return finished list\r