public static JSONObject readJsonFromChannel(RetainingAsyncWritableChannel channel) throws RestServiceException {
    try (InputStream inputStream = channel.consumeContentAsInputStream()) {
      return new JSONObject(new JSONTokener(new InputStreamReader(inputStream, StandardCharsets.UTF_8)));
    } catch (Exception e) {
      throw new RestServiceException("Could not parse json request body", e, RestServiceErrorCode.BadRequest);
    }
  }
Parse a {@link JSONObject} from the data in {@code channel}. This assumes that the data is UTF-8 encoded.
@param channel the {@link RetainingAsyncWritableChannel} that contains the JSON data.
@return a {@link JSONObject}.
@throws IOException if closing the {@link InputStream} fails.
@throws RestServiceException if JSON parsing fails.
ambry-frontend/src/main/java/com/github/ambry/frontend/FrontendUtils.java