# OutputStream

public abstract class **OutputStream** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html) [Flushable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html)

|---|---|---|
| Known Direct Subclasses [ByteArrayOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ByteArrayOutputStream.html), [FileOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileOutputStream.html), [FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html), [ObjectOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ObjectOutputStream.html), [PipedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html) |---|---| | [ByteArrayOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ByteArrayOutputStream.html) | This class implements an output stream in which the data is written into a byte array. | | [FileOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileOutputStream.html) | A file output stream is an output stream for writing data to a `File` or to a `FileDescriptor`. | | [FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html) | This class is the superclass of all classes that filter output streams. | | [ObjectOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ObjectOutputStream.html) | An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. | | [PipedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html) | Places information on a communications pipe. | |||

|---|---|---|
| Known Indirect Subclasses [BufferedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedOutputStream.html), [CheckedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/CheckedOutputStream.html), [CipherOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/CipherOutputStream.html), [DataOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/DataOutputStream.html), [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html), [DigestOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html), [GZIPOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/GZIPOutputStream.html), [InflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/InflaterOutputStream.html), [JarOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/jar/JarOutputStream.html), [PrintStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintStream.html), [ZipOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/ZipOutputStream.html) |---|---| | [BufferedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedOutputStream.html) | The class implements a buffered output stream. | | [CheckedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/CheckedOutputStream.html) | An output stream that also maintains a checksum of the data being written. | | [CipherOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/CipherOutputStream.html) | A CipherOutputStream is composed of an OutputStream and a Cipher so that write() methods first process the data before writing them out to the underlying OutputStream. | | [DataOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/DataOutputStream.html) | A data output stream lets an application write primitive Java data types to an output stream in a portable way. | | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html) | This class implements an output stream filter for compressing data in the "deflate" compression format. | | [DigestOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html) | A transparent stream that updates the associated message digest using the bits going through the stream. | | [GZIPOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/GZIPOutputStream.html) | This class implements a stream filter for writing compressed data in the GZIP file format. | | [InflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/InflaterOutputStream.html) | Implements an output stream filter for uncompressing data stored in the "deflate" compression format. | | [JarOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/jar/JarOutputStream.html) | The `JarOutputStream` class is used to write the contents of a JAR file to any output stream. | | [PrintStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintStream.html) | A `PrintStream` adds functionality to another output stream, namely the ability to print representations of various data values conveniently. | | [ZipOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/ZipOutputStream.html) | This class implements an output stream filter for writing files in the ZIP file format. | |||

This abstract class is the superclass of all classes representing
an output stream of bytes. An output stream accepts output bytes
and sends them to some sink.


Applications that need to define a subclass of
`OutputStream` must always provide at least a method
that writes one byte of output.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/BufferedOutputStream.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ByteArrayOutputStream.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/DataOutputStream.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(int)`

### Public Constructor Summary

|---|---|
|   | [OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#OutputStream())() |

### Public Method Summary

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#close())() Closes this output stream and releases any system resources associated with this stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#flush())() Flushes this output stream and forces any buffered output bytes to be written out. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[]))(byte\[\] b) Writes `b.length` bytes from the specified byte array to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes `len` bytes from the specified byte array starting at offset `off` to this output stream. |
| abstract void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(int))(int b) Writes the specified byte to this output stream. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.io.Flushable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html)

|---|---|
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html#flush())() Flushes this stream by writing any buffered output to the underlying stream. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Public Constructors

#### public
**OutputStream**
()

<br />

## Public Methods

#### public void
**close**
()

Closes this output stream and releases any system resources
associated with this stream. The general contract of `close`
is that it closes the output stream. A closed stream cannot perform
output operations and cannot be reopened.


The `close` method of `OutputStream` does nothing.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. |
|---|---|

#### public void
**flush**
()

Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of `flush` is
that calling it is an indication that, if any bytes previously
written have been buffered by the implementation of the output
stream, such bytes should immediately be written to their
intended destination.


If the intended destination of this stream is an abstraction provided by
the underlying operating system, for example a file, then flushing the
stream guarantees only that bytes previously written to the stream are
passed to the operating system for writing; it does not guarantee that
they are actually written to a physical device such as a disk drive.


The `flush` method of `OutputStream` does nothing.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. |
|---|---|

#### public void
**write**
(byte\[\] b)

Writes `b.length` bytes from the specified byte array
to this output stream. The general contract for `write(b)`
is that it should have exactly the same effect as the call
`write(b, 0, b.length)`.

##### Parameters

| b | the data. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[],%20int,%20int)`

#### public void
**write**
(byte\[\] b, int off, int len)

Writes `len` bytes from the specified byte array
starting at offset `off` to this output stream.
The general contract for `write(b, off, len)` is that
some of the bytes in the array `b` are written to the
output stream in order; element `b[off]` is the first
byte written and `b[off+len-1]` is the last byte written
by this operation.


The `write` method of `OutputStream` calls
the write method of one argument on each of the bytes to be
written out. Subclasses are encouraged to override this method and
provide a more efficient implementation.


If `b` is `null`, a
`NullPointerException` is thrown.


If `off` is negative, or `len` is negative, or
`off+len` is greater than the length of the array
`b`, then an IndexOutOfBoundsException is thrown.

##### Parameters

| b | the data. |
| off | the start offset in the data. |
| len | the number of bytes to write. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. In particular, an `IOException` is thrown if the output stream is closed. |
|---|---|

#### public abstract void
**write**
(int b)

Writes the specified byte to this output stream. The general
contract for `write` is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument `b`. The 24
high-order bits of `b` are ignored.


Subclasses of `OutputStream` must provide an
implementation for this method.

##### Parameters

| b | the `byte`. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. In particular, an `IOException` may be thrown if the output stream has been closed. |
|---|---|