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:org.jfree.chart.demo.ImageMapDemo5.java

/**
 * Saves the chart image and HTML.//from w  w  w. j a va 2 s .c o m
 */
public void saveImageAndHTML() {

    // create a dataset
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    final JFreeChart chart = createChart(dataset);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("areachart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("areachart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"areachart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
}

From source file:HttpConnections.RestConnFactory.java

public ResponseContents RestRequest(HttpRequestBase httprequest) throws IOException {
    HttpResponse httpResponseTemp = null;
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
    HttpConnectionParams.setSoTimeout(httpParams, 30000);
    this.httpclient = new DefaultHttpClient(httpParams);

    try {//from  ww w . j  a  v  a  2 s  . co  m
        httpResponseTemp = this.httpclient.execute(httprequest);
    } catch (IOException ex) {
        System.out.println("An error occured while executing the request. Message: " + ex);
        this.responseObj.setContents(ex.toString());
    } finally {
        if (httpResponseTemp != null) {
            this.httpResponse = httpResponseTemp;
            this.responseObj.setStatus(this.httpResponse.getStatusLine().toString());
            if (this.httpResponse.getEntity() == null
                    || this.httpResponse.getStatusLine().toString().contains("500")) {
                this.responseObj.setContents("No Content");
            } else {
                this.responseObj.setContents(EntityUtils.toString(this.httpResponse.getEntity()));
            }
        }
        this.httpclient.close();
        return this.responseObj;
    }
}

From source file:org.apache.storm.elasticsearch.trident.EsState.java

/**
 * Store current state to ElasticSearch.
 *
 * @param tuples list of tuples for storing to ES.
 *               Each tuple should have relevant fields (source, index, type, id) for EsState's tupleMapper to extract ES document.
 * @throws IOException/*from www  .ja  v a 2s.  c o m*/
 * @throws UnsupportedEncodingException
 */
public void updateState(List<TridentTuple> tuples) {
    try {
        String bulkRequest = buildRequest(tuples);
        Response response = client.performRequest("post", "_bulk", new HashMap<>(),
                new StringEntity(bulkRequest.toString()));
        BulkIndexResponse bulkResponse = objectMapper.readValue(response.getEntity().getContent(),
                BulkIndexResponse.class);
        if (bulkResponse.hasErrors()) {
            LOG.warn("failed processing bulk index requests: " + bulkResponse.getFirstError() + ": "
                    + bulkResponse.getFirstResult());
            throw new FailedException();
        }
    } catch (IOException e) {
        LOG.warn("failed processing bulk index requests: " + e.toString());
        throw new FailedException(e);
    }
}

From source file:ReaderUtil.java

/**
 * Dumps the contents of the {@link Reader} to a String, closing the {@link Reader} when done.
 *///from www  .  j a v  a  2s . com
public String readToString(Reader in) throws IOException {
    StringBuffer buf = null;
    try {
        buf = pool.borrowObject();
        for (int c = in.read(); c != -1; c = in.read()) {
            buf.append((char) c);
        }
        return buf.toString();
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("Unable to borrow buffer from pool" + e.toString());
    } finally {
        try {
            in.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            if (null != buf) {
                pool.returnObject(buf);
            }
        } catch (Exception e) {
            // ignored
        }
    }
}

From source file:com.lyonsdensoftware.vanitymirror.PythonConnectionThread.java

@Override
public void run() {
    // Try connecting to the master server
    try {//ww w . j  a  va2 s .  c  om

        // Create a socket to connect to the server
        this.socket = new Socket(this.mainWindow.getConfigFile().getHostname(),
                this.mainWindow.getConfigFile().getPort());

        // Note it in the log
        log.info("LOG", "Connect to MasterServer at IP: " + socket.getInetAddress().getHostAddress()
                + " on PORT: " + socket.getPort());

        connectedToServer = true;

        // Create an input stream to receive data from the server
        mainWindow.setFromServer(new DataInputStream(socket.getInputStream()));

        // Create an output stream to send data to the server
        mainWindow.setToServer(new DataOutputStream(socket.getOutputStream()));

        // Main Loop
        while (runThread) {

            // Check for data from the server
            BufferedReader in = new BufferedReader(new InputStreamReader(mainWindow.getFromServer()));

            if (in.ready()) {
                // Convert in data to json
                Gson gson = new Gson();

                JSONObject json = new JSONObject(gson.fromJson(in.readLine(), JSONObject.class));

                if (json.keys().hasNext()) {
                    // handle the data
                    handleDataFromServer(json);
                } else {
                    System.out.println(json.toString());
                }
            }
        }

        // Loop not running now so close connection
        socket.close();
        mainWindow.getFromServer().close();
        mainWindow.getToServer().close();
    } catch (IOException ex) {
        log.error("ERROR", ex.toString());
    }
}

From source file:com.photon.phresco.nativeapp.unit.test.testcases.F_ProductReviewActivityTest.java

/**
 * get the product review comments/*w  w w  .  j ava2s. co m*/
 * from web server
 *
 */

@Test
public final void testProductReview() {
    try {
        PhrescoLogger.info(TAG + " testProductReview -------------- START ");

        int productId = 1;
        JSONObject prodReviewJSONObj = JSONHelper
                .getJSONObjectFromURL(Constants.getWebContextURL() + Constants.getRestAPI()
                        + Constants.PRODUCTS_URL + productId + "/" + Constants.PRODUCT_REVIEW_URL);
        JSONObject productReviewArray = prodReviewJSONObj.getJSONObject("review");
        assertTrue(productReviewArray.length() > 0);

        PhrescoLogger.info(TAG + " testProductReview -------------- END ");
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "testProductReview - IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (JSONException ex) {
        PhrescoLogger.info(TAG + "testProductReview - JSONException: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.photon.phresco.nativeapp.unit.test.testcases.I_RegistrationActivityTest.java

/**
 *  submit the registration form to web server
 *  and get response/*from  www.j  a v  a  2 s .c  om*/
 *
 */
@Test
public final void testRegistraion() {
    JSONObject jObjMain = new JSONObject();
    JSONObject jObj = new JSONObject();

    try {
        PhrescoLogger.info(TAG + " testRegistraion -------------- START ");

        jObj.put("firstName", "john");
        jObj.put("lastName", "albert");
        jObj.put("email", "john_albert@phresco.com");
        jObj.put("phoneNumber", "");
        jObj.put("password", "123");

        jObjMain.put("register", jObj);

        JSONObject responseJSON = null;
        responseJSON = JSONHelper.postJSONObjectToURL(
                Constants.getWebContextURL() + Constants.getRestAPI() + Constants.REGISTER_POST_URL,
                jObjMain.toString());
        assertNotNull("Login failed", responseJSON.length() > 0);

        PhrescoLogger.info(TAG + " testRegistraion -------------- END ");

    } catch (IOException ex) {
        PhrescoLogger.info(TAG + " - testRegistraion  - IOException : " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (JSONException ex) {
        PhrescoLogger.info(TAG + " - testRegistraion  - JSONException : " + ex.toString());
        PhrescoLogger.warning(ex);
    }

}

From source file:com.ibm.connectors.splunklog.SplunkHttpConnection.java

public Properties sendLogEvent(SplunkConnectionData connData, byte[] thePayload, Properties properties)
        throws ConnectorException {
    HttpClient myhClient = HttpClients.custom().setConnectionManager(this.cm).build();

    HttpClientContext myhContext = HttpClientContext.create();

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(connData.getUser(), connData.getPass()));
    AuthCache authCache = new BasicAuthCache();
    authCache.put(new HttpHost(connData.getHost(), Integer.parseInt(connData.getPort()), connData.getScheme()),
            new BasicScheme());

    myhContext.setCredentialsProvider(credsProvider);
    myhContext.setAuthCache(authCache);/*from  www  . ja va 2s  .  c om*/

    HttpPost myhPost = new HttpPost(connData.getSplunkURI());

    ByteArrayEntity payload = new ByteArrayEntity(thePayload);
    try {
        myhPost.setEntity(payload);
        HttpResponse response = myhClient.execute(myhPost, myhContext);
        Integer statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200 && !connData.getIgnoreSplunkErrors()) {
            throw new ConnectorException(
                    "Error posting log event to Splunk: " + response.getStatusLine().toString());
        }
        System.out.println(response.getStatusLine().toString());
        properties.setProperty("status", String.valueOf(statusCode));
        Integer leasedConns = Integer
                .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getLeased());
        properties.setProperty("conns_leased", leasedConns.toString());
        Integer availConns = Integer
                .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getAvailable());
        properties.setProperty("conns_available", availConns.toString());
    } catch (IOException e) {
        e.fillInStackTrace();
        throw new ConnectorException(e.toString());
    }
    return properties;
}

From source file:com.cisco.oss.foundation.http.apache.ApacheHttpResponse.java

@Override
public void close() {
    try {//from w  w  w .j a v a 2  s .  co  m
        if (httpResponse instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) httpResponse).close();
        }
    } catch (IOException e) {
        throw new ClientException(e.toString(), e);
    }
    isClosed = true;
}

From source file:com.buaa.cfs.utils.VersionInfo.java

protected VersionInfo(String component) {
    info = new Properties();
    String versionInfoFile = component + "-version-info.properties";
    InputStream is = null;/*from w  w  w  .  j a v a 2 s.c  om*/
    try {
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(versionInfoFile);
        if (is == null) {
            throw new IOException("Resource not found");
        }
        info.load(is);
    } catch (IOException ex) {
        LogFactory.getLog(getClass()).warn("Could not read '" + versionInfoFile + "', " + ex.toString(), ex);
    } finally {
        IOUtils.closeStream(is);
    }
}