'How to consume streaming JSON data from an HTTP call in Java

I am trying to switch to a new data feed provider API that works fine in CURL with this command

curl -X GET 'https://api.activetick.com/stream.json?sessionid=12225759b81b421a9ce69db19c9222d8&symbols=AAPL_S-U,IBM_S-U' -H "Connection: Keep-Alive" -H "Accept: application/json"

Our system is running in Java and I am unsure how to build code that can consume the JSON formatted messages the stream provides, below is how I am trying to do it now and when reading from in the input stream returned it throws unexpected end of line exception.

static  void test() throws IOException {
        try {
            HttpsURLConnection c = (HttpsURLConnection) new URL("https://api.activetick.com/stream.json?sessionid=12225759b81b421a9ce69db19c9222d8&symbols=AAPL_S-U,IBM_S-U")
                    .openConnection();
            c.setRequestMethod("POST");
            c.setRequestProperty("Connection", "Keep-Alive");
            c.setRequestProperty("Accept-Encoding", "json");
            c.connect();
            InputStream io = c.getInputStream();
            
            BufferedInputStream bis = new BufferedInputStream(io);
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            for (int result = bis.read(); result != -1; result = bis.read()) {
                buf.write((byte) result);
            }       
        } catch (Exception e) {
            System.err.println("here");
        }
    
        
    }

Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source