com.google.cloud.dataflow.sdk.coders

## Class ByteCoder

- java.lang.Object
- - com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
  - - com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder<T>
    - - com.google.cloud.dataflow.sdk.coders.AtomicCoder<Byte>
      - - com.google.cloud.dataflow.sdk.coders.ByteCoder

All Implemented Interfaces:
  Coder<Byte>, Serializable

    public class ByteCoder
    extends AtomicCoder<Byte>

A `ByteCoder` encodes `Byte` values in 1 byte using Java serialization.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder

`Coder.Context, Coder.NonDeterministicException`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`boolean` `consistentWithEquals()` Returns `true` if this `Coder` is injective with respect to `Object.equals(java.lang.Object)`.
`Byte` `decode(InputStream inStream, Coder.Context context)` Decodes a value of type `T` from the given input stream in the given context.
`void` `encode(Byte value, OutputStream outStream, Coder.Context context)` Encodes the given value of type `T` onto the given output stream in the given context.
`protected long` `getEncodedElementByteSize(Byte value, Coder.Context context)` Returns the size in bytes of the encoded value using this coder.

`boolean`

`isRegisterByteSizeObserverCheap(Byte value, Coder.Context context)`
Returns whether `Coder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)` cheap enough to call for every element, that is, if this `Coder` can calculate the byte size of the element to be coded in roughly constant time (or lazily).

`static ByteCoder` `of()`
`void` `verifyDeterministic()` Throw `Coder.NonDeterministicException` if the coding is not deterministic.

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.AtomicCoder

`getCoderArguments, getInstanceComponents`

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder

`asCloudObject, equals, getAllowedEncodings, getComponents, getEncodingId, hashCode, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Method Detail

#### of

    public static ByteCoder of()

#### encode

    public void encode(Byte value,
                       OutputStream outStream,
                       Coder.Context context)
                throws IOException,
                       CoderException

Description copied from interface: `Coder`
Encodes the given value of type `T` onto the given output stream in the given context.

Throws:
  `IOException` - if writing to the `OutputStream` fails for some reason
  `CoderException` - if the value could not be encoded for some reason

#### decode

    public Byte decode(InputStream inStream,
                       Coder.Context context)
                throws IOException,
                       CoderException

Description copied from interface: `Coder`
Decodes a value of type `T` from the given input stream in the given context. Returns the decoded value.

Throws:
  `IOException` - if reading from the `InputStream` fails for some reason
  `CoderException` - if the value could not be decoded for some reason

#### verifyDeterministic

    public void verifyDeterministic()

Throw `Coder.NonDeterministicException` if the coding is not deterministic.

In order for a `Coder` to be considered deterministic, the following must be true:

- two values that compare as equal (via `Object.equals()` or `Comparable.compareTo()`, if supported) have the same encoding.
- the `Coder` always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.

`ByteCoder` will never throw a `Coder.NonDeterministicException`; bytes can always be encoded deterministically.

Specified by:
  `verifyDeterministic` in interface `Coder<Byte>`
Overrides:
  `verifyDeterministic` in class `DeterministicStandardCoder<Byte>`

#### consistentWithEquals

    public boolean consistentWithEquals()

Returns `true` if this `Coder` is injective with respect to `Object.equals(java.lang.Object)`.

Whenever the encoded bytes of two values are equal, then the original values are equal according to `Objects.equals()`. Note that this is well-defined for `null`.

This condition is most notably false for arrays. More generally, this condition is false whenever `equals()` compares object identity, rather than performing a semantic/structural comparison.

Specified by:
  `consistentWithEquals` in interface `Coder<Byte>`
Overrides:
  `consistentWithEquals` in class `StandardCoder<Byte>`
Returns:
  `true`. This coder is injective.

#### isRegisterByteSizeObserverCheap

    public boolean isRegisterByteSizeObserverCheap(Byte value,
                                                   Coder.Context context)

Returns whether `Coder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)` cheap enough to call for every element, that is, if this `Coder` can calculate the byte size of the element to be coded in roughly constant time (or lazily).

Not intended to be called by user code, but instead by `PipelineRunner` implementations.

Specified by:
  `isRegisterByteSizeObserverCheap` in interface `Coder<Byte>`
Overrides:
  `isRegisterByteSizeObserverCheap` in class `StandardCoder<Byte>`
Returns:
  `true`. `getEncodedElementByteSize(java.lang.Byte, com.google.cloud.dataflow.sdk.coders.Coder.Context)` returns a constant.

#### getEncodedElementByteSize

    protected long getEncodedElementByteSize(Byte value,
                                             Coder.Context context)
                                      throws Exception

Returns the size in bytes of the encoded value using this coder.

Overrides:
  `getEncodedElementByteSize` in class `StandardCoder<Byte>`
Returns:
  `1`, the byte size of a `Byte` encoded using Java serialization.
Throws:
  `Exception`