本文整理匯總了Java中org.xmlpull.v1.XmlSerializer.setFeature方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlSerializer.setFeature方法的具體用法?Java XmlSerializer.setFeature怎麽用?Java XmlSerializer.setFeature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xmlpull.v1.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.setFeature方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: writeToXmlImpl
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* Serializes all Blocks in the given list and writes them to the either the output stream or
* writer, whichever is not null.
*
* @param toSerialize A list of Blocks to serialize.
* @param os An OutputStream to write the blocks to.
* @param writer A writer to write the blocks to, if {@code os} is null.
* @param options The options to configure the block serialization. If omitted,
* {@link IOOptions#WRITE_ALL_DATA} will be used by default.
*
* @throws BlocklySerializerException
*/
public static void writeToXmlImpl(final @NonNull List<Block> toSerialize,
@Nullable OutputStream os, @Nullable Writer writer,
@Nullable IOOptions options)
throws BlocklySerializerException {
final IOOptions finalOptions = options == null ? IOOptions.WRITE_ALL_DATA : options;
XmlContentWriter contentWriter = new XmlContentWriter() {
@Override
public void write(XmlSerializer serializer) throws IOException {
serializer.setPrefix("", XML_NAMESPACE);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(XML_NAMESPACE, "xml");
for (int i = 0; i < toSerialize.size(); i++) {
toSerialize.get(i).serialize(serializer, true, finalOptions);
}
serializer.endTag(XML_NAMESPACE, "xml");
}
};
try {
if (os != null) {
writeXml(os, contentWriter);
} else {
writeXml(writer, contentWriter);
}
} catch (IOException e) {
throw new BlocklySerializerException(e);
}
}
示例3: 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");
}
}
示例4: 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;
}
示例5: initAndStartDocument
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
private static XmlSerializer initAndStartDocument(Writer output)
throws IllegalArgumentException, IllegalStateException, IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.setOutput(output);
serializer.startDocument(StringUtils.CHARSET_UTF8.name(), Boolean.TRUE);
return serializer;
}
示例6: 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();
}
示例7: writeListXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* 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, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
writeListXml(val, null, serializer);
serializer.endDocument();
}
示例8: 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();
}
示例9: writeListXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* 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();
}