# Class ByteOutput (3.19.4)

    public abstract class ByteOutput

An output target for raw bytes. This interface provides semantics that support two types of
writing:

**Traditional write operations:** (as defined by [java.io.OutputStream](https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html)) where the
target method is responsible for either copying the data or completing the write before returning
from the method call.

**Lazy write operations:** where the caller guarantees that it will never modify the
provided buffer and it can therefore be considered immutable. The target method is free to
maintain a reference to the buffer beyond the scope of the method call (e.g. until the write
operation completes).

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> ByteOutput

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### ByteOutput()

    public ByteOutput()

## Methods

### write(byte value)

    public abstract void write(byte value)

Writes a single byte.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the byte to be written |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | thrown if an error occurred while writing |

### write(byte\[\] value, int offset, int length)

    public abstract void write(byte[] value, int offset, int length)

Writes a sequence of bytes. The [ByteOutput](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteOutput) must copy `value` if it will not be
processed prior to the return of this method call, since `value` may be reused/altered by
the caller.

NOTE: This method **MUST NOT** modify the `value`. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` the bytes to be written |
| `offset` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the offset of the start of the writable range |
| `length` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the number of bytes to write starting from `offset` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | thrown if an error occurred while writing |

### write(ByteBuffer value)

    public abstract void write(ByteBuffer value)

Writes a sequence of bytes. The [ByteOutput](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteOutput) must copy `value` if it will not be
processed prior to the return of this method call, since `value` may be reused/altered by
the caller.

NOTE: This method **MUST NOT** modify the `value`. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` the bytes to be written. Upon returning from this call, the `position` of this buffer will be set to the `limit` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | thrown if an error occurred while writing |

### writeLazy(byte\[\] value, int offset, int length)

    public abstract void writeLazy(byte[] value, int offset, int length)

Writes a sequence of bytes. The [ByteOutput](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteOutput) is free to retain a reference to the value
beyond the scope of this method call (e.g. write later) since it is considered immutable and is
guaranteed not to change by the caller.

NOTE: This method **MUST NOT** modify the `value`. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` the bytes to be written |
| `offset` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the offset of the start of the writable range |
| `length` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the number of bytes to write starting from `offset` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | thrown if an error occurred while writing |

### writeLazy(ByteBuffer value)

    public abstract void writeLazy(ByteBuffer value)

Writes a sequence of bytes. The [ByteOutput](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteOutput) is free to retain a reference to the value
beyond the scope of this method call (e.g. write later) since it is considered immutable and is
guaranteed not to change by the caller.

NOTE: This method **MUST NOT** modify the `value`. Doing so is a
programming error and will lead to data corruption which will be difficult to debug.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` the bytes to be written. Upon returning from this call, the `position` of this buffer will be set to the `limit` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | thrown if an error occurred while writing |