Search in sources :

Example 86 with XmlSerializer

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

the class MountService method writeSettingsLocked.

private void writeSettingsLocked() {
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_VOLUMES);
        writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
        writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
        writeBooleanAttribute(out, ATTR_FORCE_ADOPTABLE, mForceAdoptable);
        final int size = mRecords.size();
        for (int i = 0; i < size; i++) {
            final VolumeRecord rec = mRecords.valueAt(i);
            writeVolumeRecord(out, rec);
        }
        out.endTag(null, TAG_VOLUMES);
        out.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) 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)

Example 87 with XmlSerializer

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

the class FastXmlSerializerTest method testEmptyText.

public void testEmptyText() throws Exception {
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    final XmlSerializer out = new FastXmlSerializer();
    out.setOutput(stream, "utf-8");
    out.startDocument(null, true);
    out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    out.startTag(null, "string");
    out.attribute(null, "name", "meow");
    out.text("");
    out.endTag(null, "string");
    out.endDocument();
    assertEquals("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<string name=\"meow\"></string>\n", stream.toString());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 88 with XmlSerializer

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

the class SyncStorageEngine method writeAccountInfoLocked.

/**
     * Write all account information to the account file.
     */
private void writeAccountInfoLocked() {
    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
        Slog.v(TAG_FILE, "Writing new " + mAccountInfoFile.getBaseFile());
    }
    FileOutputStream fos = null;
    try {
        fos = mAccountInfoFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "accounts");
        out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
        out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
        out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
        // Write the Sync Automatically flags for each user
        final int M = mMasterSyncAutomatically.size();
        for (int m = 0; m < M; m++) {
            int userId = mMasterSyncAutomatically.keyAt(m);
            Boolean listen = mMasterSyncAutomatically.valueAt(m);
            out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
            out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
            out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
        }
        final int N = mAuthorities.size();
        for (int i = 0; i < N; i++) {
            AuthorityInfo authority = mAuthorities.valueAt(i);
            EndPoint info = authority.target;
            out.startTag(null, "authority");
            out.attribute(null, "id", Integer.toString(authority.ident));
            out.attribute(null, XML_ATTR_USER, Integer.toString(info.userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
            out.attribute(null, "account", info.account.name);
            out.attribute(null, "type", info.account.type);
            out.attribute(null, "authority", info.provider);
            out.attribute(null, "syncable", Integer.toString(authority.syncable));
            out.endTag(null, "authority");
        }
        out.endTag(null, "accounts");
        out.endDocument();
        mAccountInfoFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            mAccountInfoFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 89 with XmlSerializer

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

the class PersistentDataStore method save.

private void save() {
    final FileOutputStream os;
    try {
        os = mAtomicFile.startWrite();
        boolean success = false;
        try {
            XmlSerializer serializer = new FastXmlSerializer();
            serializer.setOutput(new BufferedOutputStream(os), StandardCharsets.UTF_8.name());
            saveToXml(serializer);
            serializer.flush();
            success = true;
        } finally {
            if (success) {
                mAtomicFile.finishWrite(os);
            } else {
                mAtomicFile.failWrite(os);
            }
        }
    } catch (IOException ex) {
        Slog.w(TAG, "Failed to save display manager persistent store data.", ex);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 90 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project robovm by robovm.

the class XsltXPathConformanceTestSuite method nodeToNormalizedString.

private String nodeToNormalizedString(Node node) throws XmlPullParserException, IOException {
    StringWriter writer = new StringWriter();
    XmlSerializer xmlSerializer = xmlPullParserFactory.newSerializer();
    xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    xmlSerializer.setOutput(writer);
    emitNode(xmlSerializer, node);
    xmlSerializer.flush();
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Aggregations

XmlSerializer (org.xmlpull.v1.XmlSerializer)268 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)156 IOException (java.io.IOException)151 FileOutputStream (java.io.FileOutputStream)144 BufferedOutputStream (java.io.BufferedOutputStream)57 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 AtomicFile (android.util.AtomicFile)39 RemoteException (android.os.RemoteException)29 File (java.io.File)26 FileNotFoundException (java.io.FileNotFoundException)26 StringWriter (java.io.StringWriter)26 Map (java.util.Map)23 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 UserInfo (android.content.pm.UserInfo)9 HashMap (java.util.HashMap)9 SendIntentException (android.content.IntentSender.SendIntentException)8 PackageParserException (android.content.pm.PackageParser.PackageParserException)8