Search in sources :

Example 71 with XmlPullParserFactory

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) {
            }
        }
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)71 XmlPullParser (org.xmlpull.v1.XmlPullParser)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)30 IOException (java.io.IOException)24 InputStream (java.io.InputStream)16 InputStreamReader (java.io.InputStreamReader)10 StringReader (java.io.StringReader)10 FileInputStream (java.io.FileInputStream)8 XmlSerializer (org.xmlpull.v1.XmlSerializer)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 File (java.io.File)5 XmlResourceParser (android.content.res.XmlResourceParser)4 IOException2 (hudson.util.IOException2)4 BufferedReader (java.io.BufferedReader)4 Reader (java.io.Reader)4 Map (java.util.Map)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2