blob: b470a987f35b3ac075615138c30bbca22c0f8e28 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Copyright 1999-2005 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21package com.sun.org.apache.xml.internal.security.utils;
22
23import java.io.ByteArrayOutputStream;
24
25/**
26 * A simple Unsynced ByteArryOutputStream
27 * @author raul
28 *
29 */
30public class UnsyncByteArrayOutputStream extends ByteArrayOutputStream {
31 int size=4*1024;
32 byte []buf=new byte[size];
33 int pos;
34 /** @inheritDoc */
35 public void write(byte[] arg0) {
36 int newPos=pos+arg0.length;
37 if (newPos>size) {
38 expandSize();
39 }
40 System.arraycopy(arg0,0,buf,pos,arg0.length);
41 pos=newPos;
42 }
43 /** @inheritDoc */
44 public void write(byte[] arg0, int arg1, int arg2) {
45 int newPos=pos+arg2;
46 if (newPos>size) {
47 expandSize();
48 }
49 System.arraycopy(arg0,arg1,buf,pos,arg2);
50 pos=newPos;
51 }
52 /** @inheritDoc */
53 public void write(int arg0) {
54 if (pos>=size) {
55 expandSize();
56 }
57 buf[pos++]=(byte)arg0;
58 }
59 /** @inheritDoc */
60 public byte[] toByteArray() {
61 byte result[]=new byte[pos];
62 System.arraycopy(buf,0,result,0,pos);
63 return result;
64 }
65
66 /** @inheritDoc */
67 public void reset() {
68 pos=0;
69 }
70
71 /** @inheritDoc */
72 void expandSize() {
73 int newSize=size<<2;
74 byte newBuf[]=new byte[newSize];
75 System.arraycopy(buf,0,newBuf,0,pos);
76 buf=newBuf;
77 size=newSize;
78
79 }
80}