OutputStreampublic abstract class OutputStream extends Object implements Closeable, FlushableThe base class for all output streams. An output stream is a means of writing
data to a target in a byte-wise manner. Most output streams expect the
{@link #flush()} method to be called before closing the stream, to ensure all
data is actually written through.
This abstract class does not provide a fully working implementation, so it
needs to be subclassed, and at least the {@link #write(int)} method needs to
be overridden. Overriding some of the non-abstract methods is also often
advised, since it might result in higher efficiency.
Many specialized output streams for purposes like writing to a file already
exist in this package. |
Constructors Summary |
---|
public OutputStream()Default constructor.
super();
|
Methods Summary |
---|
public void | close()Closes this stream. Implementations of this method should free any
resources used by the stream. This implementation does nothing.
/* empty */
| public void | flush()Flushes this stream. Implementations of this method should ensure that
any buffered data is written out. This implementation does nothing.
/* empty */
| public void | write(byte[] buffer)Writes the entire contents of the byte array {@code buffer} to this
stream.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
write(buffer, 0, buffer.length);
| public void | write(byte[] buffer, int offset, int count)Writes {@code count} bytes from the byte array {@code buffer} starting at
position {@code offset} to this stream.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
// avoid int overflow, check null buffer
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, made implicit null check explicit,
// used (offset | count) < 0 instead of (offset < 0) || (count < 0)
// to safe one operation
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
if ((offset | count) < 0 || count > buffer.length - offset) {
throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
for (int i = offset; i < offset + count; i++) {
write(buffer[i]);
}
| public abstract void | write(int oneByte)Writes a single byte to this stream. Only the least significant byte of
the integer {@code oneByte} is written to the stream.
|
|