Mechanical refactoring to new XML resolvers.
Related changes are introducing new TypedXmlSerializer and TypedXmlPullParser interfaces which offer efficient access to primitive attributes. This change is a purely mechanical refactoring to prepare for upcoming data format shifts, and has no behavior changes. Bug: 171832118 Test: manual Change-Id: I716193540e8a8baeca72cffbc2ba62bb1f731c49
This commit is contained in:
@@ -21,14 +21,15 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.TypedXmlPullParser;
|
||||
import android.util.TypedXmlSerializer;
|
||||
import android.util.Xml;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.internal.util.FastXmlSerializer;
|
||||
import com.android.internal.util.XmlUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -234,7 +235,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
public void writeUnknownObject(Object v, String name, XmlSerializer out)
|
||||
public void writeUnknownObject(Object v, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, IOException {
|
||||
if (v instanceof PersistableBundle) {
|
||||
out.startTag(null, TAG_PERSISTABLEMAP);
|
||||
@@ -248,6 +249,11 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
|
||||
/** @hide */
|
||||
public void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
|
||||
saveToXml(XmlUtils.makeTyped(out));
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void saveToXml(TypedXmlSerializer out) throws IOException, XmlPullParserException {
|
||||
unparcel();
|
||||
XmlUtils.writeMapXml(mMap, out, this);
|
||||
}
|
||||
@@ -255,7 +261,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
/** @hide */
|
||||
static class MyReadMapCallback implements XmlUtils.ReadMapCallback {
|
||||
@Override
|
||||
public Object readThisUnknownObjectXml(XmlPullParser in, String tag)
|
||||
public Object readThisUnknownObjectXml(TypedXmlPullParser in, String tag)
|
||||
throws XmlPullParserException, IOException {
|
||||
if (TAG_PERSISTABLEMAP.equals(tag)) {
|
||||
return restoreFromXml(in);
|
||||
@@ -290,6 +296,12 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
/** @hide */
|
||||
public static PersistableBundle restoreFromXml(XmlPullParser in) throws IOException,
|
||||
XmlPullParserException {
|
||||
return restoreFromXml(XmlUtils.makeTyped(in));
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static PersistableBundle restoreFromXml(TypedXmlPullParser in) throws IOException,
|
||||
XmlPullParserException {
|
||||
final int outerDepth = in.getDepth();
|
||||
final String startTag = in.getName();
|
||||
final String[] tagName = new String[1];
|
||||
@@ -355,7 +367,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
* @see #readFromStream
|
||||
*/
|
||||
public void writeToStream(@NonNull OutputStream outputStream) throws IOException {
|
||||
FastXmlSerializer serializer = new FastXmlSerializer();
|
||||
TypedXmlSerializer serializer = Xml.newFastSerializer();
|
||||
serializer.setOutput(outputStream, UTF_8.name());
|
||||
serializer.startTag(null, "bundle");
|
||||
try {
|
||||
@@ -378,7 +390,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
|
||||
public static PersistableBundle readFromStream(@NonNull InputStream inputStream)
|
||||
throws IOException {
|
||||
try {
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
TypedXmlPullParser parser = Xml.newFastPullParser();
|
||||
parser.setInput(inputStream, UTF_8.name());
|
||||
parser.next();
|
||||
return PersistableBundle.restoreFromXml(parser);
|
||||
|
||||
@@ -389,7 +389,7 @@ public class XmlUtils {
|
||||
@UnsupportedAppUsage
|
||||
public static final void writeMapXml(Map val, OutputStream out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
XmlSerializer serializer = new FastXmlSerializer();
|
||||
TypedXmlSerializer serializer = Xml.newFastSerializer();
|
||||
serializer.setOutput(out, StandardCharsets.UTF_8.name());
|
||||
serializer.startDocument(null, true);
|
||||
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
|
||||
@@ -412,7 +412,7 @@ public class XmlUtils {
|
||||
public static final void writeListXml(List val, OutputStream out)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
XmlSerializer serializer = Xml.newSerializer();
|
||||
TypedXmlSerializer serializer = Xml.newFastSerializer();
|
||||
serializer.setOutput(out, StandardCharsets.UTF_8.name());
|
||||
serializer.startDocument(null, true);
|
||||
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
|
||||
@@ -434,7 +434,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readMapXml
|
||||
*/
|
||||
public static final void writeMapXml(Map val, String name, XmlSerializer out)
|
||||
public static final void writeMapXml(Map val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
writeMapXml(val, name, out, null);
|
||||
}
|
||||
@@ -456,7 +456,7 @@ public class XmlUtils {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final void writeMapXml(Map val, String name, XmlSerializer out,
|
||||
public static final void writeMapXml(Map val, String name, TypedXmlSerializer out,
|
||||
WriteMapCallback callback) throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -490,7 +490,7 @@ public class XmlUtils {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final void writeMapXml(Map val, XmlSerializer out,
|
||||
public static final void writeMapXml(Map val, TypedXmlSerializer out,
|
||||
WriteMapCallback callback) throws XmlPullParserException, java.io.IOException {
|
||||
if (val == null) {
|
||||
return;
|
||||
@@ -519,7 +519,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final void writeListXml(List val, String name, XmlSerializer out)
|
||||
public static final void writeListXml(List val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
if (val == null) {
|
||||
@@ -543,7 +543,7 @@ public class XmlUtils {
|
||||
out.endTag(null, "list");
|
||||
}
|
||||
|
||||
public static final void writeSetXml(Set val, String name, XmlSerializer out)
|
||||
public static final void writeSetXml(Set val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
if (val == null) {
|
||||
out.startTag(null, "null");
|
||||
@@ -576,7 +576,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
*/
|
||||
public static final void writeByteArrayXml(byte[] val, String name,
|
||||
XmlSerializer out)
|
||||
TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -591,7 +591,7 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
out.text(HexEncoding.encodeToString(val).toLowerCase());
|
||||
|
||||
@@ -612,7 +612,7 @@ public class XmlUtils {
|
||||
* @see #readThisIntArrayXml
|
||||
*/
|
||||
public static final void writeIntArrayXml(int[] val, String name,
|
||||
XmlSerializer out)
|
||||
TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -627,11 +627,11 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
out.startTag(null, "item");
|
||||
out.attribute(null, "value", Integer.toString(val[i]));
|
||||
out.attributeInt(null, "value", val[i]);
|
||||
out.endTag(null, "item");
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readThisIntArrayXml
|
||||
*/
|
||||
public static final void writeLongArrayXml(long[] val, String name, XmlSerializer out)
|
||||
public static final void writeLongArrayXml(long[] val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -666,11 +666,11 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
out.startTag(null, "item");
|
||||
out.attribute(null, "value", Long.toString(val[i]));
|
||||
out.attributeLong(null, "value", val[i]);
|
||||
out.endTag(null, "item");
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readThisIntArrayXml
|
||||
*/
|
||||
public static final void writeDoubleArrayXml(double[] val, String name, XmlSerializer out)
|
||||
public static final void writeDoubleArrayXml(double[] val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -705,11 +705,11 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
out.startTag(null, "item");
|
||||
out.attribute(null, "value", Double.toString(val[i]));
|
||||
out.attributeDouble(null, "value", val[i]);
|
||||
out.endTag(null, "item");
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readThisIntArrayXml
|
||||
*/
|
||||
public static final void writeStringArrayXml(String[] val, String name, XmlSerializer out)
|
||||
public static final void writeStringArrayXml(String[] val, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
@@ -744,7 +744,7 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
out.startTag(null, "item");
|
||||
@@ -768,8 +768,8 @@ public class XmlUtils {
|
||||
* @see #writeValueXml
|
||||
* @see #readThisIntArrayXml
|
||||
*/
|
||||
public static final void writeBooleanArrayXml(boolean[] val, String name, XmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
public static final void writeBooleanArrayXml(boolean[] val, String name,
|
||||
TypedXmlSerializer out) throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
if (val == null) {
|
||||
out.startTag(null, "null");
|
||||
@@ -783,17 +783,23 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
final int N = val.length;
|
||||
out.attribute(null, "num", Integer.toString(N));
|
||||
out.attributeInt(null, "num", N);
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
out.startTag(null, "item");
|
||||
out.attribute(null, "value", Boolean.toString(val[i]));
|
||||
out.attributeBoolean(null, "value", val[i]);
|
||||
out.endTag(null, "item");
|
||||
}
|
||||
|
||||
out.endTag(null, "boolean-array");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final void writeValueXml(Object v, String name, XmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
writeValueXml(v, name, XmlUtils.makeTyped(out));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an object's value into an XmlSerializer. The value can later
|
||||
* be read back with readThisValueXml().
|
||||
@@ -810,7 +816,7 @@ public class XmlUtils {
|
||||
* @see #writeListXml
|
||||
* @see #readValueXml
|
||||
*/
|
||||
public static final void writeValueXml(Object v, String name, XmlSerializer out)
|
||||
public static final void writeValueXml(Object v, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
writeValueXml(v, name, out, null);
|
||||
}
|
||||
@@ -832,9 +838,8 @@ public class XmlUtils {
|
||||
* @see #writeListXml
|
||||
* @see #readValueXml
|
||||
*/
|
||||
private static final void writeValueXml(Object v, String name, XmlSerializer out,
|
||||
private static final void writeValueXml(Object v, String name, TypedXmlSerializer out,
|
||||
WriteMapCallback callback) throws XmlPullParserException, java.io.IOException {
|
||||
String typeStr;
|
||||
if (v == null) {
|
||||
out.startTag(null, "null");
|
||||
if (name != null) {
|
||||
@@ -851,15 +856,40 @@ public class XmlUtils {
|
||||
out.endTag(null, "string");
|
||||
return;
|
||||
} else if (v instanceof Integer) {
|
||||
typeStr = "int";
|
||||
out.startTag(null, "int");
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attributeInt(null, "value", (int) v);
|
||||
out.endTag(null, "int");
|
||||
} else if (v instanceof Long) {
|
||||
typeStr = "long";
|
||||
out.startTag(null, "long");
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attributeLong(null, "value", (long) v);
|
||||
out.endTag(null, "long");
|
||||
} else if (v instanceof Float) {
|
||||
typeStr = "float";
|
||||
out.startTag(null, "float");
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attributeFloat(null, "value", (float) v);
|
||||
out.endTag(null, "float");
|
||||
} else if (v instanceof Double) {
|
||||
typeStr = "double";
|
||||
out.startTag(null, "double");
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attributeDouble(null, "value", (double) v);
|
||||
out.endTag(null, "double");
|
||||
} else if (v instanceof Boolean) {
|
||||
typeStr = "boolean";
|
||||
out.startTag(null, "boolean");
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attributeBoolean(null, "value", (boolean) v);
|
||||
out.endTag(null, "boolean");
|
||||
} else if (v instanceof byte[]) {
|
||||
writeByteArrayXml((byte[])v, name, out);
|
||||
return;
|
||||
@@ -904,13 +934,6 @@ public class XmlUtils {
|
||||
} else {
|
||||
throw new RuntimeException("writeValueXml: unable to write value " + v);
|
||||
}
|
||||
|
||||
out.startTag(null, typeStr);
|
||||
if (name != null) {
|
||||
out.attribute(null, "name", name);
|
||||
}
|
||||
out.attribute(null, "value", v.toString());
|
||||
out.endTag(null, typeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -929,9 +952,8 @@ public class XmlUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
@UnsupportedAppUsage
|
||||
public static final HashMap<String, ?> readMapXml(InputStream in)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
TypedXmlPullParser parser = Xml.newFastPullParser();
|
||||
parser.setInput(in, StandardCharsets.UTF_8.name());
|
||||
return (HashMap<String, ?>) readValueXml(parser, new String[1]);
|
||||
}
|
||||
@@ -950,9 +972,8 @@ public class XmlUtils {
|
||||
* @see #writeListXml
|
||||
*/
|
||||
public static final ArrayList readListXml(InputStream in)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
TypedXmlPullParser parser = Xml.newFastPullParser();
|
||||
parser.setInput(in, StandardCharsets.UTF_8.name());
|
||||
return (ArrayList)readValueXml(parser, new String[1]);
|
||||
}
|
||||
@@ -975,8 +996,8 @@ public class XmlUtils {
|
||||
*/
|
||||
public static final HashSet readSetXml(InputStream in)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
parser.setInput(in, null);
|
||||
TypedXmlPullParser parser = Xml.newFastPullParser();
|
||||
parser.setInput(in, StandardCharsets.UTF_8.name());
|
||||
return (HashSet) readValueXml(parser, new String[1]);
|
||||
}
|
||||
|
||||
@@ -994,7 +1015,7 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readMapXml
|
||||
*/
|
||||
public static final HashMap<String, ?> readThisMapXml(XmlPullParser parser, String endTag,
|
||||
public static final HashMap<String, ?> readThisMapXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
return readThisMapXml(parser, endTag, name, null);
|
||||
}
|
||||
@@ -1014,10 +1035,9 @@ public class XmlUtils {
|
||||
* @see #readMapXml
|
||||
* @hide
|
||||
*/
|
||||
public static final HashMap<String, ?> readThisMapXml(XmlPullParser parser, String endTag,
|
||||
public static final HashMap<String, ?> readThisMapXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name, ReadMapCallback callback)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
int eventType = parser.getEventType();
|
||||
@@ -1043,10 +1063,9 @@ public class XmlUtils {
|
||||
* Like {@link #readThisMapXml}, but returns an ArrayMap instead of HashMap.
|
||||
* @hide
|
||||
*/
|
||||
public static final ArrayMap<String, ?> readThisArrayMapXml(XmlPullParser parser, String endTag,
|
||||
String[] name, ReadMapCallback callback)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
public static final ArrayMap<String, ?> readThisArrayMapXml(TypedXmlPullParser parser,
|
||||
String endTag, String[] name, ReadMapCallback callback)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
ArrayMap<String, Object> map = new ArrayMap<>();
|
||||
|
||||
int eventType = parser.getEventType();
|
||||
@@ -1082,7 +1101,7 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final ArrayList readThisListXml(XmlPullParser parser, String endTag,
|
||||
public static final ArrayList readThisListXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
return readThisListXml(parser, endTag, name, null, false);
|
||||
}
|
||||
@@ -1101,7 +1120,7 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
private static final ArrayList readThisListXml(XmlPullParser parser, String endTag,
|
||||
private static final ArrayList readThisListXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name, ReadMapCallback callback, boolean arrayMap)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
ArrayList list = new ArrayList();
|
||||
@@ -1143,8 +1162,8 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readSetXml
|
||||
*/
|
||||
public static final HashSet readThisSetXml(XmlPullParser parser, String endTag, String[] name)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
public static final HashSet readThisSetXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
return readThisSetXml(parser, endTag, name, null, false);
|
||||
}
|
||||
|
||||
@@ -1166,8 +1185,8 @@ public class XmlUtils {
|
||||
* @see #readSetXml
|
||||
* @hide
|
||||
*/
|
||||
private static final HashSet readThisSetXml(XmlPullParser parser, String endTag, String[] name,
|
||||
ReadMapCallback callback, boolean arrayMap)
|
||||
private static final HashSet readThisSetXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name, ReadMapCallback callback, boolean arrayMap)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
HashSet set = new HashSet();
|
||||
|
||||
@@ -1205,20 +1224,11 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #writeByteArrayXml
|
||||
*/
|
||||
public static final byte[] readThisByteArrayXml(XmlPullParser parser,
|
||||
public static final byte[] readThisByteArrayXml(TypedXmlPullParser parser,
|
||||
String endTag, String[] name)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Need num attribute in byte-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Not a number in num attribute in byte-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
|
||||
// 0 len byte array does not have a text in the XML tag. So, initialize to 0 len array.
|
||||
// For all other array lens, HexEncoding.decode() below overrides the array.
|
||||
@@ -1265,20 +1275,11 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final int[] readThisIntArrayXml(XmlPullParser parser,
|
||||
public static final int[] readThisIntArrayXml(TypedXmlPullParser parser,
|
||||
String endTag, String[] name)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Need num attribute in int-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Not a number in num attribute in int-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
parser.next();
|
||||
|
||||
int[] array = new int[num];
|
||||
@@ -1288,16 +1289,7 @@ public class XmlUtils {
|
||||
do {
|
||||
if (eventType == parser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
try {
|
||||
array[i] = Integer.parseInt(
|
||||
parser.getAttributeValue(null, "value"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Need value attribute in item");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Not a number in value attribute in item");
|
||||
}
|
||||
array[i] = parser.getAttributeInt(null, "value");
|
||||
} else {
|
||||
throw new XmlPullParserException(
|
||||
"Expected item tag at: " + parser.getName());
|
||||
@@ -1334,18 +1326,11 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final long[] readThisLongArrayXml(XmlPullParser parser,
|
||||
public static final long[] readThisLongArrayXml(TypedXmlPullParser parser,
|
||||
String endTag, String[] name)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need num attribute in long-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in num attribute in long-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
parser.next();
|
||||
|
||||
long[] array = new long[num];
|
||||
@@ -1355,13 +1340,7 @@ public class XmlUtils {
|
||||
do {
|
||||
if (eventType == parser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
try {
|
||||
array[i] = Long.parseLong(parser.getAttributeValue(null, "value"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need value attribute in item");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in value attribute in item");
|
||||
}
|
||||
array[i] = parser.getAttributeLong(null, "value");
|
||||
} else {
|
||||
throw new XmlPullParserException("Expected item tag at: " + parser.getName());
|
||||
}
|
||||
@@ -1395,17 +1374,10 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final double[] readThisDoubleArrayXml(XmlPullParser parser, String endTag,
|
||||
public static final double[] readThisDoubleArrayXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need num attribute in double-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in num attribute in double-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
parser.next();
|
||||
|
||||
double[] array = new double[num];
|
||||
@@ -1415,13 +1387,7 @@ public class XmlUtils {
|
||||
do {
|
||||
if (eventType == parser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
try {
|
||||
array[i] = Double.parseDouble(parser.getAttributeValue(null, "value"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need value attribute in item");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in value attribute in item");
|
||||
}
|
||||
array[i] = parser.getAttributeDouble(null, "value");
|
||||
} else {
|
||||
throw new XmlPullParserException("Expected item tag at: " + parser.getName());
|
||||
}
|
||||
@@ -1455,17 +1421,10 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final String[] readThisStringArrayXml(XmlPullParser parser, String endTag,
|
||||
public static final String[] readThisStringArrayXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need num attribute in string-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in num attribute in string-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
parser.next();
|
||||
|
||||
String[] array = new String[num];
|
||||
@@ -1475,13 +1434,7 @@ public class XmlUtils {
|
||||
do {
|
||||
if (eventType == parser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
try {
|
||||
array[i] = parser.getAttributeValue(null, "value");
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need value attribute in item");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in value attribute in item");
|
||||
}
|
||||
array[i] = parser.getAttributeValue(null, "value");
|
||||
} else {
|
||||
throw new XmlPullParserException("Expected item tag at: " + parser.getName());
|
||||
}
|
||||
@@ -1515,17 +1468,10 @@ public class XmlUtils {
|
||||
*
|
||||
* @see #readListXml
|
||||
*/
|
||||
public static final boolean[] readThisBooleanArrayXml(XmlPullParser parser, String endTag,
|
||||
public static final boolean[] readThisBooleanArrayXml(TypedXmlPullParser parser, String endTag,
|
||||
String[] name) throws XmlPullParserException, java.io.IOException {
|
||||
|
||||
int num;
|
||||
try {
|
||||
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need num attribute in string-array");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in num attribute in string-array");
|
||||
}
|
||||
int num = parser.getAttributeInt(null, "num");
|
||||
parser.next();
|
||||
|
||||
boolean[] array = new boolean[num];
|
||||
@@ -1535,13 +1481,7 @@ public class XmlUtils {
|
||||
do {
|
||||
if (eventType == parser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
try {
|
||||
array[i] = Boolean.parseBoolean(parser.getAttributeValue(null, "value"));
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need value attribute in item");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException("Not a number in value attribute in item");
|
||||
}
|
||||
array[i] = parser.getAttributeBoolean(null, "value");
|
||||
} else {
|
||||
throw new XmlPullParserException("Expected item tag at: " + parser.getName());
|
||||
}
|
||||
@@ -1577,7 +1517,7 @@ public class XmlUtils {
|
||||
* @see #readListXml
|
||||
* @see #writeValueXml
|
||||
*/
|
||||
public static final Object readValueXml(XmlPullParser parser, String[] name)
|
||||
public static final Object readValueXml(TypedXmlPullParser parser, String[] name)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
int eventType = parser.getEventType();
|
||||
@@ -1598,7 +1538,7 @@ public class XmlUtils {
|
||||
"Unexpected end of document");
|
||||
}
|
||||
|
||||
private static final Object readThisValueXml(XmlPullParser parser, String[] name,
|
||||
private static final Object readThisValueXml(TypedXmlPullParser parser, String[] name,
|
||||
ReadMapCallback callback, boolean arrayMap)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
final String valueName = parser.getAttributeValue(null, "name");
|
||||
@@ -1714,28 +1654,20 @@ public class XmlUtils {
|
||||
"Unexpected end of document in <" + tagName + ">");
|
||||
}
|
||||
|
||||
private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
|
||||
throws XmlPullParserException, java.io.IOException
|
||||
{
|
||||
try {
|
||||
if (tagName.equals("int")) {
|
||||
return Integer.parseInt(parser.getAttributeValue(null, "value"));
|
||||
} else if (tagName.equals("long")) {
|
||||
return Long.valueOf(parser.getAttributeValue(null, "value"));
|
||||
} else if (tagName.equals("float")) {
|
||||
return new Float(parser.getAttributeValue(null, "value"));
|
||||
} else if (tagName.equals("double")) {
|
||||
return new Double(parser.getAttributeValue(null, "value"));
|
||||
} else if (tagName.equals("boolean")) {
|
||||
return Boolean.valueOf(parser.getAttributeValue(null, "value"));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Not a number in value attribute in <" + tagName + ">");
|
||||
private static final Object readThisPrimitiveValueXml(TypedXmlPullParser parser, String tagName)
|
||||
throws XmlPullParserException, java.io.IOException {
|
||||
if (tagName.equals("int")) {
|
||||
return parser.getAttributeInt(null, "value");
|
||||
} else if (tagName.equals("long")) {
|
||||
return parser.getAttributeLong(null, "value");
|
||||
} else if (tagName.equals("float")) {
|
||||
return parser.getAttributeFloat(null, "value");
|
||||
} else if (tagName.equals("double")) {
|
||||
return parser.getAttributeDouble(null, "value");
|
||||
} else if (tagName.equals("boolean")) {
|
||||
return parser.getAttributeBoolean(null, "value");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1784,6 +1716,9 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
public static int readIntAttribute(XmlPullParser in, String name, int defaultValue) {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
return ((TypedXmlPullParser) in).getAttributeInt(null, name, defaultValue);
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
@@ -1796,6 +1731,13 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
public static int readIntAttribute(XmlPullParser in, String name) throws IOException {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
try {
|
||||
return ((TypedXmlPullParser) in).getAttributeInt(null, name);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new ProtocolException(e.getMessage());
|
||||
}
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
@@ -1806,10 +1748,17 @@ public class XmlUtils {
|
||||
|
||||
public static void writeIntAttribute(XmlSerializer out, String name, int value)
|
||||
throws IOException {
|
||||
if (out instanceof TypedXmlSerializer) {
|
||||
((TypedXmlSerializer) out).attributeInt(null, name, value);
|
||||
return;
|
||||
}
|
||||
out.attribute(null, name, Integer.toString(value));
|
||||
}
|
||||
|
||||
public static long readLongAttribute(XmlPullParser in, String name, long defaultValue) {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
return ((TypedXmlPullParser) in).getAttributeLong(null, name, defaultValue);
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
@@ -1822,6 +1771,13 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
public static long readLongAttribute(XmlPullParser in, String name) throws IOException {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
try {
|
||||
return ((TypedXmlPullParser) in).getAttributeLong(null, name);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new ProtocolException(e.getMessage());
|
||||
}
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
@@ -1832,10 +1788,21 @@ public class XmlUtils {
|
||||
|
||||
public static void writeLongAttribute(XmlSerializer out, String name, long value)
|
||||
throws IOException {
|
||||
if (out instanceof TypedXmlSerializer) {
|
||||
((TypedXmlSerializer) out).attributeLong(null, name, value);
|
||||
return;
|
||||
}
|
||||
out.attribute(null, name, Long.toString(value));
|
||||
}
|
||||
|
||||
public static float readFloatAttribute(XmlPullParser in, String name) throws IOException {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
try {
|
||||
return ((TypedXmlPullParser) in).getAttributeFloat(null, name);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new ProtocolException(e.getMessage());
|
||||
}
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
try {
|
||||
return Float.parseFloat(value);
|
||||
@@ -1846,16 +1813,22 @@ public class XmlUtils {
|
||||
|
||||
public static void writeFloatAttribute(XmlSerializer out, String name, float value)
|
||||
throws IOException {
|
||||
if (out instanceof TypedXmlSerializer) {
|
||||
((TypedXmlSerializer) out).attributeFloat(null, name, value);
|
||||
return;
|
||||
}
|
||||
out.attribute(null, name, Float.toString(value));
|
||||
}
|
||||
|
||||
public static boolean readBooleanAttribute(XmlPullParser in, String name) {
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
return Boolean.parseBoolean(value);
|
||||
return readBooleanAttribute(in, name, false);
|
||||
}
|
||||
|
||||
public static boolean readBooleanAttribute(XmlPullParser in, String name,
|
||||
boolean defaultValue) {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
return ((TypedXmlPullParser) in).getAttributeBoolean(null, name, defaultValue);
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
@@ -1866,6 +1839,10 @@ public class XmlUtils {
|
||||
|
||||
public static void writeBooleanAttribute(XmlSerializer out, String name, boolean value)
|
||||
throws IOException {
|
||||
if (out instanceof TypedXmlSerializer) {
|
||||
((TypedXmlSerializer) out).attributeBoolean(null, name, value);
|
||||
return;
|
||||
}
|
||||
out.attribute(null, name, Boolean.toString(value));
|
||||
}
|
||||
|
||||
@@ -1893,6 +1870,13 @@ public class XmlUtils {
|
||||
}
|
||||
|
||||
public static byte[] readByteArrayAttribute(XmlPullParser in, String name) {
|
||||
if (in instanceof TypedXmlPullParser) {
|
||||
try {
|
||||
return ((TypedXmlPullParser) in).getAttributeBytesBase64(null, name);
|
||||
} catch (XmlPullParserException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final String value = in.getAttributeValue(null, name);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
return Base64.decode(value, Base64.DEFAULT);
|
||||
@@ -1904,6 +1888,10 @@ public class XmlUtils {
|
||||
public static void writeByteArrayAttribute(XmlSerializer out, String name, byte[] value)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
if (out instanceof TypedXmlSerializer) {
|
||||
((TypedXmlSerializer) out).attributeBytesBase64(null, name, value);
|
||||
return;
|
||||
}
|
||||
out.attribute(null, name, Base64.encodeToString(value, Base64.DEFAULT));
|
||||
}
|
||||
}
|
||||
@@ -1941,7 +1929,7 @@ public class XmlUtils {
|
||||
* @throws IOException on XmlSerializer serialization errors.
|
||||
* @hide
|
||||
*/
|
||||
public void writeUnknownObject(Object v, String name, XmlSerializer out)
|
||||
public void writeUnknownObject(Object v, String name, TypedXmlSerializer out)
|
||||
throws XmlPullParserException, IOException;
|
||||
}
|
||||
|
||||
@@ -1958,7 +1946,7 @@ public class XmlUtils {
|
||||
* @throws IOException on XmlPullParser serialization errors.
|
||||
* @hide
|
||||
*/
|
||||
public Object readThisUnknownObjectXml(XmlPullParser in, String tag)
|
||||
public Object readThisUnknownObjectXml(TypedXmlPullParser in, String tag)
|
||||
throws XmlPullParserException, IOException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1683,7 +1683,7 @@ class ShortcutPackage extends ShortcutPackageItem {
|
||||
if (cat != null && cat.size() > 0) {
|
||||
out.startTag(null, TAG_CATEGORIES);
|
||||
XmlUtils.writeStringArrayXml(cat.toArray(new String[cat.size()]),
|
||||
NAME_CATEGORIES, out);
|
||||
NAME_CATEGORIES, XmlUtils.makeTyped(out));
|
||||
out.endTag(null, TAG_CATEGORIES);
|
||||
}
|
||||
}
|
||||
@@ -1904,7 +1904,7 @@ class ShortcutPackage extends ShortcutPackageItem {
|
||||
if (NAME_CATEGORIES.equals(ShortcutService.parseStringAttribute(parser,
|
||||
ATTR_NAME_XMLUTILS))) {
|
||||
final String[] ar = XmlUtils.readThisStringArrayXml(
|
||||
parser, TAG_STRING_ARRAY_XMLUTILS, null);
|
||||
XmlUtils.makeTyped(parser), TAG_STRING_ARRAY_XMLUTILS, null);
|
||||
categories = new ArraySet<>(ar.length);
|
||||
for (int i = 0; i < ar.length; i++) {
|
||||
categories.add(ar[i]);
|
||||
|
||||
Reference in New Issue
Block a user