Code example for URLConnection

Methods: connect, getInputStream, setConnectTimeout, setReadTimeout

0
                } 
            } 
            // Handle LTC/EUR special since we have to do maths 
            final URL URL = new URL("https://btc-e.com/api/2/btc_eur/ticker");
            final URLConnection connection = URL.openConnection();
            connection.setConnectTimeout(TIMEOUT_MS);
            connection.setReadTimeout(TIMEOUT_MS);
            connection.connect();
            final StringBuilder content = new StringBuilder();
 
            Reader reader = null;
            try 
            { 
                reader = new InputStreamReader(new BufferedInputStream(connection.getInputStream(), 1024));
                IOUtils.copy(reader, content);
                final JSONObject head = new JSONObject(content.toString());
                JSONObject ticker = head.getJSONObject("ticker");
                Double avg = ticker.getDouble("avg");
                // This is bitcoins priced in euros.  We want LTC! 
                avg *= btcRate;
                rates.put("EUR", new ExchangeRate("EUR", Utils.toNanoCoins(String.format("%4f", avg)), URL.getHost()));