Java Code Examples for org.xmlpull.v1.XmlPullParserException

The following examples show how to use org.xmlpull.v1.XmlPullParserException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: EFRConnect-android   Source File: BluetoothXmlParser.java    License: Apache License 2.0 6 votes vote down vote up
private Characteristic readCharacteristic(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, Consts.TAG_CHARACTERISTIC);

    Characteristic characteristic = new Characteristic();

    String characteristicName = readCharacteristicName(parser);
    characteristic.setName(characteristicName);

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();
        if (name.equals(Consts.TAG_INFORMATIVE_TEXT)) {
            String summary = readSummary(parser);
            characteristic.setSummary(summary);
        } else if (name.equals(Consts.TAG_VALUE)) {
            ArrayList<Field> fields = readFieldValue(parser, characteristic);
        } else {
            skip(parser);
        }
    }

    return characteristic;
}
 
Example 2
Source Project: Connect-SDK-Android-Core   Source File: PListParser.java    License: Apache License 2.0 6 votes vote down vote up
private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
    if (parser.getEventType() != XmlPullParser.START_TAG) {
        throw new IllegalStateException();
    }
    int depth = 1;
    while (depth != 0) {
        switch (parser.next()) {
        case XmlPullParser.END_TAG:
            depth--;
            break;
        case XmlPullParser.START_TAG:
            depth++;
            break;
        }
    }
}
 
Example 3
Source Project: openboard   Source File: KeyboardLayoutSet.java    License: GNU General Public License v3.0 6 votes vote down vote up
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
    final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
            + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
    final int xmlId = getXmlId(resources, layoutSetName);
    final XmlResourceParser parser = resources.getXml(xmlId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
            // the script Id from it.
            parser.next();
            final String tag = parser.getName();
            if (TAG_FEATURE.equals(tag)) {
                return readScriptIdFromTagFeature(resources, parser);
            }
        }
    } catch (final IOException | XmlPullParserException e) {
        throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
    } finally {
        parser.close();
    }
    // If the tag is not found, then the default script is Latin.
    return ScriptUtils.SCRIPT_LATIN;
}
 
Example 4
Source Project: openboard   Source File: KeyboardBuilder.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void parseKey(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_KEY, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final String keySpec = keyStyle.getString(keyAttr, R.styleable.Keyboard_Key_keySpec);
    if (TextUtils.isEmpty(keySpec)) {
        throw new ParseException("Empty keySpec", parser);
    }
    final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) {
        startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
                key, Arrays.toString(key.getMoreKeys()));
    }
    XmlParseUtils.checkEndTag(TAG_KEY, parser);
    endKey(key);
}
 
Example 5
Source Project: android-gpx-parser   Source File: GPXParser.java    License: Apache License 2.0 6 votes vote down vote up
private Copyright readCopyright(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, namespace, TAG_COPYRIGHT);

    Copyright.Builder copyrightBuilder = new Copyright.Builder();
    copyrightBuilder.setAuthor(parser.getAttributeValue(namespace, TAG_AUTHOR));

    while (loopMustContinue(parser.next())) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case TAG_YEAR:
                copyrightBuilder.setYear(readYear(parser));
                break;
            case TAG_LICENSE:
                copyrightBuilder.setLicense(readString(parser, TAG_LICENSE));
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, namespace, TAG_COPYRIGHT);
    return copyrightBuilder.build();
}
 
Example 6
Source Project: android_9.0.0_r45   Source File: PersistentDataStore.java    License: Apache License 2.0 6 votes vote down vote up
private void loadFromXml(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    XmlUtils.beginDocument(parser, TAG_DISPLAY_MANAGER_STATE);
    final int outerDepth = parser.getDepth();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        if (parser.getName().equals(TAG_REMEMBERED_WIFI_DISPLAYS)) {
            loadRememberedWifiDisplaysFromXml(parser);
        }
        if (parser.getName().equals(TAG_DISPLAY_STATES)) {
            loadDisplaysFromXml(parser);
        }
        if (parser.getName().equals(TAG_STABLE_DEVICE_VALUES)) {
            mStableDeviceValues.loadFromXml(parser);
        }
        if (parser.getName().equals(TAG_BRIGHTNESS_CONFIGURATIONS)) {
            mBrightnessConfigurations.loadFromXml(parser);
        }
    }
}
 
