Search in sources :

Example 36 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class NotificationManagerService method writePolicyXml.

private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException {
    final XmlSerializer out = new FastXmlSerializer();
    out.setOutput(stream, StandardCharsets.UTF_8.name());
    out.startDocument(null, true);
    out.startTag(null, TAG_NOTIFICATION_POLICY);
    out.attribute(null, ATTR_VERSION, Integer.toString(DB_VERSION));
    mZenModeHelper.writeXml(out, forBackup);
    mRankingHelper.writeXml(out, forBackup);
    out.endTag(null, TAG_NOTIFICATION_POLICY);
    out.endDocument();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 37 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class XmlUtils method writeMapXml.

/**
     * Flatten a Map into an output stream as XML.  The map can later be
     * read back with readMapXml().
     *
     * @param val The map to be flattened.
     * @param out Where to write the XML data.
     *
     * @see #writeMapXml(Map, String, XmlSerializer)
     * @see #writeListXml
     * @see #writeValueXml
     * @see #readMapXml
     */
public static final void writeMapXml(Map val, OutputStream out) throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, StandardCharsets.UTF_8.name());
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 38 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class XmlUtils method writeListXml.

/**
     * Flatten a List into an output stream as XML.  The list can later be
     * read back with readListXml().
     *
     * @param val The list to be flattened.
     * @param out Where to write the XML data.
     *
     * @see #writeListXml(List, String, XmlSerializer)
     * @see #writeMapXml
     * @see #writeValueXml
     * @see #readListXml
     */
public static final void writeListXml(List val, OutputStream out) throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, StandardCharsets.UTF_8.name());
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 39 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class DeviceIdleController method handleWriteConfigFile.

void handleWriteConfigFile() {
    final ByteArrayOutputStream memStream = new ByteArrayOutputStream();
    try {
        synchronized (this) {
            XmlSerializer out = new FastXmlSerializer();
            out.setOutput(memStream, StandardCharsets.UTF_8.name());
            writeConfigFileLocked(out);
        }
    } catch (IOException e) {
    }
    synchronized (mConfigFile) {
        FileOutputStream stream = null;
        try {
            stream = mConfigFile.startWrite();
            memStream.writeTo(stream);
            stream.flush();
            FileUtils.sync(stream);
            stream.close();
            mConfigFile.finishWrite(stream);
        } catch (IOException e) {
            Slog.w(TAG, "Error writing config file", e);
            mConfigFile.failWrite(stream);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 40 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class DisplaySettings method writeSettingsLocked.

public void writeSettingsLocked() {
    FileOutputStream stream;
    try {
        stream = mFile.startWrite();
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings: " + e);
        return;
    }
    try {
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, "display-settings");
        for (Entry entry : mEntries.values()) {
            out.startTag(null, "display");
            out.attribute(null, "name", entry.name);
            if (entry.overscanLeft != 0) {
                out.attribute(null, "overscanLeft", Integer.toString(entry.overscanLeft));
            }
            if (entry.overscanTop != 0) {
                out.attribute(null, "overscanTop", Integer.toString(entry.overscanTop));
            }
            if (entry.overscanRight != 0) {
                out.attribute(null, "overscanRight", Integer.toString(entry.overscanRight));
            }
            if (entry.overscanBottom != 0) {
                out.attribute(null, "overscanBottom", Integer.toString(entry.overscanBottom));
            }
            out.endTag(null, "display");
        }
        out.endTag(null, "display-settings");
        out.endDocument();
        mFile.finishWrite(stream);
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings, restoring backup.", e);
        mFile.failWrite(stream);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Aggregations

XmlSerializer (org.xmlpull.v1.XmlSerializer)307 IOException (java.io.IOException)171 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)157 FileOutputStream (java.io.FileOutputStream)156 BufferedOutputStream (java.io.BufferedOutputStream)61 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)56 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 AtomicFile (android.util.AtomicFile)39 File (java.io.File)32 FileNotFoundException (java.io.FileNotFoundException)32 StringWriter (java.io.StringWriter)30 RemoteException (android.os.RemoteException)29 Map (java.util.Map)26 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 HashMap (java.util.HashMap)14 FileWriter (java.io.FileWriter)12 UserInfo (android.content.pm.UserInfo)9 SendIntentException (android.content.IntentSender.SendIntentException)8