/** * Attempts to load * * @param jid the jid of the user. * @return the VCard if found, otherwise null. */ private VCard loadFromFileSystem(String jid) { if (jid == null || jid.trim().isEmpty()) { return null; } // Unescape JID String fileName = Base64.encodeBytes(jid.getBytes()); // remove tab fileName = fileName.replaceAll("\t", ""); // remove new line (Unix) fileName = fileName.replaceAll("\n", ""); // remove new line (Windows) fileName = fileName.replaceAll("\r", ""); final File vcardFile = new File(vcardStorageDirectory, fileName); if (!vcardFile.exists()) { return null; } try { // Otherwise load from file system. BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(vcardFile), "UTF-8")); VCardProvider provider = new VCardProvider(); parser.setInput(in); VCard vcard = (VCard)provider.parseIQ(parser); // Check to see if the file is older 10 minutes. If so, reload. String timestamp = vcard.getField("timestamp"); if (timestamp != null) { long time = Long.parseLong(timestamp); long now = System.currentTimeMillis(); long hour = (1000 * 60) * 60; if (now - time > hour) { addToQueue(jid); } } addVCard(jid, vcard); return vcard; } catch (Exception e) { Log.warning("Unable to load vCard for " + jid, e); } return null; }