Example 7
Source Project: cwac-netsecurity   Source File: XmlConfigSource.java    License: Apache License 2.0 6 votes vote down vote up
private Domain parseDomain(XmlResourceParser parser, Set<String> seenDomains)
        throws IOException, XmlPullParserException, ParserException {
    boolean includeSubdomains =
            parser.getAttributeBooleanValue(null, "includeSubdomains", false);
    if (parser.next() != XmlPullParser.TEXT) {
        throw new ParserException(parser, "Domain name missing");
    }
    String domain = parser.getText().trim().toLowerCase(Locale.US);
    if (parser.next() != XmlPullParser.END_TAG) {
        throw new ParserException(parser, "domain contains additional elements");
    }
    // Domains are matched using a most specific match, so don't allow duplicates.
    // includeSubdomains isn't relevant here, both android.com + subdomains and android.com
    // match for android.com equally. Do not allow any duplicates period.
    if (!seenDomains.add(domain)) {
        throw new ParserException(parser, domain + " has already been specified");
    }
    return new Domain(domain, includeSubdomains);
}
 
Example 8
Source Project: trekarta   Source File: KmlParser.java    License: GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static FileDataSource readKml(XmlPullParser parser) throws XmlPullParserException, IOException {
    FileDataSource dataSource = null;
    parser.require(XmlPullParser.START_TAG, NS, KmlFile.TAG_KML);
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        // Both folder and document can be root containers
        if (name.equals(KmlFile.TAG_DOCUMENT) || name.equals(KmlFile.TAG_FOLDER)) {
            dataSource = readDocument(parser, name);
        } else {
            skip(parser);
        }
    }
    if (dataSource == null)
        throw new XmlPullParserException("No valid data", parser, null);
    return dataSource;
}
 
Example 9
Source Project: Trebuchet   Source File: AutoInstallsLayout.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses the layout and returns the number of elements added on the homescreen.
 */
protected int parseLayout(int layoutId, ArrayList<Long> screenIds)
        throws XmlPullParserException, IOException {
    XmlResourceParser parser = mSourceRes.getXml(layoutId);
    beginDocument(parser, mRootTag);
    final int depth = parser.getDepth();
    int type;
    HashMap<String, TagParser> tagParserMap = getLayoutElementsMap();
    int count = 0;

    while (((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        count += parseAndAddNode(parser, tagParserMap, screenIds);
    }
    return count;
}
 
Example 10
Source Project: android_9.0.0_r45   Source File: XmlConfigSource.java    License: Apache License 2.0 6 votes vote down vote up
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
        boolean defaultOverridePins)
        throws IOException, XmlPullParserException, ParserException {
    boolean overridePins =
            parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
    int sourceId = parser.getAttributeResourceValue(null, "src", -1);
    String sourceString = parser.getAttributeValue(null, "src");
    CertificateSource source = null;
    if (sourceString == null) {
        throw new ParserException(parser, "certificates element missing src attribute");
    }
    if (sourceId != -1) {
        // TODO: Cache ResourceCertificateSources by sourceId
        source = new ResourceCertificateSource(sourceId, mContext);
    } else if ("system".equals(sourceString)) {
        source = SystemCertificateSource.getInstance();
    } else if ("user".equals(sourceString)) {
        source = UserCertificateSource.getInstance();
    } else {
        throw new ParserException(parser, "Unknown certificates src. "
                + "Should be one of system|user|@resourceVal");
    }
    XmlUtils.skipCurrentTag(parser);
    return new CertificatesEntryRef(source, overridePins);
}
 
Example 11
Source Project: simple-keyboard   Source File: KeyboardBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void parseKeyStyle(final XmlPullParser parser, final boolean skip)
        throws XmlPullParserException, IOException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyStyleAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard_KeyStyle);
    final TypedArray keyAttrs = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) {
            throw new XmlParseUtils.ParseException("<" + TAG_KEY_STYLE
                    + "/> needs styleName attribute", parser);
        }
        if (DEBUG) {
            startEndTag("<%s styleName=%s />%s", TAG_KEY_STYLE,
                    keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName),
                    skip ? " skipped" : "");
        }
        if (!skip) {
            mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser);
        }
    } finally {
        keyStyleAttr.recycle();
        keyAttrs.recycle();
    }
    XmlParseUtils.checkEndTag(TAG_KEY_STYLE, parser);
}
 
