src/java.base/share/classes/java/io/ByteArrayOutputStream.java
changeset 48436 45a9a7a49379
parent 48252 77b88d8f8380
child 49414 1f14faf358fb
equal deleted inserted replaced
48435:20fe8cd3179d 48436:45a9a7a49379
    25 
    25 
    26 package java.io;
    26 package java.io;
    27 
    27 
    28 import java.nio.charset.Charset;
    28 import java.nio.charset.Charset;
    29 import java.util.Arrays;
    29 import java.util.Arrays;
       
    30 import java.util.Objects;
    30 
    31 
    31 /**
    32 /**
    32  * This class implements an output stream in which the data is
    33  * This class implements an output stream in which the data is
    33  * written into a byte array. The buffer automatically grows as data
    34  * written into a byte array. The buffer automatically grows as data
    34  * is written to it.
    35  * is written to it.
   145      * @param   b     the data.
   146      * @param   b     the data.
   146      * @param   off   the start offset in the data.
   147      * @param   off   the start offset in the data.
   147      * @param   len   the number of bytes to write.
   148      * @param   len   the number of bytes to write.
   148      */
   149      */
   149     public synchronized void write(byte b[], int off, int len) {
   150     public synchronized void write(byte b[], int off, int len) {
   150         if ((off < 0) || (off > b.length) || (len < 0) ||
   151         Objects.checkFromIndexSize(off, len, b.length);
   151             ((off + len) - b.length > 0)) {
       
   152             throw new IndexOutOfBoundsException();
       
   153         }
       
   154         ensureCapacity(count + len);
   152         ensureCapacity(count + len);
   155         System.arraycopy(b, off, buf, count, len);
   153         System.arraycopy(b, off, buf, count, len);
   156         count += len;
   154         count += len;
   157     }
   155     }
   158 
   156