Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.nubits.nubot.pricefeeds.GoogleUnofficialPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = getUrl(pair);
        String htmlString;/*from w  w  w.  jav  a 2s .  c o  m*/
        try {
            htmlString = Utils.getHTML(url, true);
        } catch (IOException ex) {
            LOG.severe(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double last = Utils.getDouble((Double) httpAnswerJson.get("rate"));
            last = Utils.round(last, 8);
            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.severe(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.fine("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }
}

From source file:de.schneider.dev.poi.service.GoogleMapGeoService.java

public void getGeoCoordinate(String location) throws EncoderException {

    LOG.info("Start GeoCoordination Google Map");

    // create default HttpClient
    HttpClient httpClient = new DefaultHttpClient();

    // get data from URI
    URLCodec urlCodec = new URLCodec("UTF-8");
    HttpGet httpGet = new HttpGet(DEFAULT_JSON_URI + urlCodec.encode(location) + "&sensor=false");
    LOG.info("HttpGet: " + httpGet);

    // get response
    try {//from   w  ww  .j  a va  2s  .  co  m
        HttpResponse httpResponse = httpClient.execute(httpGet);
        LOG.info("HttpResponse: " + httpResponse);
        LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode());
        LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase());

        HttpEntity httpEntity = httpResponse.getEntity();
        LOG.info("HttpEntity: " + httpEntity);
        LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming());
        if (httpEntity.isStreaming()) {
            InputStream inputStream = httpEntity.getContent();
            String content = EntityUtils.toString(httpEntity);
            LOG.info(content);
            inputStream.close();
        }

    } catch (ClientProtocolException cpe) {
        LOG.error(cpe.toString());
    } catch (IOException ioe) {
        LOG.error(ioe.toString());
    }
}

From source file:com.nubits.nubot.pricefeeds.CoinmarketcapnorthpolePriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {

    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String htmlString;/*from  w ww .j  a v a2s. c  om*/
        try {
            htmlString = Utils.getHTML(getUrl(pair), true);
        } catch (IOException ex) {
            LOG.severe(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double last = Utils.getDouble(httpAnswerJson.get("price"));
            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.severe(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.fine("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }

}

From source file:com.nubits.nubot.pricefeeds.feedservices.BitstampPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = "https://www.bitstamp.net/api/ticker/";
        String htmlString;//  w w w .j a  va 2 s .com
        try {
            htmlString = Utils.getHTML(url, true);
        } catch (IOException ex) {
            LOG.error(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double last = Double.valueOf((String) httpAnswerJson.get("last"));

            //Make the average between buy and sell
            last = Utils.round(last, 8);

            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.error(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.warn("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }
}

From source file:com.nubits.nubot.pricefeeds.feedservices.CoinmarketcapnorthpolePriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {

    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String htmlString;//  www .  j  a va  2  s . co m
        try {
            htmlString = Utils.getHTML(getUrl(pair), true);
        } catch (IOException ex) {
            LOG.error(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double last = Utils.getDouble(httpAnswerJson.get("price"));
            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.error(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.warn("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }

}

From source file:io.lightlink.output.BinaryDownloadResponseStream.java

@Override
public void writeInputStream(InputStream value) {
    try {// ww  w.j a v  a  2 s  .c o  m
        IOUtils.copy(value, response.getOutputStream());
    } catch (IOException e) {
        throw new RuntimeException(e.toString(), e);
    }
}

From source file:io.github.retz.scheduler.AdminConsole.java

private String maybeEncodeAsJSON(Object o) {
    try {// www.ja  va 2 s.  c o m
        return MAPPER.writeValueAsString(o);
    } catch (IOException e) {
        LOG.error(e.toString());
        return errorJSON(e.toString());
    }
}

From source file:net.bis5.slack.command.gcal.SlashCommandApi.java

@RequestMapping(path = "/execute", method = RequestMethod.POST)
public ResponseEntity<String> execute(@ModelAttribute RequestPayload payload) {
    log.info("Request: " + payload.toString());

    EventRequest event = payload.createEvent();
    log.info("Parsed Request: " + event.toString());

    try {/*from  w w  w.j  ava2  s  .co  m*/
        Event result = client.events().insert(config.getTargetCalendarId(), createEvent(event)).execute();
        log.info("Event Create Result: " + result.toString());

        ResponsePayload response = new ResponsePayload();
        Date date = toDate(event.getDate().atStartOfDay());
        Date start = toDate(LocalDateTime.of(event.getDate(), event.getFrom()));
        Date end = toDate(LocalDateTime.of(event.getDate(), event.getTo()));
        String user = payload.getUser_name();
        String title = event.getTitle();
        response.setText(String.format(
                "%s?????\n: %tY/%tm/%td\n: %tH:%tM\n: %tH:%tM\n??: %s", //
                user, date, date, date, start, start, end, end, title));

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            ObjectMapper mapper = new ObjectMapper();
            String responseBody = mapper.writeValueAsString(response);
            log.info("Response Payload: " + responseBody);
            Request.Post(payload.getResponse_url()).bodyString(responseBody, ContentType.APPLICATION_JSON)
                    .execute();
        }

        return ResponseEntity.ok(null);
    } catch (IOException ex) {
        log.error(ex.toString());
        return ResponseEntity.ok(ex.getMessage()); // OK??????????
    }
}

From source file:com.nubits.nubot.pricefeeds.BitstampEURPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = "https://www.bitstamp.net/api/eur_usd/";
        String htmlString;/*from  ww w.  j a  v  a2  s. c  om*/
        try {
            htmlString = Utils.getHTML(url, true);
        } catch (IOException ex) {
            LOG.severe(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double buy = Double.valueOf((String) httpAnswerJson.get("buy"));
            double sell = Double.valueOf((String) httpAnswerJson.get("sell"));

            //Make the average between buy and sell
            double last = Utils.round((buy + sell) / 2, 8);

            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.severe(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.fine("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }
}

From source file:com.nubits.nubot.pricefeeds.feedservices.BitstampEURPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = "https://www.bitstamp.net/api/eur_usd/";
        String htmlString;//from  w  ww  .  j av a2 s  . com
        try {
            htmlString = Utils.getHTML(url, true);
        } catch (IOException ex) {
            LOG.error(ex.toString());
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
        JSONParser parser = new JSONParser();
        try {
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double buy = Double.valueOf((String) httpAnswerJson.get("buy"));
            double sell = Double.valueOf((String) httpAnswerJson.get("sell"));

            //Make the average between buy and sell
            double last = Utils.round((buy + sell) / 2, 8);

            lastRequest = System.currentTimeMillis();
            lastPrice = new LastPrice(false, name, pair.getOrderCurrency(),
                    new Amount(last, pair.getPaymentCurrency()));
            return lastPrice;
        } catch (Exception ex) {
            LOG.error(ex.toString());
            lastRequest = System.currentTimeMillis();
            return new LastPrice(true, name, pair.getOrderCurrency(), null);
        }
    } else {
        LOG.warn("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms "
                + "before making a new request. Now returning the last saved price\n\n");
        return lastPrice;
    }
}