1 package com.android.hotspot2.asn1; 2 3 import java.nio.ByteBuffer; 4 import java.util.*; 5 6 public class Asn1Constructed extends Asn1Object { 7 private final int mTagPosition; 8 private final List<Asn1Object> mChildren; 9 Asn1Constructed(int tag, Asn1Class asn1Class, int length, ByteBuffer payload, int tagPosition)10 public Asn1Constructed(int tag, Asn1Class asn1Class, int length, 11 ByteBuffer payload, int tagPosition) { 12 super(tag, asn1Class, true, length, payload); 13 mTagPosition = tagPosition; 14 mChildren = new ArrayList<>(); 15 } 16 addChild(Asn1Object object)17 public void addChild(Asn1Object object) { 18 mChildren.add(object); 19 } 20 21 @Override getChildren()22 public Collection<Asn1Object> getChildren() { 23 return Collections.unmodifiableCollection(mChildren); 24 } 25 getEncoding()26 public ByteBuffer getEncoding() { 27 return getPayload(mTagPosition); 28 } 29 toString(int level, StringBuilder sb)30 private void toString(int level, StringBuilder sb) { 31 sb.append(indent(level)).append(super.toString()).append(":\n"); 32 for (Asn1Object child : mChildren) { 33 if (child.isConstructed()) { 34 ((Asn1Constructed) child).toString(level + 1, sb); 35 } else { 36 sb.append(indent(level + 1)).append(child.toString()).append('\n'); 37 } 38 } 39 } 40 indent(int level)41 public static String indent(int level) { 42 char[] indent = new char[level * 2]; 43 Arrays.fill(indent, ' '); 44 return new String(indent); 45 } 46 47 @Override toString()48 public String toString() { 49 StringBuilder sb = new StringBuilder(); 50 toString(0, sb); 51 return sb.toString(); 52 } 53 } 54