package org.jabref.logic.importer.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

import org.jabref.logic.importer.ParseException;

import kong.unirest.json.JSONObject;

/**
 * Converts an {@link InputStream} into a {@link JSONObject}.
 */
public class JsonReader {

    public static JSONObject toJsonObject(InputStreamReader input) throws ParseException {
        BufferedReader streamReader = new BufferedReader(input);
        StringBuilder responseStrBuilder = new StringBuilder();

        try {
            String inputStr;
            while ((inputStr = streamReader.readLine()) != null) {
                responseStrBuilder.append(inputStr);
            }
            return new JSONObject(responseStrBuilder.toString());
        } catch (IOException e) {
            throw new ParseException(e);
        }
    }

    public static JSONObject toJsonObject(InputStream input) throws ParseException {
        return toJsonObject(new InputStreamReader(input, StandardCharsets.UTF_8));
    }
}

@@ -777,24 +777,155 @@
           %7D%0A
+            if (responseStrBuilder.toString().isBlank()) %7B%0A                throw new ParseException(%22Empty input!%22);%0A            %7D%0A
             

throw parseException when input is empty