Android APIs
public abstract class

OutputStream

extends Object
implements Closeable Flushable
java.lang.Object
   ↳ java.io.OutputStream
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A writable sink for bytes.

Most clients will use output streams that write data to the file system (FileOutputStream), the network (getOutputStream()/getOutputStream()), or to an in-memory byte array (ByteArrayOutputStream).

Use OutputStreamWriter to adapt a byte stream like this one into a character stream.

Most clients should wrap their output stream with BufferedOutputStream. Callers that do only bulk writes may omit buffering.

Subclassing OutputStream

Subclasses that decorate another output stream should consider subclassing FilterOutputStream, which delegates all calls to the target output stream.

All output stream subclasses should override both write(int) and write(byte[],int,int). The three argument overload is necessary for bulk access to the data. This is much more efficient than byte-by-byte access.

See also:

Summary

Public Constructors
OutputStream()
Default constructor.
Public Methods
void close()
Closes this stream.
void flush()
Flushes this stream.
void write(byte[] buffer, int offset, int count)
Writes count bytes from the byte array buffer starting at position offset to this stream.
void write(byte[] buffer)
Equivalent to write(buffer, 0, buffer.length).
abstract void write(int oneByte)
Writes a single byte to this stream.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public Constructors

public OutputStream ()

Added in API level 1

Default constructor.

Public Methods

public void close ()

Added in API level 1

Closes this stream. Implementations of this method should free any resources used by the stream. This implementation does nothing.

Throws
IOException if an error occurs while closing this stream.

public void flush ()

Added in API level 1

Flushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing.

Throws
IOException if an error occurs while flushing this stream.

public void write (byte[] buffer, int offset, int count)

Added in API level 1

Writes count bytes from the byte array buffer starting at position offset to this stream.

Parameters
buffer byte: the buffer to be written.
offset int: the start position in buffer from where to get bytes.
count int: the number of bytes from buffer to write to this stream.
Throws
IOException if an error occurs while writing to this stream.
IndexOutOfBoundsException if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.

public void write (byte[] buffer)

Added in API level 1

Equivalent to write(buffer, 0, buffer.length).

Parameters
buffer byte
Throws
IOException

public abstract void write (int oneByte)

Added in API level 1

Writes a single byte to this stream. Only the least significant byte of the integer oneByte is written to the stream.

Parameters
oneByte int: the byte to be written.
Throws
IOException if an error occurs while writing to this stream.