Example 12
Source Project: a   Source File: XmlUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read a flattened object from an XmlPullParser.  The XML data could
 * previously have been written with writeMapXml(), writeListXml(), or
 * writeValueXml().  The XmlPullParser must be positioned <em>at</em> the
 * tag that defines the value.
 *
 * @param parser The XmlPullParser from which to read the object.
 * @param name   An array of one string, used to return the name attribute
 *               of the value's tag.
 * @return Object The newly generated value object.
 * @see #readMapXml
 * @see #readListXml
 * @see #writeValueXml
 */
public static Object readValueXml(XmlPullParser parser, String[] name)
        throws XmlPullParserException, java.io.IOException {
    int eventType = parser.getEventType();
    do {
        if (eventType == parser.START_TAG) {
            return readThisValueXml(parser, name, null);
        } else if (eventType == parser.END_TAG) {
            throw new XmlPullParserException(
                    "Unexpected end tag at: " + parser.getName());
        } else if (eventType == parser.TEXT) {
            throw new XmlPullParserException(
                    "Unexpected text: " + parser.getText());
        }
        eventType = parser.next();
    } while (eventType != parser.END_DOCUMENT);

    throw new XmlPullParserException(
            "Unexpected end of document");
}
 
Example 13
Source Project: apkReSign   Source File: AXmlResourceParser.java    License: Apache License 2.0 6 votes vote down vote up
public String nextText() throws XmlPullParserException,IOException {
	if(getEventType()!=START_TAG) {
		throw new XmlPullParserException("Parser must be on START_TAG to read next text.",this,null);
	}
	int eventType=next();
	if (eventType==TEXT) {
		String result=getText();
		eventType=next();
		if (eventType!=END_TAG) {
			throw new XmlPullParserException("Event TEXT must be immediately followed by END_TAG.",this,null);
		}
		return result;
	} else if (eventType==END_TAG) {
		return "";
	} else {
		throw new XmlPullParserException("Parser must be on START_TAG or TEXT to read text.",this,null);
	}
}
 
Example 14
Source Project: simple-keyboard   Source File: KeyboardBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void parseMerge(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (DEBUG) startTag("<%s>", TAG_MERGE);
    while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
        final int event = parser.next();
        if (event == XmlPullParser.START_TAG) {
            final String tag = parser.getName();
            if (TAG_MERGE.equals(tag)) {
                if (row == null) {
                    parseKeyboardContent(parser, skip);
                } else {
                    parseRowContent(parser, row, skip);
                }
                return;
            }
            throw new XmlParseUtils.ParseException(
                    "Included keyboard layout must have <merge> root element", parser);
        }
    }
}
 
Example 15
Source Project: ONVIF-Java   Source File: OnvifUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Util method for parsing.
 * Retrieve the XAddrs from the XmlPullParser given.
 */
public static String retrieveXAddrs(XmlPullParser xpp) throws IOException, XmlPullParserException {
    String result = "";
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {

        if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("XAddrs")) {
            xpp.next();
            result = xpp.getText();
            break;
        }
        eventType = xpp.next();
    }

    return result;
}
 
