use of org.xmlpull.v1.XmlPullParserFactory in project Mindroid.java by Himmele.
the class SharedPreferencesImpl method writeMap.
private void writeMap(File file, Map<String, Object> map) throws XmlPullParserException, IOException {
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlSerializer serializer = factory.newSerializer();
serializer.setOutput(os, UTF_8);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startDocument(UTF_8, true);
serializer.startTag(null, MAP_TAG);
Iterator<Map.Entry<String, Object>> itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, Object> entry = itr.next();
writeValue(serializer, entry.getKey(), entry.getValue());
}
serializer.endTag(null, MAP_TAG);
serializer.endDocument();
} catch (FileNotFoundException e) {
throw e;
} catch (XmlPullParserException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
}
}
}
}
Aggregations