< prev index next >

src/java.base/share/classes/java/io/ByteArrayOutputStream.java

Print this page
rev 15357 : imported patch 8163517-Various-cleanup-in-java-io-code


 170     /**
 171      * Resets the {@code count} field of this byte array output
 172      * stream to zero, so that all currently accumulated output in the
 173      * output stream is discarded. The output stream can be used again,
 174      * reusing the already allocated buffer space.
 175      *
 176      * @see     java.io.ByteArrayInputStream#count
 177      */
 178     public synchronized void reset() {
 179         count = 0;
 180     }
 181 
 182     /**
 183      * Creates a newly allocated byte array. Its size is the current
 184      * size of this output stream and the valid contents of the buffer
 185      * have been copied into it.
 186      *
 187      * @return  the current contents of this output stream, as a byte array.
 188      * @see     java.io.ByteArrayOutputStream#size()
 189      */
 190     public synchronized byte toByteArray()[] {
 191         return Arrays.copyOf(buf, count);
 192     }
 193 
 194     /**
 195      * Returns the current size of the buffer.
 196      *
 197      * @return  the value of the {@code count} field, which is the number
 198      *          of valid bytes in this output stream.
 199      * @see     java.io.ByteArrayOutputStream#count
 200      */
 201     public synchronized int size() {
 202         return count;
 203     }
 204 
 205     /**
 206      * Converts the buffer's contents into a string decoding bytes using the
 207      * platform's default character set. The length of the new {@code String}
 208      * is a function of the character set, and hence may not be equal to the
 209      * size of the buffer.
 210      *




 170     /**
 171      * Resets the {@code count} field of this byte array output
 172      * stream to zero, so that all currently accumulated output in the
 173      * output stream is discarded. The output stream can be used again,
 174      * reusing the already allocated buffer space.
 175      *
 176      * @see     java.io.ByteArrayInputStream#count
 177      */
 178     public synchronized void reset() {
 179         count = 0;
 180     }
 181 
 182     /**
 183      * Creates a newly allocated byte array. Its size is the current
 184      * size of this output stream and the valid contents of the buffer
 185      * have been copied into it.
 186      *
 187      * @return  the current contents of this output stream, as a byte array.
 188      * @see     java.io.ByteArrayOutputStream#size()
 189      */
 190     public synchronized byte[] toByteArray() {
 191         return Arrays.copyOf(buf, count);
 192     }
 193 
 194     /**
 195      * Returns the current size of the buffer.
 196      *
 197      * @return  the value of the {@code count} field, which is the number
 198      *          of valid bytes in this output stream.
 199      * @see     java.io.ByteArrayOutputStream#count
 200      */
 201     public synchronized int size() {
 202         return count;
 203     }
 204 
 205     /**
 206      * Converts the buffer's contents into a string decoding bytes using the
 207      * platform's default character set. The length of the new {@code String}
 208      * is a function of the character set, and hence may not be equal to the
 209      * size of the buffer.
 210      *


< prev index next >