Example 16
Source Project: cwac-netsecurity   Source File: XmlUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Read an ArrayList object from an XmlPullParser.  The XML data could
 * previously have been generated by writeListXml().  The XmlPullParser
 * must be positioned <em>after</em> the tag that begins the list.
 *
 * @param parser The XmlPullParser from which to read the list data.
 * @param endTag Name of the tag that will end the list, usually "list".
 * @param name An array of one string, used to return the name attribute
 *             of the list's tag.
 *
 * @return HashMap The newly generated list.
 *
 * @see # readListXml
 */
private static final ArrayList readThisListXml(XmlPullParser parser, String endTag,
        String[] name, ReadMapCallback callback, boolean arrayMap)
        throws XmlPullParserException, IOException {
    ArrayList list = new ArrayList();

    int eventType = parser.getEventType();
    do {
        if (eventType == parser.START_TAG) {
            Object val = readThisValueXml(parser, name, callback, arrayMap);
            list.add(val);
            //System.out.println("Adding to list: " + val);
        } else if (eventType == parser.END_TAG) {
            if (parser.getName().equals(endTag)) {
                return list;
            }
            throw new XmlPullParserException(
                "Expected " + endTag + " end tag at: " + parser.getName());
        }
        eventType = parser.next();
    } while (eventType != parser.END_DOCUMENT);

    throw new XmlPullParserException(
        "Document ended before " + endTag + " end tag");
}
 
Example 17
Source Project: android-gpx-parser   Source File: GPXParser.java    License: Apache License 2.0 6 votes vote down vote up
private Link readLink(XmlPullParser parser) throws IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG, namespace, TAG_LINK);

    Link.Builder linkBuilder = new Link.Builder();
    linkBuilder.setLinkHref(parser.getAttributeValue(namespace, TAG_HREF));

    while (loopMustContinue(parser.next())) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case TAG_TEXT:
                linkBuilder.setLinkText(readString(parser, TAG_TEXT));
                break;
            case TAG_TYPE:
                linkBuilder.setLinkType(readString(parser, TAG_TYPE));
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, namespace, TAG_LINK);
    return linkBuilder.build();
}
 
Example 18
Source Project: Openfire   Source File: SocketReadingMode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * After SASL authentication was successful we should open a new stream and offer
 * new stream features such as resource binding and session establishment. Notice that
 * resource binding and session establishment should only be offered to clients (i.e. not
 * to servers or external components)
 */
protected void saslSuccessful() throws XmlPullParserException, IOException {
    StringBuilder sb = new StringBuilder(420);
    sb.append(geStreamHeader());
    sb.append("<stream:features>");

    // Include specific features such as resource binding and session establishment
    // for client sessions
    String specificFeatures = socketReader.session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");
    socketReader.connection.deliverRawText(sb.toString());
}
 
Example 19
private void loadAndSetupScene() throws IOException, XmlPullParserException {
	scene = new Scene(getClass().getResource("example17.2.scene.xml"), getClass(), "example17.2.");
	
	nodes = new ArrayList<>();
	nodes.add(scene.findNode("cube"));
	nodes.add(scene.findNode("rightBar"));
	nodes.add(scene.findNode("leaningBar"));
	nodes.add(scene.findNode("spinBar"));
	nodes.add(scene.findNode("diorama"));
	nodes.add(scene.findNode("floor"));
	
	lightNumBinder = new UniformIntBinder();
	lightProjMatBinder = new UniformMat4Binder();
	camLightPosBinder = new UniformVec3Binder();
	
	for(SceneNode node : nodes) {
		lightNumBinder.associateWithProgram(node.getProgram(), "numberOfLights");
		lightProjMatBinder.associateWithProgram(node.getProgram(), "cameraToLightProjMatrix");
		camLightPosBinder.associateWithProgram(node.getProgram(), "cameraSpaceProjLightPos");
		
		node.setStateBinder(lightNumBinder);
		node.setStateBinder(lightProjMatBinder);
		node.setStateBinder(camLightPosBinder);
	}
	
	spinBarOrient = nodes.get(3).getOrient();
	
	unlit = scene.findProgram("p_unlit");
	unlitModelToCameraMatrixUniform = glGetUniformLocation(unlit.getProgram(), "modelToCameraMatrix");
	unlitObjectColorUniform = glGetUniformLocation(unlit.getProgram(), "objectColor");
	
	colored = scene.findProgram("p_colored");
	coloredModelToCameraMatrixUniform = glGetUniformBlockIndex(colored.getProgram(), "modelToCameraMatrix");
	
	sphereMesh = scene.findMesh("m_sphere");
	axesMesh = scene.findMesh("m_axes");
}
 
