private static void checkFinishReason(FinishReason finishReason) {
    if (finishReason == FinishReason.SAFETY) {
      throw new IllegalArgumentException("The response is blocked due to safety reason.");
    } else if (finishReason == FinishReason.RECITATION) {
      throw new IllegalArgumentException("The response is blocked due to unauthorized citations.");
    }
  }
Aggregates a stream of responses into a single GenerateContentResponse.
java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/generativeai/ResponseHandler.java