public class ByteArrayCoder extends AtomicCoder<byte[]>
Coder for byte[].
The encoding format is as follows:
byte[] is the only value in the stream), the
bytes are read/written directly.VarIntCoder.Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
byte[] |
decode(java.io.InputStream inStream)
Decodes a value of type
T from the given input stream in
the given context. |
byte[] |
decode(java.io.InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(byte[] value,
java.io.OutputStream outStream)
Encodes the given value of type
T onto the given output stream. |
void |
encode(byte[] value,
java.io.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,
java.io.OutputStream outStream,
Coder.Context context)
Encodes the provided
value with the identical encoding to encode(byte[], java.io.OutputStream), but with
optimizations that take ownership of the value. |
java.util.List<? extends Coder<?>> |
getCoderArguments()
|
protected long |
getEncodedElementByteSize(byte[] value)
Returns the size in bytes of the encoded value using this coder.
|
TypeDescriptor<byte[]> |
getEncodedTypeDescriptor()
Returns the
TypeDescriptor for the type encoded. |
boolean |
isRegisterByteSizeObserverCheap(byte[] value)
Returns whether
Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver) 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() |
java.lang.Object |
structuralValue(byte[] value)
Returns an object with an
Object.equals() method that represents structural equality on
the argument. |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
equals, getComponents, hashCodeconsistentWithEquals, toStringregisterByteSizeObserver, verifyDeterministic, verifyDeterministicpublic static ByteArrayCoder of()
public void encode(byte[] value,
java.io.OutputStream outStream)
throws java.io.IOException,
CoderException
CoderT onto the given output stream.encode in class Coder<byte[]>java.io.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic void encode(byte[] value,
java.io.OutputStream outStream,
Coder.Context context)
throws java.io.IOException,
CoderException
CoderT onto the given output stream
in the given context.encode in class Coder<byte[]>java.io.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic void encodeAndOwn(byte[] value,
java.io.OutputStream outStream,
Coder.Context context)
throws java.io.IOException,
CoderException
value with the identical encoding to encode(byte[], java.io.OutputStream), but with
optimizations that take ownership of the value.
Once passed to this method, value should never be observed or mutated again.
java.io.IOExceptionCoderExceptionpublic byte[] decode(java.io.InputStream inStream)
throws java.io.IOException,
CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.decode in class Coder<byte[]>java.io.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic byte[] decode(java.io.InputStream inStream,
Coder.Context context)
throws java.io.IOException,
CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.decode in class Coder<byte[]>java.io.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic java.util.List<? extends Coder<?>> getCoderArguments()
AtomicCoderCoder for a parameterized type, returns the
list of Coders being used for each of the parameters in the same order they appear
within the parameterized type's type signature. If this cannot be done, or this
Coder does not encode/decode a parameterized type, returns the empty list..getCoderArguments in class AtomicCoder<byte[]>public void verifyDeterministic()
AtomicCoderCoder.NonDeterministicException if the coding is not deterministic.
In order for a Coder to be considered deterministic,
the following must be true:
Object.equals()
or Comparable.compareTo(), if supported) have the same
encoding.
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.
Unless overridden, does not throw. An AtomicCoder is presumed to be deterministic
verifyDeterministic in class AtomicCoder<byte[]>public java.lang.Object structuralValue(byte[] value)
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:
null should be a proper object with an
equals() method, even if the input value is null.
See also Coder.consistentWithEquals().
By default, if this coder is Coder.consistentWithEquals(), and the value is not null,
returns the provided object. Otherwise, encodes the value into a byte[], and returns
an object that performs array equality on the encoded bytes.
structuralValue in class StructuredCoder<byte[]>public boolean isRegisterByteSizeObserverCheap(byte[] value)
Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver) 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.
By default, returns false. The default Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver) implementation
invokes Coder.getEncodedElementByteSize(T) which requires re-encoding an element
unless it is overridden. This is considered expensive.
isRegisterByteSizeObserverCheap in class Coder<byte[]>true since getEncodedElementByteSize(byte[]) runs in
constant time using the length of the provided array.public TypeDescriptor<byte[]> getEncodedTypeDescriptor()
CoderTypeDescriptor for the type encoded.getEncodedTypeDescriptor in class StructuredCoder<byte[]>protected long getEncodedElementByteSize(byte[] value)
throws java.lang.Exception
CodergetEncodedElementByteSize in class Coder<byte[]>java.lang.Exception