本文整理汇总了Java中org.xmlpull.v1.XmlSerializer.endDocument方法的典型用法代码示例。如果您正苦于以下问题:Java XmlSerializer.endDocument方法的具体用法?Java XmlSerializer.endDocument怎么用?Java XmlSerializer.endDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmlpull.v1.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.endDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePublicXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void generatePublicXml(ResPackage pkg, Directory out,
XmlSerializer serial) throws AndrolibException {
try {
OutputStream outStream = out.getFileOutput("values/public.xml");
serial.setOutput(outStream, null);
serial.startDocument(null, null);
serial.startTag(null, "resources");
for (ResResSpec spec : pkg.listResSpecs()) {
serial.startTag(null, "public");
serial.attribute(null, "type", spec.getType().getName());
serial.attribute(null, "name", spec.getName());
serial.attribute(null, "id", String.format("0x%08x", spec.getId().id));
serial.endTag(null, "public");
}
serial.endTag(null, "resources");
serial.endDocument();
serial.flush();
outStream.close();
} catch (IOException | DirectoryException ex) {
throw new AndrolibException("Could not generate public.xml file", ex);
}
}
示例2: writeUserLocked
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void writeUserLocked(VUserInfo userInfo) {
FileOutputStream fos = null;
AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml"));
try {
fos = userFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id));
serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber));
serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags));
serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime));
serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME,
Long.toString(userInfo.lastLoggedInTime));
if (userInfo.iconPath != null) {
serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath);
}
if (userInfo.partial) {
serializer.attribute(null, ATTR_PARTIAL, "true");
}
serializer.startTag(null, TAG_NAME);
serializer.text(userInfo.name);
serializer.endTag(null, TAG_NAME);
serializer.endTag(null, TAG_USER);
serializer.endDocument();
userFile.finishWrite(fos);
} catch (Exception ioe) {
VLog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe);
userFile.failWrite(fos);
}
}
示例3: save
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Method that saves list of document into XML file
* @throws IOException
*/
@Override
public void save() throws IOException {
Log.d("DocManager","ActualSave");
File toWrite = new File(context.getFilesDir(), URI);
FileOutputStream fos = new FileOutputStream(toWrite);
XmlSerializer xmlSerializer = Xml.newSerializer();
xmlSerializer.setOutput(fos, "UTF-8");
xmlSerializer.startDocument(null, true);
xmlSerializer.startTag(null, "documentList");
for(int i=0; i < documents.size(); ++i){
xmlSerializer.startTag(null, "document");
addTag(xmlSerializer, "uri", documents.get(i).getUri());
addTag(xmlSerializer, "title", documents.get(i).getTitle());
addTag(xmlSerializer, "author", documents.get(i).getAuthor());
addTag(xmlSerializer, "importDate", String.valueOf(documents.get(i).getImportDate().getTime()));
addTag(xmlSerializer, "lastReadPosition", String.valueOf(documents.get(i).getLastReadPosition()));
Log.d("CicloFir",String.valueOf(documents.get(i).getLastReadPosition()));
//addTag(xmlSerializer, "length", String.valueOf(documents.get(i).getLength()));
// Insert list of bookmarks
for(int j=0; j < documents.get(i).getBookmark().size(); ++j){
addTag(xmlSerializer, "bmName", documents.get(i).getBookmark().get(j).getName());
addTag(xmlSerializer, "bmPosition", String.valueOf(documents.get(i).getBookmark().get(j).getIndex()));
}
xmlSerializer.endTag(null, "document");
}
xmlSerializer.endTag(null, "documentList");
xmlSerializer.endDocument();
xmlSerializer.flush();
fos.close();
}
示例4: save
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/***
* Public Method that save current application setting to XML file
* @throws IOException
*/
public void save() throws IOException {
//SettingManager systemSetts = new SettingManager();
TextSetting textSetts = (TextSetting) /*systemSetts.*/settings.get(0);
ArrayMap<String, String> textSpecs = textSetts.getSpecs();
ThemeSetting themeSetts = (ThemeSetting) /*systemSetts.*/settings.get(1);
ArrayMap<String, String> themeSpecs = themeSetts.getSpecs();
FattsSetting fattsSetts = (FattsSetting) /*systemSetts.*/settings.get(2);
ArrayMap<String, String> fattsSpecs = fattsSetts.getSpecs();
File toWrite = new File(context.getFilesDir(), context.getResources().getString(R.string.uri_setting));
FileOutputStream fos = new FileOutputStream(toWrite);
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(fos, "UTF-8");
serializer.startDocument(null, true);
//serializer.setFeature(FEATURE_PROCESS_NAMESPACES, false);
serializer.startTag(null, "settings");
serializer.startTag(null, "textsetting");
genTag(serializer, "size", textSpecs.get("size"));
genTag(serializer, "spacing", textSpecs.get("spacing"));
genTag(serializer, "lineSpacing", textSpecs.get("lineSpacing"));
serializer.endTag(null, "textsetting");
serializer.startTag(null, "themesetting");
genTag(serializer, "font", themeSpecs.get("originalFont"));
genTag(serializer, "palette", themeSpecs.get("palette"));
genTag(serializer, "highlight", themeSpecs.get("highlight"));
serializer.endTag(null, "themesetting");
serializer.startTag(null, "fattssetting");
genTag(serializer, "id", fattsSpecs.get("id"));
genTag(serializer, "language", fattsSpecs.get("language"));
genTag(serializer, "gender", fattsSpecs.get("gender"));
genTag(serializer, "speed", fattsSpecs.get("speed"));
serializer.endTag(null, "fattssetting");
serializer.endDocument();
serializer.flush();
fos.close();
}
示例5: writeUserListLocked
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void writeUserListLocked() {
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
for (int i = 0; i < mUsers.size(); i++) {
VUserInfo user = mUsers.valueAt(i);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(user.id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
VLog.e(LOG_TAG, "Error writing user list");
}
}
示例6: writeToStream
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* XML interface: procedure writes this list into the given stream
*/
public boolean writeToStream(OutputStream stream, String name)
{
try
{
final StringWriter writer = new StringWriter();
final XmlSerializer serializer = Xml.newSerializer();
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
serializer.setPrefix(FormulaList.XML_PROP_MMT, FormulaList.XML_HTTP);
serializer.startTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
serializer.startTag(FormulaList.XML_NS, XML_LIST_TAG);
documentSettings.writeToXml(serializer);
final ArrayList<FormulaBase> fList = formulaListView.getFormulas(FormulaBase.class);
for (FormulaBase f : fList)
{
final String term = f.getBaseType().toString().toLowerCase(Locale.ENGLISH);
serializer.startTag(FormulaList.XML_NS, term);
f.writeToXml(serializer, String.valueOf(f.getId()));
serializer.endTag(FormulaList.XML_NS, term);
}
serializer.endTag(FormulaList.XML_NS, XML_LIST_TAG);
serializer.endTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
serializer.endDocument();
stream.write(writer.toString().getBytes());
return true;
}
catch (Exception e)
{
final String error = String.format(activity.getResources().getString(R.string.error_file_write), name);
Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
}
return false;
}
示例7: getAllSMS
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* 获取手机短信并保存到xml中
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
*/
public static void getAllSMS() {
// 1.获取短信
// 1.1获取内容解析者
ContentResolver resolver = Utils.getContext().getContentResolver();
// 1.2获取内容提供者地址 sms,sms表的地址:null 不写
// 1.3获取查询路径
Uri uri = Uri.parse("content://sms");
// 1.4.查询操作
// projection : 查询的字段
// selection : 查询的条件
// selectionArgs : 查询条件的参数
// sortOrder : 排序
Cursor cursor = resolver.query(uri, new String[]{"address", "date", "type", "body"}, null, null, null);
// 设置最大进度
int count = cursor.getCount();//获取短信的个数
// 2.备份短信
// 2.1获取xml序列器
XmlSerializer xmlSerializer = Xml.newSerializer();
try {
// 2.2设置xml文件保存的路径
// os : 保存的位置
// encoding : 编码格式
xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
// 2.3设置头信息
// standalone : 是否独立保存
xmlSerializer.startDocument("utf-8", true);
// 2.4设置根标签
xmlSerializer.startTag(null, "smss");
// 1.5.解析cursor
while (cursor.moveToNext()) {
SystemClock.sleep(1000);
// 2.5设置短信的标签
xmlSerializer.startTag(null, "sms");
// 2.6设置文本内容的标签
xmlSerializer.startTag(null, "address");
String address = cursor.getString(0);
// 2.7设置文本内容
xmlSerializer.text(address);
xmlSerializer.endTag(null, "address");
xmlSerializer.startTag(null, "date");
String date = cursor.getString(1);
xmlSerializer.text(date);
xmlSerializer.endTag(null, "date");
xmlSerializer.startTag(null, "type");
String type = cursor.getString(2);
xmlSerializer.text(type);
xmlSerializer.endTag(null, "type");
xmlSerializer.startTag(null, "body");
String body = cursor.getString(3);
xmlSerializer.text(body);
xmlSerializer.endTag(null, "body");
xmlSerializer.endTag(null, "sms");
System.out.println("address:" + address + " date:" + date + " type:" + type + " body:" + body);
}
xmlSerializer.endTag(null, "smss");
xmlSerializer.endDocument();
// 2.8将数据刷新到文件中
xmlSerializer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: createChangesetXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public static String createChangesetXmlBody(Map<String, String> tags) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<changeset>
<tag k="created_by" v="JOSM 1.61"/>
<tag k="comment" v="Just adding some streetnames"/>
...
</changeset>
...
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "changeset");
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "changeset");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例9: updateNodeXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public static String updateNodeXmlBody(Map<String, String> tags, long nodeId, String changesetId, double lat, double lon, int versionNumber) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<node id="..." changeset="12" lat="..." lon="..." version="12">
<tag k="note" v="Just a node"/>
...
</node>
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "node");
xmlSerializer.attribute("", "id", String.valueOf(nodeId));
xmlSerializer.attribute("", "changeset", changesetId);
xmlSerializer.attribute("", "lat", String.valueOf(lat));
xmlSerializer.attribute("", "lon", String.valueOf(lon));
xmlSerializer.attribute("", "version", String.valueOf(versionNumber));
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "node");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例10: createNodeXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public static String createNodeXmlBody(Map<String, String> tags, String changesetId, double lat, double lon) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<node changeset="12" lat="..." lon="...">
<tag k="note" v="Just a node"/>
...
</node>
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "node");
xmlSerializer.attribute("", "changeset", changesetId);
xmlSerializer.attribute("", "lat", String.valueOf(lat));
xmlSerializer.attribute("", "lon", String.valueOf(lon));
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "node");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例11: xmlExport
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void xmlExport(OutputStream out) throws IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(out, "UTF-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, "netguard");
serializer.startTag(null, "application");
xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer);
serializer.endTag(null, "application");
serializer.startTag(null, "wifi");
xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "wifi");
serializer.startTag(null, "mobile");
xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "mobile");
serializer.startTag(null, "screen_wifi");
xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "screen_wifi");
serializer.startTag(null, "screen_other");
xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "screen_other");
serializer.startTag(null, "roaming");
xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "roaming");
serializer.startTag(null, "lockdown");
xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "lockdown");
serializer.startTag(null, "apply");
xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "apply");
serializer.startTag(null, "notify");
xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "notify");
serializer.startTag(null, "filter");
filterExport(serializer);
serializer.endTag(null, "filter");
serializer.startTag(null, "forward");
forwardExport(serializer);
serializer.endTag(null, "forward");
serializer.endTag(null, "netguard");
serializer.endDocument();
serializer.flush();
}
示例12: getAllSMS
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* 获取手机短信并保存到 xml 中
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
*/
public static void getAllSMS(Context context) {
// 1.获取短信
// 1.1 获取内容解析者
ContentResolver resolver = context.getContentResolver();
// 1.2 获取内容提供者地址 sms,sms 表的地址:null 不写
// 1.3 获取查询路径
Uri uri = Uri.parse("content://sms");
// 1.4.查询操作
// projection : 查询的字段
// selection : 查询的条件
// selectionArgs : 查询条件的参数
// sortOrder : 排序
Cursor cursor = resolver.query(uri, new String[]{"address", "date", "type", "body"}, null, null, null);
// 设置最大进度
int count = cursor.getCount();//获取短信的个数
// 2.备份短信
// 2.1 获取 xml 序列器
XmlSerializer xmlSerializer = Xml.newSerializer();
try {
// 2.2 设置 xml 文件保存的路径
// os : 保存的位置
// encoding : 编码格式
xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
// 2.3 设置头信息
// standalone : 是否独立保存
xmlSerializer.startDocument("utf-8", true);
// 2.4 设置根标签
xmlSerializer.startTag(null, "smss");
// 1.5.解析 cursor
while (cursor.moveToNext()) {
SystemClock.sleep(1000);
// 2.5 设置短信的标签
xmlSerializer.startTag(null, "sms");
// 2.6 设置文本内容的标签
xmlSerializer.startTag(null, "address");
String address = cursor.getString(0);
// 2.7 设置文本内容
xmlSerializer.text(address);
xmlSerializer.endTag(null, "address");
xmlSerializer.startTag(null, "date");
String date = cursor.getString(1);
xmlSerializer.text(date);
xmlSerializer.endTag(null, "date");
xmlSerializer.startTag(null, "type");
String type = cursor.getString(2);
xmlSerializer.text(type);
xmlSerializer.endTag(null, "type");
xmlSerializer.startTag(null, "body");
String body = cursor.getString(3);
xmlSerializer.text(body);
xmlSerializer.endTag(null, "body");
xmlSerializer.endTag(null, "sms");
System.out.println("address:" + address + " date:" + date + " type:" + type + " body:" + body);
}
xmlSerializer.endTag(null, "smss");
xmlSerializer.endDocument();
// 2.8 将数据刷新到文件中
xmlSerializer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: getAllSMS
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* 获取手机短信并保存到xml中
* <p>需添加权限<uses-permission android:name="android.permission.READ_SMS"/>
* <p>需添加权限<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
*/
public static void getAllSMS(Context context) {
//1.获取短信
//1.1获取内容解析者
ContentResolver resolver = context.getContentResolver();
//1.2获取内容提供者地址 sms,sms表的地址:null 不写
//1.3获取查询路径
Uri uri = Uri.parse("content://sms");
//1.4.查询操作
//projection : 查询的字段
//selection : 查询的条件
//selectionArgs : 查询条件的参数
//sortOrder : 排序
Cursor cursor = resolver.query(uri, new String[]{"address", "date", "type", "body"}, null, null, null);
//设置最大进度
int count = cursor.getCount();//获取短信的个数
//2.备份短信
//2.1获取xml序列器
XmlSerializer xmlSerializer = Xml.newSerializer();
try {
//2.2设置xml文件保存的路径
//os : 保存的位置
//encoding : 编码格式
xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
//2.3设置头信息
//standalone : 是否独立保存
xmlSerializer.startDocument("utf-8", true);
//2.4设置根标签
xmlSerializer.startTag(null, "smss");
//1.5.解析cursor
while (cursor.moveToNext()) {
SystemClock.sleep(1000);
//2.5设置短信的标签
xmlSerializer.startTag(null, "sms");
//2.6设置文本内容的标签
xmlSerializer.startTag(null, "address");
String address = cursor.getString(0);
//2.7设置文本内容
xmlSerializer.text(address);
xmlSerializer.endTag(null, "address");
xmlSerializer.startTag(null, "date");
String date = cursor.getString(1);
xmlSerializer.text(date);
xmlSerializer.endTag(null, "date");
xmlSerializer.startTag(null, "type");
String type = cursor.getString(2);
xmlSerializer.text(type);
xmlSerializer.endTag(null, "type");
xmlSerializer.startTag(null, "body");
String body = cursor.getString(3);
xmlSerializer.text(body);
xmlSerializer.endTag(null, "body");
xmlSerializer.endTag(null, "sms");
System.out.println("address:" + address + " date:" + date + " type:" + type + " body:" + body);
}
xmlSerializer.endTag(null, "smss");
xmlSerializer.endDocument();
//2.8将数据刷新到文件中
xmlSerializer.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例14: doInBackground
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public Void doInBackground(Object... args) {
List<HistoricalRecord> historicalRecords = args[0];
String hostoryFileName = args[1];
try {
FileOutputStream fos = ActivityChooserModel.this.mContext.openFileOutput(hostoryFileName, 0);
XmlSerializer serializer = Xml.newSerializer();
try {
serializer.setOutput(fos, null);
serializer.startDocument("UTF-8", Boolean.valueOf(true));
serializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
int recordCount = historicalRecords.size();
for (int i = 0; i < recordCount; i++) {
HistoricalRecord record = (HistoricalRecord) historicalRecords.remove(0);
serializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
serializer.attribute(null, "activity", record.activity.flattenToString());
serializer.attribute(null, ActivityChooserModel.ATTRIBUTE_TIME, String.valueOf(record.time));
serializer.attribute(null, "weight", String.valueOf(record.weight));
serializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
}
serializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
serializer.endDocument();
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
} catch (IllegalArgumentException iae) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, iae);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e2) {
}
}
} catch (IllegalStateException ise) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, ise);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e3) {
}
}
} catch (IOException ioe) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, ioe);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e4) {
}
}
} catch (Throwable th) {
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e5) {
}
}
}
return null;
} catch (FileNotFoundException fnfe) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + hostoryFileName, fnfe);
return null;
}
}
示例15: writeMapXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* 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();
}