mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8286783: Expand use of @inheritDoc in InputStream and OutputStream subclasses
Reviewed-by: alanb
This commit is contained in:
parent
ea713c37fb
commit
8e602b862d
13 changed files with 156 additions and 141 deletions
|
@ -139,9 +139,9 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* This {@code read} method
|
||||
* cannot block.
|
||||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* stream has been reached.
|
||||
* @return {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized int read() {
|
||||
return (pos < count) ? (buf[pos++] & 0xff) : -1;
|
||||
}
|
||||
|
@ -162,17 +162,14 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* <p>
|
||||
* This {@code read} method cannot block.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in the destination array {@code b}
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @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}
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IndexOutOfBoundsException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized int read(byte[] b, int off, int len) {
|
||||
Objects.checkFromIndexSize(off, len, b.length);
|
||||
|
||||
|
@ -192,17 +189,20 @@ public class ByteArrayInputStream extends InputStream {
|
|||
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);
|
||||
|
@ -219,9 +219,10 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* The value {@code k} is added into {@code pos}
|
||||
* and {@code k} is returned.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @param n {@inheritDoc}
|
||||
* @return the actual number of bytes skipped.
|
||||
*/
|
||||
@Override
|
||||
public synchronized long skip(long n) {
|
||||
long k = count - pos;
|
||||
if (n < k) {
|
||||
|
@ -242,17 +243,20 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this {@code InputStream} supports mark/reset. The
|
||||
* {@code markSupported} method of {@code ByteArrayInputStream}
|
||||
* Tests if this {@code InputStream} supports mark/reset.
|
||||
* @implSpec
|
||||
* The {@code markSupported} method of {@code ByteArrayInputStream}
|
||||
* always returns {@code true}.
|
||||
*
|
||||
* @return true
|
||||
* @since 1.1
|
||||
*/
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return true;
|
||||
}
|
||||
|
@ -272,6 +276,7 @@ public class ByteArrayInputStream extends InputStream {
|
|||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
@Override
|
||||
public void mark(int readAheadLimit) {
|
||||
mark = pos;
|
||||
}
|
||||
|
@ -281,6 +286,7 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* is 0 unless another position was marked or an offset was specified
|
||||
* in the constructor.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reset() {
|
||||
pos = mark;
|
||||
}
|
||||
|
@ -290,7 +296,7 @@ public class ByteArrayInputStream extends InputStream {
|
|||
* this class can be called after the stream has been closed without
|
||||
* generating an {@code IOException}.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -107,6 +107,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
*
|
||||
* @param b the byte to be written.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void write(int b) {
|
||||
ensureCapacity(count + 1);
|
||||
buf[count] = (byte) b;
|
||||
|
@ -117,14 +118,15 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* Writes {@code len} bytes from the specified byte array
|
||||
* starting at offset {@code off} to this {@code ByteArrayOutputStream}.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @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 void write(byte[] b, int off, int len) {
|
||||
Objects.checkFromIndexSize(off, len, b.length);
|
||||
ensureCapacity(count + len);
|
||||
|
@ -212,6 +214,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* @return String decoded from the buffer's contents.
|
||||
* @since 1.1
|
||||
*/
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
return new String(buf, 0, count);
|
||||
}
|
||||
|
@ -306,6 +309,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* this class can be called after the stream has been closed without
|
||||
* generating an {@code IOException}.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
|
|
|
@ -228,8 +228,9 @@ public class FileInputStream extends InputStream
|
|||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* file is reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
|
@ -255,12 +256,13 @@ public class FileInputStream extends InputStream
|
|||
* stream into an array of bytes. This method blocks until some input
|
||||
* is available.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param b {@inheritDoc}
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the file has been reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
|
@ -276,18 +278,15 @@ public class FileInputStream extends InputStream
|
|||
* blocks until some input is available; otherwise, no
|
||||
* bytes are read and {@code 0} is returned.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in the destination array {@code b}
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the file has been reached.
|
||||
* @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}
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IndexOutOfBoundsException {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
|
@ -297,6 +296,7 @@ public class FileInputStream extends InputStream
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readAllBytes() throws IOException {
|
||||
long length = length();
|
||||
long position = position();
|
||||
|
@ -339,6 +339,7 @@ public class FileInputStream extends InputStream
|
|||
return (capacity == nread) ? buf : Arrays.copyOf(buf, nread);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readNBytes(int len) throws IOException {
|
||||
if (len < 0)
|
||||
throw new IllegalArgumentException("len < 0");
|
||||
|
@ -378,6 +379,7 @@ public class FileInputStream extends InputStream
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long transferTo(OutputStream out) throws IOException {
|
||||
long transferred = 0L;
|
||||
if (out instanceof FileOutputStream fos) {
|
||||
|
@ -432,11 +434,12 @@ public class FileInputStream extends InputStream
|
|||
* backing file. Attempting to read from the stream after skipping past
|
||||
* the end will result in -1 indicating the end of the file.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @param n {@inheritDoc}
|
||||
* @return the actual number of bytes skipped.
|
||||
* @throws IOException if n is negative, if the stream does not
|
||||
* support seek, or if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
|
@ -465,6 +468,7 @@ public class FileInputStream extends InputStream
|
|||
* @throws IOException if this file input stream has been closed by calling
|
||||
* {@code close} or an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
|
@ -491,10 +495,11 @@ public class FileInputStream extends InputStream
|
|||
* If cleanup of native resources is needed, other mechanisms such as
|
||||
* {@linkplain java.lang.ref.Cleaner} should be used.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*
|
||||
* @revised 1.4
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
|
|
|
@ -314,6 +314,7 @@ public class FileOutputStream extends OutputStream
|
|||
* @param b the byte to be written.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
boolean append = fdAccess.getAppend(fd);
|
||||
long comp = Blocker.begin();
|
||||
|
@ -340,9 +341,10 @@ public class FileOutputStream extends OutputStream
|
|||
* Writes {@code b.length} bytes from the specified byte array
|
||||
* to this file output stream.
|
||||
*
|
||||
* @param b the data.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @param b {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
boolean append = fdAccess.getAppend(fd);
|
||||
long comp = Blocker.begin();
|
||||
|
@ -357,11 +359,12 @@ public class FileOutputStream extends OutputStream
|
|||
* Writes {@code len} bytes from the specified byte array
|
||||
* starting at offset {@code off} to this file output stream.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
boolean append = fdAccess.getAppend(fd);
|
||||
long comp = Blocker.begin();
|
||||
|
@ -392,6 +395,7 @@ public class FileOutputStream extends OutputStream
|
|||
*
|
||||
* @revised 1.4
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
|
|
|
@ -58,20 +58,12 @@ public class FilterInputStream extends InputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Reads the next byte of data from this input stream. The value
|
||||
* byte is returned as an {@code int} in the range
|
||||
* {@code 0} to {@code 255}. If no byte is available
|
||||
* because the end of the stream has been reached, the value
|
||||
* {@code -1} is returned. This method blocks until input data
|
||||
* is available, the end of the stream is detected, or an exception
|
||||
* is thrown.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @implSpec
|
||||
* This method simply performs {@code in.read()} and returns the result.
|
||||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* stream is reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @return {@inheritDoc}
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
@Override
|
||||
|
@ -93,10 +85,8 @@ public class FilterInputStream extends InputStream {
|
|||
* depend on the implementation strategy actually
|
||||
* used.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @param b {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @see java.io.FilterInputStream#read(byte[], int, int)
|
||||
*/
|
||||
|
@ -115,16 +105,12 @@ public class FilterInputStream extends InputStream {
|
|||
* This method simply performs {@code in.read(b, off, len)}
|
||||
* and returns the result.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in the destination array {@code b}
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @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}
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IndexOutOfBoundsException {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
|
@ -143,7 +129,7 @@ public class FilterInputStream extends InputStream {
|
|||
* @implSpec
|
||||
* This method simply performs {@code in.skip(n)} and returns the result.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @param n {@inheritDoc}
|
||||
* @return the actual number of bytes skipped.
|
||||
* @throws IOException if {@code in.skip(n)} throws an IOException.
|
||||
*/
|
||||
|
@ -164,7 +150,7 @@ public class FilterInputStream extends InputStream {
|
|||
*
|
||||
* @return an estimate of the number of bytes that can be read (or
|
||||
* skipped over) from this input stream without blocking.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
|
@ -172,13 +158,11 @@ public class FilterInputStream extends InputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Closes this input stream and releases any system resources
|
||||
* associated with the stream.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @implSpec
|
||||
* This method simply performs {@code in.close()}.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
@Override
|
||||
|
@ -198,8 +182,7 @@ public class FilterInputStream extends InputStream {
|
|||
* @implSpec
|
||||
* This method simply performs {@code in.mark(readlimit)}.
|
||||
*
|
||||
* @param readlimit the maximum limit of bytes that can be read before
|
||||
* the mark position becomes invalid.
|
||||
* @param readlimit {@inheritDoc}
|
||||
* @see java.io.FilterInputStream#in
|
||||
* @see java.io.FilterInputStream#reset()
|
||||
*/
|
||||
|
@ -224,8 +207,7 @@ public class FilterInputStream extends InputStream {
|
|||
* @implSpec
|
||||
* This method simply performs {@code in.reset()}.
|
||||
*
|
||||
* @throws IOException if the stream has not been marked or if the
|
||||
* mark has been invalidated.
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @see java.io.FilterInputStream#in
|
||||
* @see java.io.FilterInputStream#mark(int)
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -79,7 +79,7 @@ public class FilterOutputStream extends OutputStream {
|
|||
* <p>
|
||||
* Implements the abstract {@code write} method of {@code OutputStream}.
|
||||
*
|
||||
* @param b the {@code byte}.
|
||||
* @param b {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
|
@ -89,18 +89,18 @@ public class FilterOutputStream extends OutputStream {
|
|||
|
||||
/**
|
||||
* Writes {@code b.length} bytes to this output stream.
|
||||
* <p>
|
||||
* @implSpec
|
||||
* The {@code write} method of {@code FilterOutputStream}
|
||||
* calls its {@code write} method of three arguments with the
|
||||
* arguments {@code b}, {@code 0}, and
|
||||
* {@code b.length}.
|
||||
* <p>
|
||||
* Note that this method does not call the one-argument
|
||||
* @implNote
|
||||
* Note that this method does <em>not</em> call the one-argument
|
||||
* {@code write} method of its underlying output stream with
|
||||
* the single argument {@code b}.
|
||||
*
|
||||
* @param b the data to be written.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @see java.io.FilterOutputStream#write(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
|
@ -112,19 +112,19 @@ public class FilterOutputStream extends OutputStream {
|
|||
* Writes {@code len} bytes from the specified
|
||||
* {@code byte} array starting at offset {@code off} to
|
||||
* this output stream.
|
||||
* <p>
|
||||
* @implSpec
|
||||
* The {@code write} method of {@code FilterOutputStream}
|
||||
* calls the {@code write} method of one argument on each
|
||||
* {@code byte} to output.
|
||||
* <p>
|
||||
* @implNote
|
||||
* Note that this method does not call the {@code write} method
|
||||
* of its underlying output stream with the same arguments. Subclasses
|
||||
* of {@code FilterOutputStream} should provide a more efficient
|
||||
* implementation of this method.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @see java.io.FilterOutputStream#write(int)
|
||||
*/
|
||||
|
@ -141,11 +141,11 @@ public class FilterOutputStream extends OutputStream {
|
|||
/**
|
||||
* Flushes this output stream and forces any buffered output bytes
|
||||
* to be written out to the stream.
|
||||
* <p>
|
||||
* @implSpec
|
||||
* The {@code flush} method of {@code FilterOutputStream}
|
||||
* calls the {@code flush} method of its underlying output stream.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @see java.io.FilterOutputStream#out
|
||||
*/
|
||||
@Override
|
||||
|
@ -156,7 +156,7 @@ public class FilterOutputStream extends OutputStream {
|
|||
/**
|
||||
* Closes this output stream and releases any system resources
|
||||
* associated with the stream.
|
||||
* <p>
|
||||
* @implSpec
|
||||
* When not already closed, the {@code close} method of {@code
|
||||
* FilterOutputStream} calls its {@code flush} method, and then
|
||||
* calls the {@code close} method of its underlying output stream.
|
||||
|
|
|
@ -742,7 +742,10 @@ public abstract class InputStream implements Closeable {
|
|||
* Tests if this input stream supports the {@code mark} and
|
||||
* {@code reset} methods. Whether or not {@code mark} and
|
||||
* {@code reset} are supported is an invariant property of a
|
||||
* particular input stream instance. The {@code markSupported} method
|
||||
* particular input stream instance.
|
||||
*
|
||||
* @implSpec
|
||||
* The {@code markSupported} method
|
||||
* of {@code InputStream} returns {@code false}.
|
||||
*
|
||||
* @return {@code true} if this stream instance supports the mark
|
||||
|
|
|
@ -1017,8 +1017,9 @@ public class ObjectInputStream
|
|||
* Reads a byte of data. This method will block if no input is available.
|
||||
*
|
||||
* @return the byte read, or -1 if the end of the stream is reached.
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return bin.read();
|
||||
}
|
||||
|
@ -1041,6 +1042,7 @@ public class ObjectInputStream
|
|||
* @throws IOException If an I/O error has occurred.
|
||||
* @see java.io.DataInputStream#readFully(byte[],int,int)
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] buf, int off, int len) throws IOException {
|
||||
if (buf == null) {
|
||||
throw new NullPointerException();
|
||||
|
@ -1056,16 +1058,17 @@ public class ObjectInputStream
|
|||
* @throws IOException if there are I/O errors while reading from the
|
||||
* underlying {@code InputStream}
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return bin.available();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the input stream. Must be called to release any resources
|
||||
* associated with the stream.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
/*
|
||||
* Even if stream already closed, propagate redundant close to
|
||||
|
@ -1225,6 +1228,7 @@ public class ObjectInputStream
|
|||
* @return the actual number of bytes skipped.
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
*/
|
||||
@Override
|
||||
public int skipBytes(int len) throws IOException {
|
||||
return bin.skipBytes(len);
|
||||
}
|
||||
|
|
|
@ -689,6 +689,7 @@ public class ObjectOutputStream
|
|||
* @param val the byte to be written to the stream
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
*/
|
||||
@Override
|
||||
public void write(int val) throws IOException {
|
||||
bout.write(val);
|
||||
}
|
||||
|
@ -700,6 +701,7 @@ public class ObjectOutputStream
|
|||
* @param buf the data to be written
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] buf) throws IOException {
|
||||
bout.write(buf, 0, buf.length, false);
|
||||
}
|
||||
|
@ -710,8 +712,9 @@ public class ObjectOutputStream
|
|||
* @param buf the data to be written
|
||||
* @param off the start offset in the data
|
||||
* @param len the number of bytes that are written
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] buf, int off, int len) throws IOException {
|
||||
if (buf == null) {
|
||||
throw new NullPointerException();
|
||||
|
@ -724,8 +727,9 @@ public class ObjectOutputStream
|
|||
* Flushes the stream. This will write any buffered output bytes and flush
|
||||
* through to the underlying stream.
|
||||
*
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
bout.flush();
|
||||
}
|
||||
|
@ -747,6 +751,7 @@ public class ObjectOutputStream
|
|||
*
|
||||
* @throws IOException If an I/O error has occurred.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
flush();
|
||||
clear();
|
||||
|
|
|
@ -295,13 +295,13 @@ public class PipedInputStream extends InputStream {
|
|||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* stream is reached.
|
||||
* @return {@inheritDoc}
|
||||
* @throws IOException if the pipe is
|
||||
* {@link #connect(java.io.PipedOutputStream) unconnected},
|
||||
* <a href="#BROKEN"> {@code broken}</a>, closed,
|
||||
* or if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public synchronized int read() throws IOException {
|
||||
if (!connected) {
|
||||
throw new IOException("Pipe not connected");
|
||||
|
@ -352,20 +352,17 @@ public class PipedInputStream extends InputStream {
|
|||
* available, end of the stream has been detected, or an exception is
|
||||
* thrown.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in the destination array {@code b}
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @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}
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IndexOutOfBoundsException {@inheritDoc}
|
||||
* @throws IOException if the pipe is <a href="#BROKEN"> {@code broken}</a>,
|
||||
* {@link #connect(java.io.PipedOutputStream) unconnected},
|
||||
* closed, or if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public synchronized int read(byte[] b, int off, int len) throws IOException {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
|
@ -422,9 +419,10 @@ public class PipedInputStream extends InputStream {
|
|||
* is {@link #connect(java.io.PipedOutputStream) unconnected}, or
|
||||
* <a href="#BROKEN"> {@code broken}</a>.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
* @since 1.0.2
|
||||
*/
|
||||
@Override
|
||||
public synchronized int available() throws IOException {
|
||||
if(in < 0)
|
||||
return 0;
|
||||
|
@ -437,11 +435,11 @@ public class PipedInputStream extends InputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Closes this piped input stream and releases any system resources
|
||||
* associated with the stream.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closedByReader = true;
|
||||
synchronized (this) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -114,6 +114,7 @@ public class PipedOutputStream extends OutputStream {
|
|||
* {@link #connect(java.io.PipedInputStream) unconnected},
|
||||
* closed, or if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
var sink = this.sink;
|
||||
if (sink == null) {
|
||||
|
@ -128,13 +129,14 @@ public class PipedOutputStream extends OutputStream {
|
|||
* This method blocks until all the bytes are written to the output
|
||||
* stream.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @throws IOException if the pipe is <a href=#BROKEN> broken</a>,
|
||||
* {@link #connect(java.io.PipedInputStream) unconnected},
|
||||
* closed, or if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
var sink = this.sink;
|
||||
if (sink == null) {
|
||||
|
@ -155,8 +157,9 @@ public class PipedOutputStream extends OutputStream {
|
|||
* to be written out.
|
||||
* This will notify any readers that bytes are waiting in the pipe.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void flush() throws IOException {
|
||||
if (sink != null) {
|
||||
synchronized (sink) {
|
||||
|
@ -170,8 +173,9 @@ public class PipedOutputStream extends OutputStream {
|
|||
* associated with this stream. This stream may no longer be used for
|
||||
* writing bytes.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
var sink = this.sink;
|
||||
if (sink != null) {
|
||||
|
|
|
@ -121,10 +121,11 @@ public class SequenceInputStream extends InputStream {
|
|||
* skipped over) from the current underlying input stream
|
||||
* without blocking or {@code 0} if this input stream
|
||||
* has been closed by invoking its {@link #close()} method
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
if (in == null) {
|
||||
return 0; // no way to signal EOF from available()
|
||||
|
@ -133,12 +134,7 @@ public class SequenceInputStream extends InputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Reads the next byte of data from this input stream. The byte is
|
||||
* returned as an {@code int} in the range {@code 0} to
|
||||
* {@code 255}. If no byte is available because the end of the
|
||||
* stream has been reached, the value {@code -1} is returned.
|
||||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* This method
|
||||
* tries to read one character from the current substream. If it
|
||||
|
@ -146,10 +142,10 @@ public class SequenceInputStream extends InputStream {
|
|||
* method of the current substream and begins reading from the next
|
||||
* substream.
|
||||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* stream is reached.
|
||||
* @return {@inheritDoc}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
while (in != null) {
|
||||
int c = in.read();
|
||||
|
@ -189,6 +185,7 @@ public class SequenceInputStream extends InputStream {
|
|||
* greater than {@code b.length - off}
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (in == null) {
|
||||
return -1;
|
||||
|
@ -210,8 +207,7 @@ public class SequenceInputStream extends InputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Closes this input stream and releases any system resources
|
||||
* associated with the stream.
|
||||
* {@inheritDoc}
|
||||
* A closed {@code SequenceInputStream}
|
||||
* cannot perform input operations and cannot
|
||||
* be reopened.
|
||||
|
@ -221,8 +217,9 @@ public class SequenceInputStream extends InputStream {
|
|||
* are requested from the enumeration and closed
|
||||
* before the {@code close} method returns.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws IOException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
IOException ioe = null;
|
||||
while (in != null) {
|
||||
|
|
|
@ -79,14 +79,15 @@ public class StringBufferInputStream extends InputStream {
|
|||
* {@code 0} to {@code 255}. If no byte is available
|
||||
* because the end of the stream has been reached, the value
|
||||
* {@code -1} is returned.
|
||||
* <p>
|
||||
*
|
||||
* @implSpec
|
||||
* The {@code read} method of
|
||||
* {@code StringBufferInputStream} cannot block. It returns the
|
||||
* low eight bits of the next character in this input stream's buffer.
|
||||
*
|
||||
* @return the next byte of data, or {@code -1} if the end of the
|
||||
* stream is reached.
|
||||
* @return {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized int read() {
|
||||
return (pos < count) ? (buffer.charAt(pos++) & 0xFF) : -1;
|
||||
}
|
||||
|
@ -94,19 +95,18 @@ public class StringBufferInputStream extends InputStream {
|
|||
/**
|
||||
* Reads up to {@code len} bytes of data from this input stream
|
||||
* into an array of bytes.
|
||||
* <p>
|
||||
* @implSpec
|
||||
* The {@code read} method of
|
||||
* {@code StringBufferInputStream} cannot block. It copies the
|
||||
* low eight bits from the characters in this input stream's buffer into
|
||||
* the byte array argument.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset of the data.
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* {@code -1} if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @param b {@inheritDoc}
|
||||
* @param off {@inheritDoc}
|
||||
* @param len {@inheritDoc}
|
||||
* @return {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public synchronized int read(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
|
@ -135,9 +135,10 @@ public class StringBufferInputStream extends InputStream {
|
|||
* Skips {@code n} bytes of input from this input stream. Fewer
|
||||
* bytes might be skipped if the end of the input stream is reached.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @param n {@inheritDoc}
|
||||
* @return the actual number of bytes skipped.
|
||||
*/
|
||||
@Override
|
||||
public synchronized long skip(long n) {
|
||||
if (n < 0) {
|
||||
return 0;
|
||||
|
@ -156,6 +157,7 @@ public class StringBufferInputStream extends InputStream {
|
|||
* @return the value of {@code count - pos}, which is the
|
||||
* number of bytes remaining to be read from the input buffer.
|
||||
*/
|
||||
@Override
|
||||
public synchronized int available() {
|
||||
return count - pos;
|
||||
}
|
||||
|
@ -164,6 +166,7 @@ public class StringBufferInputStream extends InputStream {
|
|||
* Resets the input stream to begin reading from the first character
|
||||
* of this input stream's underlying buffer.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reset() {
|
||||
pos = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue