List of usage examples for java.io IOException toString
public String toString()
From source file:LineIterator.java
/** * Indicates whether the <code>Reader</code> has more lines. * If there is an <code>IOException</code> then {@link #close()} will * be called on this instance.//from w w w . j a v a 2 s . c o m * * @return <code>true</code> if the Reader has more lines * @throws IllegalStateException if an IO exception occurs */ public boolean hasNext() { if (cachedLine != null) { return true; } else if (finished) { return false; } else { try { while (true) { String line = bufferedReader.readLine(); if (line == null) { finished = true; return false; } else if (isValidLine(line)) { cachedLine = line; return true; } } } catch (IOException ioe) { close(); throw new IllegalStateException(ioe.toString()); } } }
From source file:HttpConnections.ThreadedRestConnFactory.java
@Override public void run() { try {/*w ww . j a v a 2 s .c o m*/ HttpResponse httpResponseTemp = null; HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 30000); HttpConnectionParams.setSoTimeout(httpParams, 30000); this.httpclient = new DefaultHttpClient(httpParams); Date startDate = new Date(); try { httpResponseTemp = this.httpclient.execute(this.httprequest); } catch (IOException ex) { System.out.println("An error occured while executing the request. Message: " + ex); this.responseObj.setStatus(ex.toString()); } this.responseObj.setEndDate(); this.responseObj.getDiffMilliseconds(startDate); if (httpResponseTemp == null) { this.httpclient.close(); } else { this.httpResponse = httpResponseTemp; this.responseObj.setStatus(this.httpResponse.getStatusLine().toString()); //System.out.println("Header:"+httpResponseTemp.getFirstHeader("x-request-id")+", ExecTime:"+this.responseObj.getExecTime()); this.httpclient.close(); } } catch (IOException ex) { Logger.getLogger(RestConnFactory.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:at.jps.sanction.model.queue.file.FileQueue.java
@Override public void close() { try {//from w w w. j a v a2s . com getQueue().close(); } catch (final IOException e) { logger.error("Error closing Queue (" + getName() + ") :" + e.toString()); logger.debug("Exception: ", e); } }
From source file:at.jps.sanction.model.queue.file.FileQueue.java
@Override public void clear() { try {/* ww w . j a v a 2 s .c om*/ getQueue().removeAll(); } catch (final IOException e) { logger.error("Error during cleanup...(" + getName() + ") :" + e.toString()); logger.debug("Exception: ", e); } }
From source file:teletype.model.vk.Auth.java
private StringBuilder getContentText(HttpResponse response) throws IOException { Integer status = response.getStatusLine().getStatusCode(); if (status == 200 || status == 302 || status == 401) { StringWriter content = new StringWriter(); try {/*from w w w .jav a2 s.c o m*/ IOUtils.copy(response.getEntity().getContent(), content); } catch (IOException e) { System.out.println("Unexpected error: " + e.toString()); e.printStackTrace(); throw e; } return new StringBuilder(content.toString()); } else { System.out.println("Unexpected behavior. Http response status: " + status); } return new StringBuilder(); }
From source file:com.juick.android.Utils.java
public static RESTResponse postForm(final Context context, final String url, ArrayList<NameValuePair> data) { try {//from w w w . j ava2 s .c om final String end = "\r\n"; final String twoHyphens = "--"; final String boundary = "****+++++******+++++++********"; URL apiUrl = new URL(url); final HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection(); conn.setConnectTimeout(10000); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); conn.connect(); OutputStream out = conn.getOutputStream(); PrintStream ps = new PrintStream(out); int index = 0; byte[] block = new byte[1024]; for (NameValuePair nameValuePair : data) { ps.print(twoHyphens + boundary + end); ps.print("Content-Disposition: form-data; name=\"" + nameValuePair.getName() + "\"" + end + end); final InputStream value = nameValuePair.getValue(); while (true) { final int rd = value.read(block, 0, block.length); if (rd < 1) { break; } ps.write(block, 0, rd); } value.close(); ps.print(end); } ps.print(twoHyphens + boundary + twoHyphens + end); ps.close(); boolean b = conn.getResponseCode() == 200; if (!b) { return new RESTResponse("HTTP " + conn.getResponseCode() + ": " + conn.getResponseMessage(), false, null); } else { InputStream inputStream = conn.getInputStream(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] arr = new byte[1024]; while (true) { int rd = inputStream.read(arr); if (rd < 1) break; baos.write(arr, 0, rd); } if (conn.getHeaderField("X-GZIPCompress") != null) { return new RESTResponse(null, false, baos.toString(0)); } else { return new RESTResponse(null, false, baos.toString()); } } finally { inputStream.close(); } } } catch (IOException e) { return new RESTResponse(e.toString(), false, null); } }
From source file:cz.lbenda.rcp.config.ConfigurationRW.java
/** Return content of configuration which name is given. The any configuration is saved as file, so the config * name is file name/*w ww .ja v a 2 s .co m*/ * @param configFile name of file * @return configuration or NULL when config file isn't openable or is empty */ public String readConfigAsString(String configFile) { try (InputStream is = readConfig(configFile)) { String result = IOUtils.toString(is); if (result == null || "".equals(result)) { return null; } return result; } catch (IOException e) { LOG.error("The config file " + configFile + " is unreadable: " + e.toString(), e); } return null; }
From source file:com.baidu.asynchttpclient.AsyncHttpRequest.java
public void run() { try {//ww w . j a v a 2 s . c om if (responseHandler != null) { responseHandler.sendStartMessage(); } makeRequestWithRetries(); } catch (IOException e) { if (responseHandler != null) { // TODO: by Guangshan Shang responseHandler.sendFailureMessage(e, e.toString()); } } if (responseHandler != null) { responseHandler.sendFinishMessage(); } }
From source file:me.schiz.jmeter.ring.udp.EventLoopRunnable.java
private void readCallback(DatagramChannel dc) throws IOException { Token t = ring.get(dc);// w ww .j ava 2 s.c o m t.lock.lock(); try { t.remote = dc.receive(byteBuffer); //EOF if (t != null) { if (t.timeout != null) t.timeout.cancel(); } byteBuffer.flip(); if (t.sampleResult != null) { t.sampleResult.sampleEnd(); byte[] res = Charset.defaultCharset().decode(byteBuffer).toString().getBytes(); if (t.ishex) { t.sampleResult.setResponseData(String.valueOf(Hex.encodeHex(res, true)).getBytes()); } else { t.sampleResult.setResponseData(res); } while (!t.queue.offer(t.sampleResult)) { } t.sampleResult = null; t.queue = null; } else { log.warn("have response without request"); } ring.release(t.id); } catch (IOException e) { t.sampleResult.setResponseCode(e.toString()); t.sampleResult.setSuccessful(false); while (!t.queue.offer(t.sampleResult)) { } } finally { t.lock.unlock(); byteBuffer.clear(); } }
From source file:com.cellobject.oikos.util.NetworkHelper.java
/** * Sends HTTP GET request and returns body of response from server as HTTPResponse object. The response object contains HTTP * headers and body. This method also writes both header and body to log. Use LogCat to view output. Also notice that in this * case the body is read line by line from a stream (in.readLine()). In most cases one of the above methods should suffice. *//* w w w . j av a2 s. co m*/ public HttpResponse httpGetWithHeader(final String urlToServer, final List<BasicNameValuePair> parameterList) throws IOException { final String url = urlToServer + "?" + URLEncodedUtils.format(parameterList, null); BufferedReader in = null; try { final HttpGet request = new HttpGet(url); final HttpResponse response = client.execute(request); /* Let's get/log the HTTP-header * */ final Header[] headers = response.getAllHeaders(); for (final Header h : headers) { Log.i("HTTPHEADER", "Header names: " + h.getName()); Log.i("HTTPHEADER", "Header Value: " + h.getValue()); } /* Read body of HTTP-message from server */ in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); final StringBuffer body = new StringBuffer(""); String line = null; while ((line = in.readLine()) != null) { body.append(line + "\n"); Log.i("HTTPBODY", line); } return response; } finally { try { in.close(); } catch (final IOException ie) { Log.e("HTTP", ie.toString()); } } }