Example 20
Source Project: android_9.0.0_r45   Source File: SELinuxMMAC.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loop over a signer tag looking for seinfo, package and cert tags. A {@link Policy}
 * instance will be created and returned in the process. During the pass all other
 * tag elements will be skipped.
 *
 * @param parser an XmlPullParser object representing a signer element.
 * @return the constructed {@link Policy} instance
 * @throws IOException
 * @throws XmlPullParserException
 * @throws IllegalArgumentException if any of the validation checks fail while
 *         parsing tag values.
 * @throws IllegalStateException if any of the invariants fail when constructing
 *         the {@link Policy} instance.
 */
private static Policy readSignerOrThrow(XmlPullParser parser) throws IOException,
        XmlPullParserException {

    parser.require(XmlPullParser.START_TAG, null, "signer");
    Policy.PolicyBuilder pb = new Policy.PolicyBuilder();

    // Check for a cert attached to the signer tag. We allow a signature
    // to appear as an attribute as well as those attached to cert tags.
    String cert = parser.getAttributeValue(null, "signature");
    if (cert != null) {
        pb.addSignature(cert);
    }

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }

        String tagName = parser.getName();
        if ("seinfo".equals(tagName)) {
            String seinfo = parser.getAttributeValue(null, "value");
            pb.setGlobalSeinfoOrThrow(seinfo);
            readSeinfo(parser);
        } else if ("package".equals(tagName)) {
            readPackageOrThrow(parser, pb);
        } else if ("cert".equals(tagName)) {
            String sig = parser.getAttributeValue(null, "signature");
            pb.addSignature(sig);
            readCert(parser);
        } else {
            skip(parser);
        }
    }

    return pb.build();
}
 
Example 21
Source Project: org.hl7.fhir.core   Source File: XmlParserBase.java    License: Apache License 2.0 5 votes vote down vote up
protected Resource parseResourceContained(XmlPullParser xpp) throws IOException, FHIRFormatError, XmlPullParserException  {
	next(xpp);
	int eventType = nextNoWhitespace(xpp);
	if (eventType == XmlPullParser.START_TAG) { 
		Resource r = (Resource) parseResource(xpp);
		nextNoWhitespace(xpp);
		next(xpp);
		return r;
	} else {
		unknownContent(xpp);
		return null;
	}
}
 
Example 22
/** @see MinioClient#putObject(String, String, InputStream, String) */
void putObject(String objectName, InputStream stream, String contentType)
    throws InvalidBucketNameException, NoSuchAlgorithmException, IOException, InvalidKeyException,
        NoResponseException, XmlPullParserException, ErrorResponseException, InternalException,
        InvalidArgumentException, InsufficientDataException {
  LOG.trace("Putting object '{}' in bucket '{}' ...", objectName, bucketName);
  minioClient.putObject(bucketName, objectName, stream, contentType);
  LOG.debug("Put object '{}' in bucket '{}'", objectName, bucketName);
}
 
