1 30 31 package org.jboss.axis.components.encoding; 32 33 34 import java.io.UnsupportedEncodingException ; 35 36 37 51 52 class EncodedByteArray 53 { 54 55 private byte[] array = null; 56 57 private int pointer; 58 59 60 private final double PADDING = 1.5; 61 62 63 public EncodedByteArray(byte[] bytes, int startPos, int length) 64 { 65 66 68 array = new byte[(int)(bytes.length * PADDING)]; 69 70 System.arraycopy(bytes, startPos, array, 0, length); 71 72 pointer = length; 73 74 } 75 76 77 public EncodedByteArray(int size) 78 { 79 80 array = new byte[size]; 81 82 } 83 84 85 public void append(int aByte) 86 { 87 88 if (pointer + 1 >= array.length) 89 { 90 91 byte[] newArray = new byte[(int)(array.length * PADDING)]; 92 93 System.arraycopy(array, 0, newArray, 0, pointer); 94 95 array = newArray; 96 97 } 98 99 array[pointer] = (byte)aByte; 100 101 pointer++; 102 103 } 104 105 106 public void append(byte[] byteArray) 107 { 108 109 if (pointer + byteArray.length >= array.length) 110 { 111 112 byte[] newArray = new byte[((int)(array.length * PADDING)) + byteArray.length]; 113 114 System.arraycopy(array, 0, newArray, 0, pointer); 115 116 array = newArray; 117 118 } 119 120 121 System.arraycopy(byteArray, 0, array, pointer, byteArray.length); 122 123 pointer += byteArray.length; 124 125 } 126 127 128 public void append(byte[] byteArray, int pos, int length) 129 { 130 131 if (pointer + length >= array.length) 132 { 133 134 byte[] newArray = new byte[((int)(array.length * PADDING)) + byteArray.length]; 135 136 System.arraycopy(array, 0, newArray, 0, pointer); 137 138 array = newArray; 139 140 } 141 142 System.arraycopy(byteArray, pos, array, pointer, length); 143 144 pointer += length; 145 146 } 147 148 149 154 155 public String toString() 156 { 157 158 return new String (array, 0, pointer); 159 160 } 161 162 163 170 171 public String toString(String charsetName) throws UnsupportedEncodingException 172 { 173 174 return new String (array, 0, pointer, charsetName); 175 176 } 177 178 } 179 180 | Popular Tags |