public class ByteArrayCoder extends AtomicCoder<byte[]>
ByteArrayCoder encodes byte[] objects.
If in a nested context, prefixes the encoded array with its
length, encoded via a VarIntCoder.
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
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 true since registerByteSizeObserver() runs in constant time.
|
static ByteArrayCoder |
of() |
Object |
structuralValue(byte[] value)
Returns an object with an
Object.equals() method
that represents structural equality on the argument. |
getCoderArguments, getInstanceComponentsverifyDeterministicasCloudObject, consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodingId, hashCode, registerByteSizeObserver, toString, verifyDeterministic, verifyDeterministicpublic static ByteArrayCoder of()
public void encode(byte[] value,
OutputStream outStream,
Coder.Context context)
throws IOException,
CoderException
CoderT onto the given output stream
in the given context.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic void encodeAndOwn(byte[] value,
OutputStream outStream,
Coder.Context context)
throws IOException,
CoderException
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.
IOExceptionCoderExceptionpublic byte[] decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic Object structuralValue(byte[] value)
CoderObject.equals() method
that represents structural equality on the argument.
(and also implements a compatible Object.hashCode()).
For any two objects of type T, if their encoded bytes
are the same, then their structural values are equal
according to Object.equals().
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.
See also Coder.consistentWithEquals().
structuralValue in interface Coder<byte[]>structuralValue in class StandardCoder<byte[]>public boolean isRegisterByteSizeObserverCheap(byte[] value,
Coder.Context context)
isRegisterByteSizeObserverCheap in interface Coder<byte[]>isRegisterByteSizeObserverCheap in class StandardCoder<byte[]>protected long getEncodedElementByteSize(byte[] value,
Coder.Context context)
throws Exception
StandardCodergetEncodedElementByteSize in class StandardCoder<byte[]>Exception