< prev index next >

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

Print this page




  92         return (pos < count) ? (buffer.charAt(pos++) & 0xFF) : -1;
  93     }
  94 
  95     /**
  96      * Reads up to <code>len</code> bytes of data from this input stream
  97      * into an array of bytes.
  98      * <p>
  99      * The <code>read</code> method of
 100      * <code>StringBufferInputStream</code> cannot block. It copies the
 101      * low eight bits from the characters in this input stream's buffer into
 102      * the byte array argument.
 103      *
 104      * @param      b     the buffer into which the data is read.
 105      * @param      off   the start offset of the data.
 106      * @param      len   the maximum number of bytes read.
 107      * @return     the total number of bytes read into the buffer, or
 108      *             <code>-1</code> if there is no more data because the end of
 109      *             the stream has been reached.
 110      */
 111     @SuppressWarnings("deprecation")
 112     public synchronized int read(byte b[], int off, int len) {
 113         if (b == null) {
 114             throw new NullPointerException();
 115         } else if ((off < 0) || (off > b.length) || (len < 0) ||
 116                    ((off + len) > b.length) || ((off + len) < 0)) {
 117             throw new IndexOutOfBoundsException();
 118         }
 119         if (pos >= count) {
 120             return -1;
 121         }
 122 
 123         int avail = count - pos;
 124         if (len > avail) {
 125             len = avail;
 126         }
 127         if (len <= 0) {
 128             return 0;
 129         }
 130         buffer.getBytes(pos, pos + len, b, off);
 131         pos += len;
 132         return len;




  92         return (pos < count) ? (buffer.charAt(pos++) & 0xFF) : -1;
  93     }
  94 
  95     /**
  96      * Reads up to <code>len</code> bytes of data from this input stream
  97      * into an array of bytes.
  98      * <p>
  99      * The <code>read</code> method of
 100      * <code>StringBufferInputStream</code> cannot block. It copies the
 101      * low eight bits from the characters in this input stream's buffer into
 102      * the byte array argument.
 103      *
 104      * @param      b     the buffer into which the data is read.
 105      * @param      off   the start offset of the data.
 106      * @param      len   the maximum number of bytes read.
 107      * @return     the total number of bytes read into the buffer, or
 108      *             <code>-1</code> if there is no more data because the end of
 109      *             the stream has been reached.
 110      */
 111     @SuppressWarnings("deprecation")
 112     public synchronized int read(byte[] b, int off, int len) {
 113         if (b == null) {
 114             throw new NullPointerException();
 115         } else if ((off < 0) || (off > b.length) || (len < 0) ||
 116                    ((off + len) > b.length) || ((off + len) < 0)) {
 117             throw new IndexOutOfBoundsException();
 118         }
 119         if (pos >= count) {
 120             return -1;
 121         }
 122 
 123         int avail = count - pos;
 124         if (len > avail) {
 125             len = avail;
 126         }
 127         if (len <= 0) {
 128             return 0;
 129         }
 130         buffer.getBytes(pos, pos + len, b, off);
 131         pos += len;
 132         return len;


< prev index next >