package com.qq.taf.jce;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* 数据读取流
* @author meteorchen
*
*/
public final class JceInputStream {
private ByteBuffer bs; // 缓冲区
/**
* 头数据
* @author meteorchen
*
*/
public static class HeadData {
public byte type;
public int tag;
public void clear() {
type = 0 ;
tag = 0 ;
}
}
public JceInputStream() {
}
public JceInputStream(ByteBuffer bs) {
this.bs = bs;
}
public JceInputStream(byte[] bs) {
this.bs = ByteBuffer.wrap(bs);
}
public JceInputStream(byte[] bs, int pos) {
this.bs = ByteBuffer.wrap(bs);
this.bs.position(pos);
}
/**
* 拼写错误
* @deprecated use wrap instead
*/
public void warp(byte[] bs) {
wrap(bs);
}
public void wrap(byte[] bs) {
this.bs = ByteBuffer.wrap(bs);
}
/**
* 读取数据头
* @param hd 读取到的头信息
* @param bb 缓冲
* @return 读取的字节数
*/
public static int readHead(HeadData hd, ByteBuffer bb) {
byte b = bb.get();
hd.type = (byte) (b & 15);
hd.tag = ((b & (15 << 4)) >> 4);
if (hd.tag == 15) {
hd.tag = (bb.get()&0x00ff);
return 2;
}
return 1;
}
public void readHead(HeadData hd) {
readHead(hd, bs);
}
// 读取头信息,但不移动缓冲区的当前偏移
private int peakHead(HeadData hd) {
return readHead(hd, bs.duplicate());
}
// 跳过若干字节
private void skip(int len) {
bs.position(bs.position() + len);
}
// 跳到指定的tag的数据之前
public boolean skipToTag(int tag) {
try {
HeadData hd = new HeadData();
while (true) {
int len = peakHead(hd);
if (hd.type == JceStruct.STRUCT_END) {
return false;
}
if (tag <= hd.tag)
return tag == hd.tag;
skip(len);
skipField(hd.type);
}
} catch (JceDecodeException e) {
} catch (BufferUnderflowException e) {
}
return false;
}
// 跳到当前结构的结束位置
public void skipToStructEnd() {
HeadData hd = new HeadData();
do {
readHead(hd);
skipField(hd.type);
} while (hd.type != JceStruct.STRUCT_END);
}
// 跳过一个字段
private void skipField() {
HeadData hd = new HeadData();
readHead(hd);
skipField(hd.type);
}
private void skipField(byte type) {
switch (type) {
case JceStruct.BYTE:
skip(1);
break;
case JceStruct.SHORT:
skip(2);
break;
case JceStruct.INT:
skip(4);
break;
case JceStruct.LONG:
skip(8);
break;
case JceStruct.FLOAT:
skip(4);
break;
case JceStruct.DOUBLE:
skip(8);
break;
case JceStruct.STRING1: {
int len = bs.get();
if (len < 0)
len += 256;
skip(len);
break;
}
case JceStruct.STRING4: {
skip(bs.getInt());
break;
}
case JceStruct.MAP: {
int size = read(0, 0, true);
for (int i = 0; i < size * 2; ++i)
skipField();
break;
}
case JceStruct.LIST: {
int size = read(0, 0, true);
for (int i = 0; i < size; ++i)
skipField();
break;
}
case JceStruct.SIMPLE_LIST: {
HeadData hd = new HeadData();
readHead(hd);
if(hd.type != JceStruct.BYTE){
throw new JceDecodeException("skipField with invalid type, type value: " + type + ", " + hd.type);
}
int size = read(0, 0, true);
skip(size);
break;
}
case JceStruct.STRUCT_BEGIN:
skipToStructEnd();
break;
case JceStruct.STRUCT_END:
case JceStruct.ZERO_TAG:
break;
default:
throw new JceDecodeException("invalid type.");
}
}
public boolean read(boolean b, int tag, boolean isRequire) {
byte c = read((byte) 0x0, tag, isRequire);
return c != 0;
}
public byte read(byte c, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
c = 0x0;
break;
case JceStruct.BYTE:
c = bs.get();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return c;
}
public short read(short n, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
n = 0;
break;
case JceStruct.BYTE:
n = (short) bs.get();
break;
case JceStruct.SHORT:
n = bs.getShort();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return n;
}
public int read(int n, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
n = 0;
break;
case JceStruct.BYTE:
n = bs.get();
break;
case JceStruct.SHORT:
n = bs.getShort();
break;
case JceStruct.INT:
n = bs.getInt();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return n;
}
public long read(long n, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
n = 0;
break;
case JceStruct.BYTE:
n = bs.get();
break;
case JceStruct.SHORT:
n = bs.getShort();
break;
case JceStruct.INT:
n = bs.getInt();
break;
case JceStruct.LONG:
n = bs.getLong();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return n;
}
public float read(float n, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
n = 0;
break;
case JceStruct.FLOAT:
n = bs.getFloat();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return n;
}
public double read(double n, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.ZERO_TAG:
n = 0;
break;
case JceStruct.FLOAT:
n = bs.getFloat();
break;
case JceStruct.DOUBLE:
n = bs.getDouble();
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw new JceDecodeException("require field not exist.");
}
return n;
}
public String readByteString(String s, int tag, boolean isRequire) {
if (skipToTag(tag)) {
HeadData hd = new HeadData();
readHead(hd);
switch (hd.type) {
case JceStruct.STRING1: {
int len = bs.get();
if (len < 0)
len += 256;
byte[] ss = new byte[len];
bs.get(ss);
s = HexUtil.bytes2HexStr(ss);
}
break;
case JceStruct.STRING4: {
int len = bs.getInt();
if (len > JceStruct.JCE_MAX_STRING_LENGTH || len < 0 || len > bs.capacity())
throw new JceDecodeException("String too long: " + len);
byte[] ss = new byte[len];
bs.get(ss);
s = HexUtil.bytes2HexStr(ss);
}
break;
default:
throw new JceDecodeException("type mismatch.");
}
} else if (isRequire) {
throw n
没有合适的资源?快使用搜索试试~ 我知道了~
安卓应用-媒体影音-海豚tv手机版 v2.1.2.zip
共1920个文件
png:1060个
xml:652个
gif:105个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 109 浏览量
2021-12-09
12:54:28
上传
评论
收藏 59.65MB ZIP 举报
温馨提示
安卓应用-健康医疗
资源推荐
资源详情
资源评论
收起资源包目录
安卓应用-媒体影音-海豚tv手机版 v2.1.2.zip (1920个子文件)
FromServiceMsg.aidl 69B
ToServiceMsg.aidl 67B
.appkey 16B
resources.arsc 1.38MB
soconfig.cfg 341B
ap2d.data 6KB
ap12d.data 6KB
classes.dex 7.6MB
35.gif 13KB
99.gif 13KB
97.gif 10KB
18.gif 8KB
19.gif 8KB
11.gif 8KB
32.gif 7KB
106.gif 6KB
31.gif 6KB
127.gif 5KB
103.gif 5KB
113.gif 5KB
8.gif 5KB
29.gif 5KB
102.gif 5KB
5.gif 5KB
53.gif 4KB
33.gif 4KB
100.gif 4KB
0.gif 4KB
26.gif 4KB
7.gif 4KB
10.gif 4KB
104.gif 4KB
108.gif 4KB
57.gif 4KB
86.gif 3KB
119.gif 3KB
9.gif 3KB
28.gif 3KB
98.gif 3KB
6.gif 3KB
17.gif 3KB
107.gif 3KB
22.gif 3KB
125.gif 3KB
67.gif 3KB
60.gif 3KB
27.gif 3KB
114.gif 3KB
42.gif 2KB
59.gif 2KB
25.gif 2KB
131.gif 2KB
112.gif 2KB
111.gif 2KB
24.gif 2KB
12.gif 2KB
117.gif 2KB
129.gif 2KB
134.gif 2KB
133.gif 2KB
34.gif 2KB
123.gif 2KB
110.gif 2KB
4.gif 2KB
23.gif 2KB
21.gif 2KB
3.gif 2KB
14.gif 2KB
20.gif 2KB
2.gif 2KB
39.gif 2KB
126.gif 2KB
130.gif 2KB
30.gif 2KB
105.gif 2KB
13.gif 2KB
38.gif 2KB
128.gif 2KB
78.gif 2KB
118.gif 2KB
1.gif 2KB
120.gif 2KB
101.gif 2KB
49.gif 2KB
15.gif 2KB
122.gif 2KB
79.gif 2KB
77.gif 2KB
115.gif 1KB
109.gif 1KB
121.gif 1KB
76.gif 1KB
132.gif 1KB
36.gif 1KB
16.gif 1KB
43.gif 1KB
116.gif 1KB
46.gif 1KB
75.gif 1KB
124.gif 1KB
共 1920 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
programxh
- 粉丝: 17
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功