11/*
2- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java,v 1.4 2003/12/30 06:55:59 bayard Exp $
3- * $Revision: 1.4 $
4- * $Date: 2003/12/30 06:55:59 $
2+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java,v 1.5 2003/12/30 15:19:45 jeremias Exp $
3+ * $Revision: 1.5 $
4+ * $Date: 2003/12/30 15:19:45 $
55 *
66 * ====================================================================
77 *
8787 * designed to behave exactly like the original. The only exception is the
8888 * deprecated toString(int) method that has been ignored.
8989 * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
90- * @version $Id: ByteArrayOutputStream.java,v 1.4 2003/12/30 06:55:59 bayard Exp $
90+ * @version $Id: ByteArrayOutputStream.java,v 1.5 2003/12/30 15:19:45 jeremias Exp $
9191 */
9292public class ByteArrayOutputStream extends OutputStream {
9393
94- private static boolean DEBUG = false ;
95-
9694 private List buffers = new java .util .ArrayList ();
9795 private int currentBufferIndex ;
9896 private int filledBufferSum ;
@@ -132,17 +130,14 @@ private int getCurrentCapacity() {
132130 }*/
133131
134132 private void needNewBuffer (int newcount ) {
135- if (DEBUG ) System .out .println ("Need new buffer: newcount=" + newcount
136- + " curBufIdx=" + currentBufferIndex
137- + " buffers=" + buffers .size ());
138133 if (currentBufferIndex < buffers .size () - 1 ) {
134+ //Recycling old buffer
139135 filledBufferSum += currentBuffer .length ;
140136
141137 currentBufferIndex ++;
142138 currentBuffer = getBuffer (currentBufferIndex );
143- if (DEBUG ) System .out .println ("-->Recycling old buffer: size="
144- + currentBuffer .length );
145139 } else {
140+ //Creating new buffer
146141 int newBufferSize ;
147142 if (currentBuffer == null ) {
148143 newBufferSize = newcount ;
@@ -154,7 +149,6 @@ private void needNewBuffer(int newcount) {
154149 filledBufferSum += currentBuffer .length ;
155150 }
156151
157- if (DEBUG ) System .out .println ("-->Adding new buffer: size=" + newBufferSize );
158152 currentBufferIndex ++;
159153 currentBuffer = new byte [newBufferSize ];
160154 buffers .add (currentBuffer );
@@ -174,16 +168,11 @@ public synchronized void write(byte[] b, int off, int len) {
174168 } else if (len == 0 ) {
175169 return ;
176170 }
177- if (DEBUG ) System .out .println ("------------------write(" +len +" bytes)" );
178171 int newcount = count + len ;
179172 int remaining = len ;
180173 int inBufferPos = count - filledBufferSum ;
181174 while (remaining > 0 ) {
182175 int part = Math .min (remaining , currentBuffer .length - inBufferPos );
183- if (DEBUG ) System .out .println ("Writing " + part
184- + " bytes at pos " + inBufferPos + " of buffer "
185- + currentBuffer + " len=" + currentBuffer .length
186- + " idx=" + currentBufferIndex );
187176 System .arraycopy (b , off + len - remaining , currentBuffer , inBufferPos , part );
188177 remaining -= part ;
189178 if (remaining > 0 ) {
0 commit comments