1 19 20 package jxl.biff; 21 22 25 public class ByteArray 26 { 27 30 private int growSize; 31 32 35 private byte[] bytes; 36 37 40 private int pos; 41 42 private final static int defaultGrowSize = 1024; 44 45 48 public ByteArray() 49 { 50 this(defaultGrowSize); 51 } 52 53 58 public ByteArray(int gs) 59 { 60 growSize = gs; 61 bytes = new byte[defaultGrowSize]; 62 pos = 0; 63 } 64 65 70 public void add(byte b) 71 { 72 checkSize(1); 73 bytes[pos] = b; 74 pos++; 75 } 76 77 82 public void add(byte[] b) 83 { 84 checkSize(b.length); 85 System.arraycopy(b, 0, bytes, pos, b.length); 86 pos += b.length; 87 } 88 89 94 public byte[] getBytes() 95 { 96 byte[] returnArray = new byte[pos]; 97 System.arraycopy(bytes, 0, returnArray, 0, pos); 98 return returnArray; 99 } 100 101 107 private void checkSize(int sz) 108 { 109 while (pos + sz >= bytes.length) 110 { 111 byte[] newArray = new byte[bytes.length + growSize]; 113 System.arraycopy(bytes, 0, newArray, 0, pos); 114 bytes = newArray; 115 } 116 } 117 } 118 | Popular Tags |