Example usage for android.util Xml newSerializer

List of usage examples for android.util Xml newSerializer

Introduction

In this page you can find the example usage for android.util Xml newSerializer.

Prototype

public static XmlSerializer newSerializer() 

Source Link

Document

Creates a new xml serializer.

Usage

From source file:com.southernstorm.tvguide.TvChannelCache.java

/**
 * Saves the hidden-vs-shown states of all channels to the SD card.
 *///from w  w w . j a  v a  2  s  .  c o m
public void saveChannelHiddenStates() {
    if (!isMediaUsable())
        return;
    File serviceDir = new File(getFilesDir(), serviceName);
    serviceDir.mkdirs();
    File file = new File(serviceDir, "channels.xml");
    try {
        FileOutputStream fileStream = new FileOutputStream(file);
        XmlSerializer serializer = Xml.newSerializer();
        serializer.setOutput(fileStream, "UTF-8");
        serializer.startDocument(null, Boolean.valueOf(true));
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, "tv");
        for (TvChannel channel : channels.values()) {
            if (channel.getHiddenState() == channel.getDefaultHiddenState())
                continue; // Don't save channels that have their default hidden state.
            serializer.startTag(null, "channel");
            serializer.attribute(null, "id", channel.getId());
            if (channel.getHiddenState() == TvChannel.HIDDEN)
                serializer.attribute(null, "hidden-state", "hide");
            else if (channel.getHiddenState() == TvChannel.NOT_HIDDEN)
                serializer.attribute(null, "hidden-state", "show");
            else
                serializer.attribute(null, "hidden-state", "by-region");
            serializer.endTag(null, "channel");
        }
        serializer.endTag(null, "tv");
        serializer.endDocument();
        fileStream.close();
    } catch (IOException e) {
    }
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private void fpse() {
      String str1 = Settings.Secure.getString(getContext().getContentResolver(), "android_id");
      Object localObject1 = new AESObfuscator(salt, this.package_name, str1);
      str1 = Long.toString(System.currentTimeMillis() + 62208000000L);
      String str3 = Long.toString(System.currentTimeMillis() + 62208000000L);
      str1 = ((AESObfuscator) localObject1).obfuscate(str1, "validityTimestamp");
      String str2 = ((AESObfuscator) localObject1).obfuscate("256", "lastResponse");
      str3 = ((AESObfuscator) localObject1).obfuscate(str3, "retryUntil");
      String str4 = ((AESObfuscator) localObject1).obfuscate("10", "maxRetries");
      String str5 = ((AESObfuscator) localObject1).obfuscate("0", "retryCount");
      Object localObject2 = new File(getContext().getFilesDir() + "/" + this.prefs_name);
      localObject1 = new File("/data/data/" + this.package_name + "/" + this.prefs_dir + "/" + this.prefs_name);
      File localFile = new File(
              "/dbdata/databases/" + this.package_name + "/" + this.prefs_dir + "/" + this.prefs_name);
      try {// w  w  w  .jav a  2  s . co m
          ((File) localObject2).createNewFile();
          localObject2 = new FileOutputStream((File) localObject2);
          XmlSerializer localXmlSerializer = Xml.newSerializer();
          localXmlSerializer.setOutput((OutputStream) localObject2, "UTF-8");
          localXmlSerializer.startDocument(null, Boolean.valueOf(true));
          localXmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
          localXmlSerializer.startTag(null, "map");
          localXmlSerializer.startTag(null, "string");
          localXmlSerializer.attribute("", "name", "validityTimestamp");
          localXmlSerializer.text(str1);
          localXmlSerializer.endTag(null, "string");
          localXmlSerializer.startTag(null, "string");
          localXmlSerializer.attribute("", "name", "retryCount");
          localXmlSerializer.text(str5);
          localXmlSerializer.endTag(null, "string");
          localXmlSerializer.startTag(null, "string");
          localXmlSerializer.attribute("", "name", "maxRetries");
          localXmlSerializer.text(str4);
          localXmlSerializer.endTag(null, "string");
          localXmlSerializer.startTag(null, "string");
          localXmlSerializer.attribute("", "name", "retryUntil");
          localXmlSerializer.text(str3);
          localXmlSerializer.endTag(null, "string");
          localXmlSerializer.startTag(null, "string");
          localXmlSerializer.attribute("", "name", "lastResponse");
          localXmlSerializer.text(str2);
          localXmlSerializer.endTag(null, "string");
          localXmlSerializer.endTag(null, "map");
          localXmlSerializer.endDocument();
          localXmlSerializer.flush();
          ((FileOutputStream) localObject2).close();
          Utils.copyFile(getContext().getFilesDir() + "/" + this.prefs_name,
                  ((File) localObject1).getAbsolutePath(), false, false);
          Utils.copyFile(getContext().getFilesDir() + "/" + this.prefs_name, localFile.getAbsolutePath(), false,
                  false);
          if (new File(getContext().getFilesDir() + "/" + this.prefs_name).exists()) {
              new File(getContext().getFilesDir() + "/" + this.prefs_name).delete();
          }
          Utils.run_all("chmod 777 " + ((File) localObject1).getAbsolutePath());
          Utils.run_all("chmod 777 " + localFile.getAbsolutePath());
          return;
      } catch (Exception localException) {
          for (;;) {
          }
      }
  }

From source file:cm.aptoide.pt.MainActivity.java

protected void generateXML() {
    System.out.println("Generating servers.xml");
    File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/.aptoide/servers.xml");
    try {//from  w ww  .  j a  v  a 2s  . com
        newxmlfile.createNewFile();
    } catch (IOException e) {
        Log.e("IOException", "exception in createNewFile() method");
    }
    FileOutputStream fileos = null;
    try {
        fileos = new FileOutputStream(newxmlfile);
    } catch (FileNotFoundException e) {
        Log.e("FileNotFoundException", "can't create FileOutputStream");
    }
    XmlSerializer serializer = Xml.newSerializer();
    try {
        serializer.setOutput(fileos, "UTF-8");
        serializer.startDocument(null, Boolean.valueOf(true));
        serializer.startTag(null, "myapp");
        Cursor c = db.getStores(false);
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            serializer.startTag(null, "newserver");
            serializer.startTag(null, "server");
            serializer.text(c.getString(1));
            serializer.endTag(null, "server");
            serializer.endTag(null, "newserver");
        }
        c.close();

        serializer.endTag(null, "myapp");
        serializer.endDocument();
        serializer.flush();
        fileos.close();
    } catch (Exception e) {
        Log.e("Exception", "error occurred while creating xml file");
    }

}