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(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, org.apache.beam.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, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.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. |
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, org.apache.beam.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)
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().
structuralValue in interface Coder<byte[]>structuralValue in class StandardCoder<byte[]>public boolean isRegisterByteSizeObserverCheap(byte[] value,
Coder.Context context)
Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.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.
isRegisterByteSizeObserverCheap in interface Coder<byte[]>isRegisterByteSizeObserverCheap in class StandardCoder<byte[]>true since getEncodedElementByteSize(byte[], org.apache.beam.sdk.coders.Coder.Context) runs in
constant time using the length of the provided array.protected long getEncodedElementByteSize(byte[] value,
Coder.Context context)
throws Exception
StandardCodergetEncodedElementByteSize in class StandardCoder<byte[]>Exception