1 16 package org.apache.axis.components.encoding; 17 18 import java.io.UnsupportedEncodingException ; 19 20 31 class EncodedByteArray { 32 private byte[] array = null; 33 private int pointer; 34 35 private final double PADDING = 1.5; 36 37 public EncodedByteArray(byte[] bytes, int startPos, int length) { 38 array = new byte[(int) (bytes.length * PADDING)]; 40 System.arraycopy(bytes, startPos, array, 0, length); 41 pointer = length; 42 } 43 44 public EncodedByteArray(int size) { 45 array = new byte[size]; 46 } 47 48 public void append(int aByte) { 49 if (pointer + 1 >= array.length) { 50 byte[] newArray = new byte[(int) (array.length * PADDING)]; 51 System.arraycopy(array, 0, newArray, 0, pointer); 52 array = newArray; 53 } 54 array[pointer] = (byte) aByte; 55 pointer++; 56 } 57 58 public void append(byte[] byteArray) { 59 if (pointer + byteArray.length >= array.length) { 60 byte[] newArray = new byte[((int)(array.length * PADDING)) + byteArray.length]; 61 System.arraycopy(array, 0, newArray, 0, pointer); 62 array = newArray; 63 } 64 65 System.arraycopy(byteArray, 0, array, pointer, byteArray.length); 66 pointer += byteArray.length; 67 } 68 69 public void append(byte[] byteArray, int pos, int length) { 70 if (pointer + length >= array.length) { 71 byte[] newArray = new byte[((int) (array.length * PADDING)) + byteArray.length]; 72 System.arraycopy(array, 0, newArray, 0, pointer); 73 array = newArray; 74 } 75 System.arraycopy(byteArray, pos, array, pointer, length); 76 pointer += length; 77 } 78 79 83 public String toString() { 84 return new String (array, 0, pointer); 85 } 86 87 93 public String toString(String charsetName) throws UnsupportedEncodingException { 94 return new String (array, 0, pointer, charsetName); 95 } 96 } 97 | Popular Tags |