java 解析 manifest_解析AndroidManifest.xml之AXMLParser.java | 学步园

解析AndroidManifest.xml

源码地址:

http://code.google.com/p/android4me/source/browse/src/android4me/res/AXMLParser.java

/* * Copyright 2008 Android4ME * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android4me.res; import java.io.IOException; import java.io.InputStream; /** * @author Dmitry Skiba * * Parser for Android's binary xml files (axml). * * TODO: * * understand ? values */ public final class AXMLParser { /** * Types of returned tags. * Values are compatible to those in XmlPullParser. */ public static final int START_DOCUMENT =0, END_DOCUMENT =1, START_TAG =2, END_TAG =3, TEXT =4; /** * Creates object and reads file info. * Call next() to read first tag. */ public AXMLParser(InputStream stream) throws IOException { m_stream=stream; doStart(); } /** * Closes parser: * * closes (and nulls) underlying stream * * nulls dynamic data * * moves object to 'closed' state, where methods * return invalid values and next() throws IOException. */ public final void close() { if (m_stream==null) { return; } try { m_stream.close(); } catch (IOException e) { } if (m_nextException==null) { m_nextException=new IOException("Closed."); } m_stream=null; resetState(); } /** * Advances to the next tag. * Once method returns END_DOCUMENT, it always returns END_DOCUMENT. * Once method throws an exception, it always throws the same exception. * */ public final int next() throws IOException { if (m_nextException!=null) { throw m_nextException; } try { return doNext(); } catch (IOException e) { m_nextException=e; resetState(); throw e; } } /** * Returns current tag type. */ public final int getType() { return m_tagType; } /** * Returns name for the current tag. */ public final String getName() { if (m_tagName==-1) { return null; } return getString(m_tagName); } /** * Returns line number in the original XML where the current tag was. */ public final int getLineNumber() { return m_tagSourceLine; } /** * Returns count of attributes for the current tag. */ public final int getAttributeCount() { if (m_tagAttributes==null) { return -1; } return m_tagAttributes.length; } /** * Returns attribute namespace. */ public final String getAttributeNamespace(int index) { return getString(getAttribute(index).namespace); } /** * Returns attribute name. */ public final String getAttributeName(int index) { return getString(getAttribute(index).name); } /** * Returns attribute resource ID. */ public final int getAttributeResourceID(int index) { int resourceIndex=getAttribute(index).name; if (m_resourceIDs==null || resourceIndex<0 || resourceIndex>=m_resourceIDs.length) { return 0; } return m_resourceIDs[resourceIndex]; } /** * Returns type of attribute value. * See TypedValue.TYPE_ values. */ public final int getAttributeValueType(int index) { return getAttribute(index).valueType; } /** * For attributes of type TypedValue.TYPE_STRING returns * string value. For other types returns empty string. */ public final String getAttributeValueString(int index) { return getString(getAttribute(index).valueString); } /** * Returns integer attribute value. * This integer interpreted according to attribute type. */ public final int getAttributeValue(int index) { return getAttribute(index).value; } / implementation private static final class TagAttribute { public int namespace; public int name; public int valueString; public int valueType; public int value; } private final void resetState() { m_tagType=-1; m_tagSourceLine=-1; m_tagName=-1; m_tagAttributes=null; } private final void doStart() throws IOException { ReadUtil.readCheckType(m_stream,AXML_CHUNK_TYPE); /*chunk size*/ReadUtil.readInt(m_stream); m_strings=StringBlock.read(new IntReader(m_stream,false)); ReadUtil.readCheckType(m_stream,RESOURCEIDS_CHUNK_TYPE); int chunkSize=ReadUtil.readInt(m_stream); if (chunkSize<8 || (chunkSize%4)!=0) { throw new IOException("Invalid resource ids size ("+chunkSize+")."); } m_resourceIDs=ReadUtil.readIntArray(m_stream,chunkSize/4-2); resetState(); } private final int doNext() throws IOException { if (m_tagType==END_DOCUMENT) { return END_DOCUMENT; } m_tagType=(ReadUtil.readInt(m_stream) & 0xFF);/*other 3 bytes?*/ /*some source length*/ReadUtil.readInt(m_stream); m_tagSourceLine=ReadUtil.readInt(m_stream); /*0xFFFFFFFF*/ReadUtil.readInt(m_stream); m_tagName=-1; m_tagAttributes=null; switch (m_tagType) { case START_DOCUMENT: { /*namespace?*/ReadUtil.readInt(m_stream); /*name?*/ReadUtil.readInt(m_stream); break; } case START_TAG: { /*0xFFFFFFFF*/ReadUtil.readInt(m_stream); m_tagName=ReadUtil.readInt(m_stream); /*flags?*/ReadUtil.readInt(m_stream); int attributeCount=ReadUtil.readInt(m_stream); /*?*/ReadUtil.readInt(m_stream); m_tagAttributes=new TagAttribute[attributeCount]; for (int i=0;i!=attributeCount;++i) { TagAttribute attribute=new TagAttribute(); attribute.namespace=ReadUtil.readInt(m_stream); attribute.name=ReadUtil.readInt(m_stream); attribute.valueString=ReadUtil.readInt(m_stream); attribute.valueType=(ReadUtil.readInt(m_stream)>>>24);/*other 3 bytes?*/ attribute.value=ReadUtil.readInt(m_stream); m_tagAttributes[i]=attribute; } break; } case END_TAG: { /*0xFFFFFFFF*/ReadUtil.readInt(m_stream); m_tagName=ReadUtil.readInt(m_stream); break; } case TEXT: { m_tagName=ReadUtil.readInt(m_stream); /*?*/ReadUtil.readInt(m_stream); /*?*/ReadUtil.readInt(m_stream); break; } case END_DOCUMENT: { /*namespace?*/ReadUtil.readInt(m_stream); /*name?*/ReadUtil.readInt(m_stream); break; } default: { throw new IOException("Invalid tag type ("+m_tagType+")."); } } return m_tagType; } private final TagAttribute getAttribute(int index) { if (m_tagAttributes==null) { throw new IndexOutOfBoundsException("Attributes are not available."); } if (index>=m_tagAttributes.length) { throw new IndexOutOfBoundsException("Invalid attribute index ("+index+")."); } return m_tagAttributes[index]; } private final String getString(int index) { if (index==-1) { return ""; } return m_strings.getRaw(index); } /// data private InputStream m_stream; private StringBlock m_strings; private int[] m_resourceIDs; private IOException m_nextException; private int m_tagType; private int m_tagSourceLine; private int m_tagName; private TagAttribute[] m_tagAttributes; private static final int AXML_CHUNK_TYPE =0x00080003, RESOURCEIDS_CHUNK_TYPE =0x00080180; }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/308456.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java手写Hashmap(HashMap的基本用法)

一&#xff1a;引言 HashMap是Map的实现类&#xff0c;其方法都可以继承Map,不用手写&#xff0c;本篇只是为了了解底层代码和复习java基础敲得码 二&#xff1a;上码 package cn.wyj.two;public class Demo5_手写HashMap<K,V> {Node2 table[];//位桶数组int size;pub…

龙芯3A5000初样顺利交付流片

此前&#xff0c;龙芯完成3A5000设计初样的流片交付。在3A4000架构的基础上&#xff0c;3A5000采用12纳米工艺&#xff0c;设计频率提高近40%&#xff0c;同频模式下功耗降低近60%&#xff0c;同时保持与3A4000芯片管脚兼容。龙芯3A5000和3A4000在微结构上变化不大&#xff0c;…

java堆和栈 常量池_GitHub - han-guang-xue/difference-of-stack-heap-pool: Java中堆、栈和常量池的区别...

Java中堆、栈和常量池的区别栈 堆 常量池的概念首先我们先了解一下概念&#xff0c;Java把内存分成两种&#xff0c;一种叫做栈内存&#xff0c;一种叫做堆内存。栈内存存放基本类型的变量数据和对象类型的引用(请注意存放的是引用)&#xff0c;对象本身不存放在栈中&#xff0…

Java当中TreeMap用法

一&#xff1a;引言 当用到了TreeMap时候&#xff0c;是因为要根据键值进行排序&#xff0c;使输出的结果是按递增顺序的 二&#xff1a;上码 package cn.wyj.two;import java.util.Map; import java.util.TreeMap;/*** 一般当 键值需要排序时&#xff0c;我们会选择用 Tree…

redhat java 多个版本_Linux下安装JDK(多个版本) 切换

1、检查系统是否自带了OpenJDK以及相关安装包&#xff0c;如果有的话则应先将其卸载。检查命令&#xff1a;java -versionrpm -qa | grep javarpm -e --nodeps tzdata-java-2013g-1.el6.noarchrpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686rpm -e --nodeps…

efcore 新特性 SaveChanges Events

efcore 新特性 SaveChanges EventsIntro昨天早上看到之前关注的一个 efcore 的 issue 被 closed &#xff0c;于是看了一眼&#xff0c; ef core 新合并了一个 PR&#xff0c;在 DbContext 中增加了 SaveChanges 相关的几个事件&#xff0c;具体的变更可以参数 PR https://gith…

Java手写HashSet

一&#xff1a;引言 HashSet类继承于 Set接口 其方法均可被直接调用&#xff0c;不用手写&#xff0c;本篇敲的码是为了熟悉底层原理&#xff0c;HashMap的特点&#xff1a;无序&#xff0c;无重复。其底层用的也是map<key,value>容器&#xff0c;但其value值固定,所以在…

十分钟搭建自己的私有NuGet服务器-BaGet

点击上方蓝字"小黑在哪里"关注我吧搭建BaGet上传程序包在vs中使用其他前言NuGet是用于微软.NET&#xff08;包括 .NET Core&#xff09;开发平台的软件包管理器。NuGet能够令你在项目中添加、移除和更新引用的工作变得更加快捷方便。通常使用NuGet都是官方的服务&…

java swing 面试题_下面有关JAVA swing的描述,说法错误的是?

Swing是一个用于开发Java应用程序用户界面的开发工具包。它以抽象窗口工具包(AWT)为基础使跨平台应用程序可以使用任何可插拔的外观风格。Swing开发人员只用很少的代码就可以利用Swing丰富、灵活的功能和模块化组件来创建优雅的用户界面。工具包中所有的包都是以swing作为名称&…

Java当中迭代器的使用(遍历容器ArrayList, HashSet,HashMap)

一&#xff1a;引言 关于entry 的解释代码有注释&#xff0c;觉得挺重要。 二&#xff1a;上码 package cn.wyj.two;import java.util.*; import java.util.Map.Entry;public class Demo10_迭代器的使用 {public static void main(String[] args) {textList();System.out.pr…

mysql or 创建索引_Mysql索引优化

1、单表索引优化单表索引优化分析创建表建表 SQLCREATE TABLE IF NOT EXISTS article(id INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,author_id INT(10) UNSIGNED NOT NULL,category_id INT(10) UNSIGNED NOT NULL,views INT(10) UNSIGNED NOT NULL,comments INT(1…

.Net Core HttpClient处理响应压缩

前言在上篇文章[ASP.NET Core中的响应压缩]中我们谈到了在ASP.NET Core服务端处理关于响应压缩的请求&#xff0c;服务端的主要工作就是根据Content-Encoding头信息判断采用哪种方式压缩并返回。之前在群里有人问道过&#xff0c;现在的网络带宽这么高了还有必要在服务端针对请…

Java容器的遍历之增强for循环

一&#xff1a;为什么要用增强版的 for 循环呢 在普通的数组遍历当中&#xff0c;我们采用普通的for循环即可&#xff0c;但在遍历2.遍历集合、容器&#xff0c;当中我们一般采用增强版的for循环 &#xff0c;简单方便。 二&#xff1a;构造模式 for(数据类型 变量&#xff…

mysql脚本的制作_制作脚本实现mysql自动备份

首先执行vi dbbackup.sh命令&#xff0c;在打开的编辑器输入&#xff1a;#!/bin/bash/usr/local/mysql/bin/mysqldump -uuser -ppasswd databasename > /home/wwwroot/backup/date_$(date%Y%m%d).sql这段命令的意思是&#xff1a;用mysqldump导出名为databasename的数据库到…

在 PostgreSQL 中使用码农很忙 IP 地址数据库

在下载到码农很忙 IP 地址数据库后&#xff0c;我们可以将其存储在 PostgreSQL 数据库中&#xff0c;并在需要查询某个 IP 对应的位置数据时&#xff0c;通过 SQL 语句获取正确的结果。这是一种很便捷的使用方式&#xff0c;并且在增加了恰当的索引后&#xff0c;可以取得不错的…

Java当中Collections的用法

一&#xff1a;上码 package cn.wyj.two;/*** Collections辅助类的使用* * author 王永杰**/ import java.util.*;public class Demo11_Collections辅助类 {public static void main(String[] args) {List<String> list new ArrayList<String>();for( int i 0; …

.NET开发者提高编程技能的5种方法

.NET开发者提高编程技能的5种方法https://insights.dice.com/2017/08/29/5-ways-improve-programming-skills/即使拥有40年的编程经验&#xff0c;我唯一能确定的就是肯定有比我更好的程序员。但是我并没有放弃&#xff0c;我会继续尝试并提高自己的编程技能。我认为有五件事可…

Java当中用 javabean和其他容器存入表格数据 或 利用 容器进行存储表格

一&#xff1a;javabean 和list容器或map容器 package cn.wyj.two;import java.util.*;/*** javabean :必须有一个无参构造函数&#xff1b;变量属性私有化&#xff1b;* 本篇还是打印一张表* author 86155**/ public class Demo13_Javabean和其他容器 {public static void ma…

7-25 朋友圈 (25 分)(详解+并查集的了解和应用)

一&#xff1a;题目 某学校有N个学生&#xff0c;形成M个俱乐部。每个俱乐部里的学生有着一定相似的兴趣爱好&#xff0c;形成一个朋友圈。一个学生可以同时属于若干个不同的俱乐部。根据“我的朋友的朋友也是我的朋友”这个推论可以得出&#xff0c;如果A和B是朋友&#xff0…

使用Azure人脸API对图片进行人脸识别

人脸识别是人工智能机器学习比较成熟的一个领域。人脸识别已经应用到了很多生产场景。比如生物认证&#xff0c;人脸考勤&#xff0c;人流监控等场景。对于很多中小功能由于技术门槛问题很难自己实现人脸识别的算法。Azure人脸API对人脸识别机器学习算法进行封装提供REST API跟…