You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/07/02 18:02:44 UTC

[GitHub] [beam] steveniemitz commented on a diff in pull request #17802: [BEAM-14545] Optimize copies in dataflow v1 shuffle reader.

steveniemitz commented on code in PR #17802:
URL: https://github.com/apache/beam/pull/17802#discussion_r912386527


##########
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:
   done, renamed to `decodeFromByteString`



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org