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.CcedkPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    String url = TradeUtils.getCCEDKTickerUrl(pair);
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String htmlString;//from   ww w .  j  a  v  a  2 s . co 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 {
            //{"errors":false,"response":{"entity":{"pair_id":"2","min":"510","max":"510","avg":"510","vol":"0.0130249"}}}
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            JSONObject tickerObject = (JSONObject) httpAnswerJson.get("response");
            JSONObject entityObject = (JSONObject) tickerObject.get("entity");

            double last = Double.valueOf((String) entityObject.get("avg"));

            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.CcedkPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    String url = TradeUtilsCCEDK.getCCEDKTickerUrl(pair);
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String htmlString;//  ww w .j  a  v a2s .c o  m
        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 {
            //{"errors":false,"response":{"entity":{"pair_id":"2","min":"510","max":"510","avg":"510","vol":"0.0130249"}}}
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            JSONObject tickerObject = (JSONObject) httpAnswerJson.get("response");
            JSONObject entityObject = (JSONObject) tickerObject.get("entity");

            double last = Double.valueOf((String) entityObject.get("avg"));

            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:NCDSearch.NCDSearch.java

private void search(String path, int compression) {

    byte[] filebytes;

    File directory = new File(path);

    File[] files = directory.listFiles();
    double score;

    for (File file : files) {
        if (file.isDirectory()) {
            search(file.getPath(), compression);
        } else {/*www .jav a2  s.c om*/
            try {

                FileInputStream reader = new FileInputStream(file);
                while (reader.available() > 0) {

                    filebytes = new byte[Math.min(reader.available(), 10 * targetbytes.length)];
                    reader.read(filebytes);
                    score = NCD(filebytes, targetbytes, compression);

                    if (score < bestscore) {
                        this.bestscore = score;
                        this.bestpath = file.getPath();
                    }
                }

            } catch (IOException e) {
                System.out.println(e.toString());
                System.out.println("Could not read file!" + file.getPath());
            }
        }
    }
}

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

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = getUrl(pair);
        String htmlString;/*  ww  w .j  ava  2  s. c o m*/
        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 {
            //Sample asnwer : // [ { "id": "-2001" ,"t" : "GBPUSD" ,"e" : "CURRENCY" ,"l" : "1.5187" ,"l_fix" : "" ,"l_cur" : "" ,"s": "0" ,"ltt":"" ,"lt" : "Apr 25, 11:55AM GMT" ,"lt_dts" : "2015-04-25T11:55:00Z" ,"c" : "0.00000" ,"c_fix" : "" ,"cp" : "0.000" ,"cp_fix" : "" ,"ccol" : "chb" ,"pcls_fix" : "" } ]
            htmlString = htmlString.replace("//", "").replace("[", "").replace("]", "");

            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            double last = Utils.getDouble((String) httpAnswerJson.get("l"));
            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.ibm.storlet.common.StorletObjectOutputStream.java

@SuppressWarnings("unchecked")
public void setMetadata(Map<String, String> md) throws StorletException {
    JSONObject jobj = new JSONObject();
    Iterator<Map.Entry<String, String>> it = md.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
        jobj.put((String) pairs.getKey(), (String) pairs.getValue());
        it.remove();/*  w  w  w . jav a2s .  c o m*/
    }
    try {
        MetadataStream_.write(jobj.toString().getBytes());
        MetadataStream_.close();
    } catch (IOException e) {
        throw new StorletException("Failed to set metadata " + e.toString());
    }
}

From source file:hochschuledarmstadt.photostream_tools.LikeOrDislikePhotoAsyncTask.java

@Override
protected Boolean doInBackground(Void... params) {
    try {//from w ww .j ava  2 s .c  o m
        likeOrDislikePhoto();
        return true;
    } catch (IOException e) {
        Logger.log(TAG, LogLevel.ERROR, e.toString());
        postError(new HttpError(-1, e.toString()));
    } catch (JSONException e) {
        Logger.log(TAG, LogLevel.ERROR, e.toString());
    } catch (HttpPhotoStreamException e) {
        Logger.log(TAG, LogLevel.ERROR, e.toString());
        postError(e.getHttpError());
    }
    return false;
}

From source file:com.nubits.nubot.pricefeeds.YahooPriceFeed.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. j  av a  2  s .co  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));
            JSONObject query = (JSONObject) httpAnswerJson.get("query");
            JSONObject results = (JSONObject) query.get("results");
            JSONObject rate = (JSONObject) results.get("rate");

            double last = Utils.getDouble((String) rate.get("Rate"));

            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.YahooPriceFeed.java

@Override
public LastPrice getLastPrice(CurrencyPair pair) {
    long now = System.currentTimeMillis();
    long diff = now - lastRequest;
    if (diff >= refreshMinTime) {
        String url = getUrl(pair);
        String htmlString;// www .jav a 2  s . c  o  m
        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));
            JSONObject query = (JSONObject) httpAnswerJson.get("query");
            JSONObject results = (JSONObject) query.get("results");
            JSONObject rate = (JSONObject) results.get("rate");

            double last = Utils.getDouble((String) rate.get("Rate"));

            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:ImageLoaderMIDlet.java

public void startApp() {
    final Display display = Display.getDisplay(this);

    Form mainForm = new Form("Loading...");
    display.setCurrent(mainForm);//  w ww . j  a  v  a2s.c o m

    final Form imageForm = new Form("Image");
    imageForm.addCommand(new Command("Exit", Command.EXIT, 0));
    imageForm.setCommandListener(new CommandListener() {
        public void commandAction(Command c, Displayable s) {
            notifyDestroyed();
        }
    });

    Thread t = new Thread() {
        public void run() {
            try {
                String URL = "http://localhost/Duke.png";
                Image image = loadImage(URL);
                mItem = new ImageItem(null, image, 0, null);
            } catch (IOException ioe) {
                mItem = new StringItem(null, ioe.toString());
            }
            imageForm.append(mItem);
            display.setCurrent(imageForm);
        }
    };
    t.start();
}

From source file:net.oletalk.hellospringboot.controller.S3Controller.java

@RequestMapping("/from")
void from(@RequestParam(value = "key") String objectKey, HttpServletResponse response) {
    try {/*from ww  w . j a v a2 s.c  o m*/
        service.writeDocument(objectKey, response.getOutputStream());
    } catch (IOException ioe) {
        try {
            response.getWriter().println("Error in response: " + ioe.toString());
        } catch (IOException e) {
            LOG.error(e);
        }
    } catch (S3Exception ex) {
        LOG.error(ex);
    }
}