use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.io.CountingInputStream in project beam by apache.
the class CoderProperties method decode.
@VisibleForTesting
static <T> T decode(Coder<T> coder, Coder.Context context, byte[] bytes) throws CoderException, IOException {
@SuppressWarnings("unchecked") Coder<T> deserializedCoder = SerializableUtils.clone(coder);
byte[] buffer;
if (Objects.equals(context, Coder.Context.NESTED)) {
buffer = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, buffer, 0, bytes.length);
buffer[bytes.length] = 1;
} else {
buffer = bytes;
}
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(buffer));
T value = deserializedCoder.decode(new UnownedInputStream(cis), context);
assertThat("consumed bytes equal to encoded bytes", cis.getCount(), equalTo((long) bytes.length));
return value;
}
Aggregations