com.google.cloud.dataflow.sdk.coders

## Class ByteArrayCoder

- 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.ByteArrayCoder

All Implemented Interfaces:
  Coder<byte[]>, Serializable

    public class ByteArrayCoder
    extends AtomicCoder<byte[]>

A `Coder` for `byte[]`.

The encoding format is as follows:

- If in a non-nested context (the `byte[]` is the only value in the stream), the bytes are read/written directly.
- If in a nested context, the bytes are prefixed with the length of the array, encoded via a `VarIntCoder`.

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
`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.
`void` `encodeAndOwn(byte[] value, OutputStream outStream, Coder.Context context)` Encodes the provided `value` with the identical encoding to `encode(byte[], java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)`, but with optimizations that take ownership of the value.
`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 ByteArrayCoder` `of()`
`Object` `structuralValue(byte[] value)` Returns an object with an `Object.equals()` method that represents structural equality on the argument.

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

`getCoderArguments, getInstanceComponents`

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

`verifyDeterministic`

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

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

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

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

### Method Detail

#### of

    public static ByteArrayCoder 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

#### encodeAndOwn

    public void encodeAndOwn(byte[] value,
                             OutputStream outStream,
                             Coder.Context context)
                      throws IOException,
                             CoderException

Encodes the provided `value` with the identical encoding to `encode(byte[], java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)`, but with optimizations that take ownership of the value.

Once passed to this method, `value` should never be observed or mutated again.

Throws:
  `IOException`
  `CoderException`

#### 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

#### structuralValue

    public Object structuralValue(byte[] value)

Returns an object with an `Object.equals()` method that represents structural equality on the argument.

For any two values `x` and `y` of type `T`, if their encoded bytes are the same, then it must be the case that `structuralValue(x).equals(@code structuralValue(y)`.

Most notably:

- The structural value for an array coder should perform a structural comparison of the contents of the arrays, rather than the default behavior of comparing according to object identity.
- The structural value for a coder accepting `null` should be a proper object with an `equals()` method, even if the input value is `null`.

See also `Coder.consistentWithEquals()`.

Specified by:
  `structuralValue` in interface `Coder<byte[]>`
Overrides:
  `structuralValue` in class `StandardCoder<byte[]>`
Returns:
  objects that are equal if the two arrays contain the same bytes.

#### 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` since `getEncodedElementByteSize(byte[], com.google.cloud.dataflow.sdk.coders.Coder.Context)` runs in constant time using the `length` of the provided array.

#### getEncodedElementByteSize

    protected long getEncodedElementByteSize(byte[] value,
                                             Coder.Context context)
                                      throws Exception

Description copied from class: `StandardCoder`
Returns the size in bytes of the encoded value using this coder.

Overrides:
  `getEncodedElementByteSize` in class `StandardCoder<byte[]>`
Throws:
  `Exception`