Search in sources :

Example 41 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project AsmackService by rtreffer.

the class XmppInputStream method attach.

/**
     * Attach to an underlying input stream, usually done during feature
     * negotiation as some features require stream resets.
     * @param in InputStream The new underlying input stream.
     * @throws XmppTransportException In case of a transport error.
     */
public void attach(InputStream in) throws XmppTransportException {
    this.inputStream = in;
    try {
        parser = XMLUtils.getXMLPullParser();
        parser.setInput(in, "UTF-8");
    } catch (XmlPullParserException e) {
        throw new XmppTransportException("Can't initialize pull parser", e);
    }
}
Also used : XmppTransportException(com.googlecode.asmack.connection.XmppTransportException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 42 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class VectorDrawablePerformance method create.

public static VectorDrawable create(Resources resources, int rid) {
    try {
        final XmlPullParser parser = resources.getXml(rid);
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
        // Empty loop
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException("No start tag found");
        }
        final VectorDrawable drawable = new VectorDrawable();
        drawable.inflate(resources, parser, attrs);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOGCAT, "parser error", e);
    } catch (IOException e) {
        Log.e(LOGCAT, "parser error", e);
    }
    return null;
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 43 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class Resources_Delegate method getAnimation.

@LayoutlibDelegate
static XmlResourceParser getAnimation(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> v = getResourceValue(resources, id, mPlatformResourceFlag);
    if (v != null) {
        ResourceValue value = v.getSecond();
        XmlPullParser parser;
        try {
            File xml = new File(value.getValue());
            if (xml.isFile()) {
                // we need to create a pull parser around the layout XML file, and then
                // give that to our XmlBlockParser
                parser = ParserFactory.create(xml);
                return new BridgeXmlBlockParser(parser, resources.mContext, mPlatformResourceFlag[0]);
            }
        } catch (XmlPullParserException e) {
            Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + value.getValue(), e, null);
        // we'll return null below.
        } catch (FileNotFoundException e) {
        // this shouldn't happen since we check above.
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return null;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 44 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class ConfigGenerator method getEnumMap.

public static Map<String, Map<String, Integer>> getEnumMap(File path) {
    Map<String, Map<String, Integer>> map = Maps.newHashMap();
    try {
        XmlPullParser xmlPullParser = XmlPullParserFactory.newInstance().newPullParser();
        xmlPullParser.setInput(new FileInputStream(path), null);
        int eventType = xmlPullParser.getEventType();
        String attr = null;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (TAG_ATTR.equals(xmlPullParser.getName())) {
                    attr = xmlPullParser.getAttributeValue(null, ATTR_NAME);
                } else if (TAG_ENUM.equals(xmlPullParser.getName()) || TAG_FLAG.equals(xmlPullParser.getName())) {
                    String name = xmlPullParser.getAttributeValue(null, ATTR_NAME);
                    String value = xmlPullParser.getAttributeValue(null, ATTR_VALUE);
                    // Integer.decode cannot handle "ffffffff", see JDK issue 6624867
                    int i = (int) (long) Long.decode(value);
                    assert attr != null;
                    Map<String, Integer> attributeMap = map.get(attr);
                    if (attributeMap == null) {
                        attributeMap = Maps.newHashMap();
                        map.put(attr, attributeMap);
                    }
                    attributeMap.put(name, i);
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if (TAG_ATTR.equals(xmlPullParser.getName())) {
                    attr = null;
                }
            }
            eventType = xmlPullParser.next();
        }
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return map;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 45 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class ParserFactory method create.

@NonNull
private static XmlPullParser create(@NonNull InputStream stream, @Nullable String name, long size, boolean isLayout) throws XmlPullParserException {
    XmlPullParser parser = instantiateParser(name);
    stream = readAndClose(stream, name, size);
    parser.setInput(stream, ENCODING);
    if (isLayout) {
        try {
            return new LayoutParserWrapper(parser).peekTillLayoutStart();
        } catch (IOException e) {
            throw new XmlPullParserException(null, parser, e);
        }
    }
    return parser;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1071 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)440 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)186 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)99 PackageManager (android.content.pm.PackageManager)62 HashMap (java.util.HashMap)58 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)57 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)54 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43