/Honor5C-7.0/src/main/java/android/net/nsd/DnsSdTxtRecord.java

https://github.com/dstmath/HWFramework · Java · 277 lines · 231 code · 23 blank · 23 comment · 70 complexity · c3ccfead79176ad0777f7c898cdef452 MD5 · raw file

  1. package android.net.nsd;
  2. import android.net.ProxyInfo;
  3. import android.os.Parcel;
  4. import android.os.Parcelable;
  5. import android.os.Parcelable.Creator;
  6. import android.os.Process;
  7. import java.io.UnsupportedEncodingException;
  8. import java.util.Arrays;
  9. public class DnsSdTxtRecord implements Parcelable {
  10. public static final Creator<DnsSdTxtRecord> CREATOR = null;
  11. private static final byte mSeperator = (byte) 61;
  12. private byte[] mData;
  13. static {
  14. /* JADX: method processing error */
  15. /*
  16. Error: jadx.core.utils.exceptions.DecodeException: Load method exception in method: android.net.nsd.DnsSdTxtRecord.<clinit>():void
  17. at jadx.core.dex.nodes.MethodNode.load(MethodNode.java:113)
  18. at jadx.core.dex.nodes.ClassNode.load(ClassNode.java:256)
  19. at jadx.core.ProcessClass.process(ProcessClass.java:34)
  20. at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:281)
  21. at jadx.api.JavaClass.decompile(JavaClass.java:59)
  22. at jadx.api.JadxDecompiler$1.run(JadxDecompiler.java:161)
  23. Caused by: jadx.core.utils.exceptions.DecodeException: in method: android.net.nsd.DnsSdTxtRecord.<clinit>():void
  24. at jadx.core.dex.instructions.InsnDecoder.decodeInsns(InsnDecoder.java:46)
  25. at jadx.core.dex.nodes.MethodNode.load(MethodNode.java:98)
  26. ... 5 more
  27. Caused by: java.lang.IllegalArgumentException: bogus opcode: 0073
  28. at com.android.dx.io.OpcodeInfo.get(OpcodeInfo.java:1197)
  29. at com.android.dx.io.OpcodeInfo.getFormat(OpcodeInfo.java:1212)
  30. at com.android.dx.io.instructions.DecodedInstruction.decode(DecodedInstruction.java:72)
  31. at jadx.core.dex.instructions.InsnDecoder.decodeInsns(InsnDecoder.java:43)
  32. ... 6 more
  33. */
  34. /*
  35. // Can't load method instructions.
  36. */
  37. throw new UnsupportedOperationException("Method not decompiled: android.net.nsd.DnsSdTxtRecord.<clinit>():void");
  38. }
  39. public DnsSdTxtRecord() {
  40. this.mData = new byte[0];
  41. }
  42. public DnsSdTxtRecord(byte[] data) {
  43. this.mData = (byte[]) data.clone();
  44. }
  45. public DnsSdTxtRecord(DnsSdTxtRecord src) {
  46. if (src != null && src.mData != null) {
  47. this.mData = (byte[]) src.mData.clone();
  48. }
  49. }
  50. public void set(String key, String value) {
  51. byte[] valBytes;
  52. int valLen;
  53. if (value != null) {
  54. valBytes = value.getBytes();
  55. valLen = valBytes.length;
  56. } else {
  57. valBytes = null;
  58. valLen = 0;
  59. }
  60. try {
  61. byte[] keyBytes = key.getBytes("US-ASCII");
  62. for (byte b : keyBytes) {
  63. if (b == 61) {
  64. throw new IllegalArgumentException("= is not a valid character in key");
  65. }
  66. }
  67. if (keyBytes.length + valLen >= Process.PROC_TERM_MASK) {
  68. throw new IllegalArgumentException("Key and Value length cannot exceed 255 bytes");
  69. }
  70. int currentLoc = remove(key);
  71. if (currentLoc == -1) {
  72. currentLoc = keyCount();
  73. }
  74. insert(keyBytes, valBytes, currentLoc);
  75. } catch (UnsupportedEncodingException e) {
  76. throw new IllegalArgumentException("key should be US-ASCII");
  77. }
  78. }
  79. public String get(String key) {
  80. byte[] val = getValue(key);
  81. if (val != null) {
  82. return new String(val);
  83. }
  84. return null;
  85. }
  86. public int remove(String key) {
  87. int avStart = 0;
  88. int i = 0;
  89. while (avStart < this.mData.length) {
  90. int avLen = this.mData[avStart];
  91. if (key.length() > avLen || !((key.length() == avLen || this.mData[(key.length() + avStart) + 1] == 61) && key.compareToIgnoreCase(new String(this.mData, avStart + 1, key.length())) == 0)) {
  92. avStart += (avLen + 1) & Process.PROC_TERM_MASK;
  93. i++;
  94. } else {
  95. byte[] oldBytes = this.mData;
  96. this.mData = new byte[((oldBytes.length - avLen) - 1)];
  97. System.arraycopy(oldBytes, 0, this.mData, 0, avStart);
  98. System.arraycopy(oldBytes, (avStart + avLen) + 1, this.mData, avStart, ((oldBytes.length - avStart) - avLen) - 1);
  99. return i;
  100. }
  101. }
  102. return -1;
  103. }
  104. public int keyCount() {
  105. int count = 0;
  106. int nextKey = 0;
  107. while (nextKey < this.mData.length) {
  108. nextKey += (this.mData[nextKey] + 1) & Process.PROC_TERM_MASK;
  109. count++;
  110. }
  111. return count;
  112. }
  113. public boolean contains(String key) {
  114. int i = 0;
  115. while (true) {
  116. String s = getKey(i);
  117. if (s == null) {
  118. return false;
  119. }
  120. if (key.compareToIgnoreCase(s) == 0) {
  121. return true;
  122. }
  123. i++;
  124. }
  125. }
  126. public int size() {
  127. return this.mData.length;
  128. }
  129. public byte[] getRawData() {
  130. return (byte[]) this.mData.clone();
  131. }
  132. private void insert(byte[] keyBytes, byte[] value, int index) {
  133. int i;
  134. byte[] oldBytes = this.mData;
  135. int valLen = value != null ? value.length : 0;
  136. int insertion = 0;
  137. for (int i2 = 0; i2 < index && insertion < this.mData.length; i2++) {
  138. insertion += (this.mData[insertion] + 1) & Process.PROC_TERM_MASK;
  139. }
  140. int length = keyBytes.length + valLen;
  141. if (value != null) {
  142. i = 1;
  143. } else {
  144. i = 0;
  145. }
  146. int avLen = length + i;
  147. int newLen = (oldBytes.length + avLen) + 1;
  148. this.mData = new byte[newLen];
  149. System.arraycopy(oldBytes, 0, this.mData, 0, insertion);
  150. int secondHalfLen = oldBytes.length - insertion;
  151. System.arraycopy(oldBytes, insertion, this.mData, newLen - secondHalfLen, secondHalfLen);
  152. this.mData[insertion] = (byte) avLen;
  153. System.arraycopy(keyBytes, 0, this.mData, insertion + 1, keyBytes.length);
  154. if (value != null) {
  155. this.mData[(insertion + 1) + keyBytes.length] = mSeperator;
  156. System.arraycopy(value, 0, this.mData, (keyBytes.length + insertion) + 2, valLen);
  157. }
  158. }
  159. private String getKey(int index) {
  160. int avStart = 0;
  161. for (int i = 0; i < index && avStart < this.mData.length; i++) {
  162. avStart += this.mData[avStart] + 1;
  163. }
  164. if (avStart >= this.mData.length) {
  165. return null;
  166. }
  167. int avLen = this.mData[avStart];
  168. int aLen = 0;
  169. while (aLen < avLen && this.mData[(avStart + aLen) + 1] != 61) {
  170. aLen++;
  171. }
  172. return new String(this.mData, avStart + 1, aLen);
  173. }
  174. private byte[] getValue(int index) {
  175. int avStart = 0;
  176. for (int i = 0; i < index && avStart < this.mData.length; i++) {
  177. avStart += this.mData[avStart] + 1;
  178. }
  179. if (avStart >= this.mData.length) {
  180. return null;
  181. }
  182. int avLen = this.mData[avStart];
  183. for (int aLen = 0; aLen < avLen; aLen++) {
  184. if (this.mData[(avStart + aLen) + 1] == 61) {
  185. byte[] value = new byte[((avLen - aLen) - 1)];
  186. System.arraycopy(this.mData, (avStart + aLen) + 2, value, 0, (avLen - aLen) - 1);
  187. return value;
  188. }
  189. }
  190. return null;
  191. }
  192. private String getValueAsString(int index) {
  193. byte[] value = getValue(index);
  194. if (value != null) {
  195. return new String(value);
  196. }
  197. return null;
  198. }
  199. private byte[] getValue(String forKey) {
  200. int i = 0;
  201. while (true) {
  202. String s = getKey(i);
  203. if (s == null) {
  204. return null;
  205. }
  206. if (forKey.compareToIgnoreCase(s) == 0) {
  207. return getValue(i);
  208. }
  209. i++;
  210. }
  211. }
  212. public String toString() {
  213. String result = null;
  214. int i = 0;
  215. while (true) {
  216. String a = getKey(i);
  217. if (a == null) {
  218. break;
  219. }
  220. String av = "{" + a;
  221. String val = getValueAsString(i);
  222. if (val != null) {
  223. av = av + "=" + val + "}";
  224. } else {
  225. av = av + "}";
  226. }
  227. if (result == null) {
  228. result = av;
  229. } else {
  230. result = result + ", " + av;
  231. }
  232. i++;
  233. }
  234. return result != null ? result : ProxyInfo.LOCAL_EXCL_LIST;
  235. }
  236. public boolean equals(Object o) {
  237. if (o == this) {
  238. return true;
  239. }
  240. if (o instanceof DnsSdTxtRecord) {
  241. return Arrays.equals(((DnsSdTxtRecord) o).mData, this.mData);
  242. }
  243. return false;
  244. }
  245. public int hashCode() {
  246. return Arrays.hashCode(this.mData);
  247. }
  248. public int describeContents() {
  249. return 0;
  250. }
  251. public void writeToParcel(Parcel dest, int flags) {
  252. dest.writeByteArray(this.mData);
  253. }
  254. }