T - The type of objects coded.public final class StringDelegateCoder<T> extends CustomCoder<T>
Coder that wraps a Coder<String>
and encodes/decodes values via string representations.
To decode, the input byte stream is decoded to
a String, and this is passed to the single-argument
constructor for T.
To encode, the input value is converted via toString(),
and this string is encoded.
In order for this to operate correctly for a class Clazz,
it must be the case for any instance x that
x.equals(new Clazz(x.toString())).
This method of encoding is not designed for ease of evolution of Clazz;
it should only be used in cases where the class is stable or the encoding is not
important. If evolution of the class is important, see ProtoCoder, AvroCoder,
or JAXBCoder.
Coder.Context, Coder.NonDeterministicException| Modifier | Constructor and Description |
|---|---|
protected |
StringDelegateCoder(Class<T> clazz) |
| Modifier and Type | Method and Description |
|---|---|
T |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(T value,
OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
boolean |
equals(Object o) |
Collection<String> |
getAllowedEncodings()
A collection of encodings supported by
Coder.decode(java.io.InputStream, org.apache.beam.sdk.coders.Coder.Context) in addition to the encoding
from Coder.getEncodingId() (which is assumed supported). |
String |
getEncodingId()
The encoding id is the fully qualified name of the encoded/decoded class.
|
int |
hashCode() |
static <T> StringDelegateCoder<T> |
of(Class<T> clazz) |
Object |
structuralValue(T value)
Returns an object with an
Object.equals() method that represents structural equality
on the argument. |
String |
toString() |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
asCloudObject, ofgetCoderArguments, getInstanceComponentsconsistentWithEquals, getComponents, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, verifyDeterministic, verifyDeterministicpublic static <T> StringDelegateCoder<T> of(Class<T> clazz)
public String toString()
toString in class StandardCoder<T>public boolean equals(Object o)
StandardCoderequals in class StandardCoder<T>true if the two StandardCoder instances have the
same class and equal components.public int hashCode()
hashCode in class StandardCoder<T>public void encode(T value, OutputStream outStream, Coder.Context context) throws CoderException, IOException
CoderT onto the given output stream
in the given context.CoderException - if the value could not be encoded for some reasonIOException - if writing to the OutputStream fails
for some reasonpublic T decode(InputStream inStream, Coder.Context context) throws CoderException, IOException
CoderT from the given input stream in
the given context. Returns the decoded value.CoderException - if the value could not be decoded for some reasonIOException - if reading from the InputStream fails
for some reasonpublic void verifyDeterministic()
throws Coder.NonDeterministicException
CustomCoderCoder.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.
verifyDeterministic in interface Coder<T>verifyDeterministic in class CustomCoder<T>Coder.NonDeterministicException - if this coder is not deterministic.public Object structuralValue(T value) throws Exception
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<T>structuralValue in class StandardCoder<T>Exceptionpublic String getEncodingId()
getEncodingId in interface Coder<T>getEncodingId in class CustomCoder<T>public Collection<String> getAllowedEncodings()
CoderCoder.decode(java.io.InputStream, org.apache.beam.sdk.coders.Coder.Context) in addition to the encoding
from Coder.getEncodingId() (which is assumed supported).
This information is not currently used for any purpose. It is descriptive only, and this method is subject to change.
getAllowedEncodings in interface Coder<T>getAllowedEncodings in class StandardCoder<T>Coder.getEncodingId()