class JsonStreamParser implements Iterator<JsonElement> {
  private final JsonReader parser;
  private final Object lock;

  /**
   * @param json The string containing JSON elements concatenated to each other.
   * @since 1.4
   */
  public JsonStreamParser(String json) {
    this(new StringReader(json));
  }

  /**
   * @param reader The data stream containing JSON elements concatenated to each other.
   * @since 1.4
   */
  public JsonStreamParser(Reader reader) {
    parser = new JsonReader(reader);
    parser.setStrictness(Strictness.LENIENT);
    lock = new Object();
  }

  /**
   * Returns the next available {@link JsonElement} on the reader. Throws a {@link
   * NoSuchElementException} if no element is available.
   *
   * @return the next available {@code JsonElement} on the reader.
   * @throws JsonParseException if the incoming stream is malformed JSON.
   * @throws NoSuchElementException if no {@code JsonElement} is available.
   * @since 1.4
   */
  @Override
  public JsonElement next() throws JsonParseException {<FILL_FUNCTION_BODY>}

  /**
   * Returns true if a {@link JsonElement} is available on the input for consumption
   *
   * @return true if a {@link JsonElement} is available on the input, false otherwise
   * @throws JsonParseException if the incoming stream is malformed JSON.
   * @since 1.4
   */
  @Override
  public boolean hasNext() {
    synchronized (lock) {
      try {
        return parser.peek() != JsonToken.END_DOCUMENT;
      } catch (MalformedJsonException e) {
        throw new JsonSyntaxException(e);
      } catch (IOException e) {
        throw new JsonIOException(e);
      }
    }
  }

  /**
   * This optional {@link Iterator} method is not relevant for stream parsing and hence is not
   * implemented.
   *
   * @since 1.4
   */
  @Override
  public void remove() {
    throw new UnsupportedOperationException();
  }
}

    if (!hasNext()) {
      throw new NoSuchElementException();
    }

    try {
      return Streams.parse(parser);
    } catch (StackOverflowError e) {
      throw new JsonParseException("Failed parsing JSON source to Json", e);
    } catch (OutOfMemoryError e) {
      throw new JsonParseException("Failed parsing JSON source to Json", e);
    }
  
<no_super_class>