1919import java .io .IOException ;
2020import java .io .OutputStream ;
2121import java .io .UnsupportedEncodingException ;
22+ import java .util .ArrayList ;
2223import java .util .List ;
2324
2425/**
4142 * the contents don't have to be copied to the new buffer. This class is
4243 * designed to behave exactly like the original. The only exception is the
4344 * deprecated toString(int) method that has been ignored.
45+ *
4446 * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
4547 * @version $Id$
4648 */
4749public class ByteArrayOutputStream extends OutputStream {
4850
49- private List buffers = new java . util . ArrayList ();
51+ private List buffers = new ArrayList ();
5052 private int currentBufferIndex ;
5153 private int filledBufferSum ;
5254 private byte [] currentBuffer ;
@@ -166,7 +168,9 @@ public int size() {
166168 * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
167169 * this class can be called after the stream has been closed without
168170 * generating an <tt>IOException</tt>.
169- * @throws IOException in case an I/O error occurs
171+ *
172+ * @throws IOException never (this method should not declare this exception
173+ * but it has to now due to backwards compatability)
170174 */
171175 public void close () throws IOException {
172176 //nop
@@ -183,10 +187,11 @@ public synchronized void reset() {
183187 }
184188
185189 /**
186- * @param out The OutputStream to write to.
187- * @exception IOException
188- * if an I/O error occurs. In particular, an <code>IOException</code> is thrown if the output
189- * stream is closed.
190+ * Writes the entire contents of this byte stream to the
191+ * specified output stream.
192+ *
193+ * @param out the output stream to write to
194+ * @throws IOException if an I/O error occurs, such as if the stream is closed
190195 * @see java.io.ByteArrayOutputStream#writeTo(OutputStream)
191196 */
192197 public synchronized void writeTo (OutputStream out ) throws IOException {
@@ -203,9 +208,13 @@ public synchronized void writeTo(OutputStream out) throws IOException {
203208 }
204209
205210 /**
211+ * Gets the curent contents of this byte stream as a byte array.
212+ * The result is independent of this stream.
213+ *
214+ * @return the current contents of this output stream, as a byte array
206215 * @see java.io.ByteArrayOutputStream#toByteArray()
207216 */
208- public synchronized byte toByteArray ()[] {
217+ public synchronized byte [] toByteArray () {
209218 int remaining = count ;
210219 int pos = 0 ;
211220 byte newbuf [] = new byte [count ];
@@ -223,17 +232,21 @@ public synchronized byte toByteArray()[] {
223232 }
224233
225234 /**
235+ * Gets the curent contents of this byte stream as a string.
236+ *
226237 * @see java.io.ByteArrayOutputStream#toString()
227238 */
228239 public String toString () {
229240 return new String (toByteArray ());
230241 }
231242
232243 /**
233- * @param enc The name of the character encoding
234- * @return String converted from the byte array.
235- * @exception UnsupportedEncodingException
236- * If the named charset is not supported
244+ * Gets the curent contents of this byte stream as a string
245+ * using the specified encoding.
246+ *
247+ * @param enc the name of the character encoding
248+ * @return the string converted from the byte array
249+ * @throws UnsupportedEncodingException if the encoding is not supported
237250 * @see java.io.ByteArrayOutputStream#toString(String)
238251 */
239252 public String toString (String enc ) throws UnsupportedEncodingException {
0 commit comments