1 17 package com.sun.org.apache.xml.internal.security.utils; 18 19 import java.io.ByteArrayOutputStream ; 20 21 26 public class UnsyncByteArrayOutputStream extends ByteArrayOutputStream { 27 int size=4*1024; 28 byte []buf=new byte[size]; 29 int pos; 30 31 public void write(byte[] arg0) { 32 int newPos=pos+arg0.length; 33 if (newPos>size) { 34 expandSize(); 35 } 36 System.arraycopy(arg0,0,buf,pos,arg0.length); 37 pos=newPos; 38 } 39 40 public void write(byte[] arg0, int arg1, int arg2) { 41 int newPos=pos+arg2; 42 if (newPos>size) { 43 expandSize(); 44 } 45 System.arraycopy(arg0,arg1,buf,pos,arg2); 46 pos=newPos; 47 } 48 49 public void write(int arg0) { 50 if (pos>=size) { 51 expandSize(); 52 } 53 buf[pos++]=(byte)arg0; 54 } 55 56 public byte[] toByteArray() { 57 byte result[]=new byte[pos]; 58 System.arraycopy(buf,0,result,0,pos); 59 return result; 60 } 61 62 63 public void reset() { 64 pos=0; 65 } 66 67 68 void expandSize() { 69 int newSize=size<<2; 70 byte newBuf[]=new byte[newSize]; 71 System.arraycopy(buf,0,newBuf,0,pos); 72 buf=newBuf; 73 size=newSize; 74 75 } 76 } 77 | Popular Tags |