Example 23
/**
 * Processes an AppManifest which is within the given {@link File}.
 * 
 * @param	apkFile					the AppManifest within the given APK will be parsed.
 * @throws	IOException				if an I/O error occurs.
 * @throws	XmlPullParserException	can occur due to a malformed manifest.
 * @see		{@link ProcessManifest#ProcessManifest(InputStream)}
 */
public ProcessManifest(File apkFile) throws IOException, XmlPullParserException {
	this.apk = new ApkHandler(apkFile);
	InputStream is = null;
	try {
		is = this.apk.getInputStream("AndroidManifest.xml");
		this.handle(is);
	}
	finally {
		if (is != null)
			is.close();
	}
}
 
Example 24
Source Project: JobSchedulerCompat   Source File: XmlUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Flatten a byte[] into an XmlSerializer.  The list can later be read back
 * with readThisByteArrayXml().
 *
 * @param val The byte array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 */
public static final void writeByteArrayXml(byte[] val, String name,
        XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "byte-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    StringBuilder sb = new StringBuilder(val.length*2);
    for (int i=0; i<N; i++) {
        int b = val[i];
        int h = b>>4;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
        h = b&0xff;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
Example 25
Source Project: android-gpx-parser   Source File: GPXParser.java    License: Apache License 2.0 5 votes vote down vote up
private String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
    String result = "";
    if (parser.next() == XmlPullParser.TEXT) {
        result = parser.getText();
        parser.nextTag();
    }
    return result;
}
 
Example 26
private static List<WrappedApplicationKey> readWrappedApplicationKeys(XmlPullParser parser)
        throws IOException, XmlPullParserException, KeyChainSnapshotParserException {
    parser.require(XmlPullParser.START_TAG, NAMESPACE, TAG_APPLICATION_KEYS);
    ArrayList<WrappedApplicationKey> keys = new ArrayList<>();
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        keys.add(readWrappedApplicationKey(parser));
    }
    parser.require(XmlPullParser.END_TAG, NAMESPACE, TAG_APPLICATION_KEYS);
    return keys;
}
 
Example 27
Source Project: JAADAS   Source File: SourceToSinksTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * very simple testcase 
 * 
 * @throws IOException
 * @throws XmlPullParserException
 */
@Test(timeout=300000)
public void runSourceToSinkTest1()  throws IOException, XmlPullParserException {
	res = null;
	res = analyzeAPKFile("testAPKs/SourceSinkDefinitions/SourceToSink1.apk",
			"testAPKs/SourceSinkDefinitions/sourcesAndSinks.xml");
	Assert.assertNotNull(res);
	Assert.assertEquals(1, res.size());
}
 
Example 28
Source Project: Conversations   Source File: XmppConnection.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
    PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
    if (!packet.valid()) {
        Log.e(Config.LOGTAG, "encountered invalid presence from='" + packet.getFrom() + "' to='" + packet.getTo() + "'");
        return;
    }
    this.presenceListener.onPresencePacketReceived(account, packet);
}
 
Example 29
Source Project: AppOpsXposed   Source File: Backup.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void skipWhitespace(XmlPullParser xml) throws IOException, XmlPullParserException
{
	int type = xml.getEventType();

	// Skip over whitespace
	while((type == XmlPullParser.TEXT) && TextUtils.isEmpty(xml.getName()))
		type = xml.next();
}
 
Example 30
Source Project: org.hl7.fhir.core   Source File: XmlParserBase.java    License: Apache License 2.0 5 votes vote down vote up
protected Resource parseResourceContained(XmlPullParser xpp) throws IOException, FHIRFormatError, XmlPullParserException  {
	next(xpp);
	int eventType = nextNoWhitespace(xpp);
	if (eventType == XmlPullParser.START_TAG) { 
		Resource r = (Resource) parseResource(xpp);
		nextNoWhitespace(xpp);
		next(xpp);
		return r;
	} else {
		unknownContent(xpp);
		return null;
	}
}