lukecwik commented on code in PR #17802:
URL: https://github.com/apache/beam/pull/17802#discussion_r904029963
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/CoderUtils.java:
##########
@@ -107,6 +107,25 @@ public static <T> T decodeFromByteArray(
}
}
+ /** Decodes a value from the given stream, validating that no bytes are
remaining once decoded. */
+ public static <T> T decodeFromStream(Coder<T> coder, InputStream stream)
throws IOException {
+ return decodeFromStream(coder, stream, Coder.Context.OUTER);
+ }
+
+ /**
+ * Decodes a value from the given stream using a given context, validating
that no bytes are
+ * remaining once decoded.
+ */
+ public static <T> T decodeFromStream(Coder<T> coder, InputStream stream,
Coder.Context context)
+ throws IOException {
+ T result = coder.decode(stream, context);
+ if (stream.available() != 0) {
+ throw new CoderException(
+ stream.available() + " unexpected extra bytes after decoding " +
result);
+ }
+ return result;
+ }
Review Comment:
It is on the `package-info` which is how we add annotations to packages
https://github.com/apache/beam/blob/45bebebdafe7c8df707259ca11c5633aebdb3933/sdks/java/core/src/main/java/org/apache/beam/sdk/util/package-info.java#L24
but also understand that people will use it anyways and/or may not be aware of
package level annotations.
We have made some breaking changes in `util` but it is rare as it is
typically easy to maintain the existing code and just add the new use case
under a new method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]