1 19 20 package org.netbeans.lib.cvsclient.util; 21 22 28 public class ByteArray extends Object { 29 30 private byte[] bytesBuffer; 31 private int length; 32 33 34 public ByteArray() { 35 bytesBuffer = new byte[50]; 36 length = 0; 37 } 38 39 42 public void add(byte b) { 43 if (bytesBuffer.length <= length) { 44 byte[] newBytesBuffer = new byte[length + length/2]; 45 System.arraycopy(bytesBuffer, 0, newBytesBuffer, 0, bytesBuffer.length); 46 bytesBuffer = newBytesBuffer; 47 } 48 bytesBuffer[length++] = b; 49 } 50 51 54 public byte[] getBytes() { 55 byte[] bytes = new byte[length]; 56 System.arraycopy(bytesBuffer, 0, bytes, 0, length); 57 return bytes; 58 } 59 60 64 public String getStringFromBytes() { 65 return new String (bytesBuffer, 0, length); 66 } 67 68 71 public void reset() { 72 length = 0; 73 } 74 } 75 | Popular Tags |