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.
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().
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