< prev index next >

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

Print this page

        

*** 140,149 **** --- 140,150 ---- * cannot block. * * @return the next byte of data, or {@code -1} if the end of the * stream has been reached. */ + @Override public synchronized int read() { return (pos < count) ? (buf[pos++] & 0xff) : -1; } /**
*** 173,182 **** --- 174,184 ---- * @throws NullPointerException If {@code b} is {@code null}. * @throws IndexOutOfBoundsException If {@code off} is negative, * {@code len} is negative, or {@code len} is greater than * {@code b.length - off} */ + @Override public synchronized int read(byte b[], int off, int len) { Objects.checkFromIndexSize(off, len, b.length); if (pos >= count) { return -1;
*** 192,217 **** System.arraycopy(buf, pos, b, off, len); pos += len; return len; } public synchronized byte[] readAllBytes() { byte[] result = Arrays.copyOfRange(buf, pos, count); pos = count; return result; } ! public synchronized int readNBytes(byte[] b, int off, int len) { int n = read(b, off, len); return n == -1 ? 0 : n; } public synchronized long transferTo(OutputStream out) throws IOException { ! int pos0 = pos; ! out.write(buf, pos, count - pos); pos = count; ! return count - pos0; } /** * Skips {@code n} bytes of input from this input stream. Fewer * bytes might be skipped if the end of the input stream is reached. --- 194,222 ---- System.arraycopy(buf, pos, b, off, len); pos += len; return len; } + @Override public synchronized byte[] readAllBytes() { byte[] result = Arrays.copyOfRange(buf, pos, count); pos = count; return result; } ! @Override ! public int readNBytes(byte[] b, int off, int len) { int n = read(b, off, len); return n == -1 ? 0 : n; } + @Override public synchronized long transferTo(OutputStream out) throws IOException { ! int len = count - pos; ! out.write(buf, pos, len); pos = count; ! return len; } /** * Skips {@code n} bytes of input from this input stream. Fewer * bytes might be skipped if the end of the input stream is reached.
*** 222,231 **** --- 227,237 ---- * and {@code k} is returned. * * @param n the number of bytes to be skipped. * @return the actual number of bytes skipped. */ + @Override public synchronized long skip(long n) { long k = count - pos; if (n < k) { k = n < 0 ? 0 : n; }
*** 242,251 **** --- 248,258 ---- * which is the number of bytes remaining to be read from the input buffer. * * @return the number of remaining bytes that can be read (or skipped * over) from this input stream without blocking. */ + @Override public synchronized int available() { return count - pos; } /**
*** 253,262 **** --- 260,270 ---- * {@code markSupported} method of {@code ByteArrayInputStream} * always returns {@code true}. * * @since 1.1 */ + @Override public boolean markSupported() { return true; } /**
*** 272,298 **** --- 280,309 ---- * <p> Note: The {@code readAheadLimit} for this class * has no meaning. * * @since 1.1 */ + @Override public void mark(int readAheadLimit) { mark = pos; } /** * Resets the buffer to the marked position. The marked position * is 0 unless another position was marked or an offset was specified * in the constructor. */ + @Override public synchronized void reset() { pos = mark; } /** * Closing a {@code ByteArrayInputStream} has no effect. The methods in * this class can be called after the stream has been closed without * generating an {@code IOException}. */ + @Override public void close() throws IOException { } }
< prev index next >