List of usage examples for java.io IOException toString
public String toString()
From source file:Main.java
/** * Locte the tun.ko driver on the filesystem * @return a String with the path of the tun.ko driver *//*from w ww.jav a2 s. c o m*/ public static String findTunDriverPath() { String tunDriverPath = ""; String find_str; try { Process find_proc = Runtime.getRuntime().exec("find /sdcard /system /data -name tun.ko"); DataInputStream find_in = new DataInputStream(find_proc.getInputStream()); try { while ((find_str = find_in.readLine()) != null) { tunDriverPath = find_str; } } catch (IOException e) { System.exit(0); } } catch (IOException e1) { Log.e("OpenVpnSettings_Util", e1.toString()); } // if (new File(tunDriverPath).exists()) // System.out.println(tunDriverPath); // else System.out.println("ERROR file does not exist: " + tunDriverPath); return tunDriverPath; }
From source file:Main.java
public static byte[] transform(Transformer transformer, Document useDocument) { byte[] returnData = new byte[0]; try {//w w w . j a v a 2 s .c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(useDocument.getDocumentElement()); transformer.transform(domSource, new StreamResult(baos)); returnData = baos.toByteArray(); baos.close(); } catch (TransformerException te) { String err = new String(te.toString()); returnData = err.getBytes(); te.printStackTrace(); } catch (IOException ie) { String err = new String(ie.toString()); returnData = err.getBytes(); ie.printStackTrace(); } return returnData; }
From source file:Main.java
public static String httpStringGet(String url, String enc) throws Exception { // This method for HttpConnection String page = ""; BufferedReader bufferedReader = null; try {//from w ww.j ava2 s. c om HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android"); HttpParams httpParams = client.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); HttpConnectionParams.setSoTimeout(httpParams, 5000); HttpGet request = new HttpGet(); request.setHeader("Content-Type", "text/plain; charset=utf-8"); request.setURI(new URI(url)); HttpResponse response = client.execute(request); bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), enc)); StringBuffer stringBuffer = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator");// "\n" while ((line = bufferedReader.readLine()) != null) { stringBuffer.append(line + NL); } bufferedReader.close(); page = stringBuffer.toString(); Log.i("page", page); System.out.println(page + "page"); return page; } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { Log.d("BBB", e.toString()); } } } }
From source file:com.liveramp.hank.util.CliUtils.java
public static String fileToString(String fileName) { if (fileName == null || StringUtils.isBlank(fileName)) { return ""; }/*w ww . j a v a2 s . c om*/ File file = new File(fileName); String content = ""; try { content = FsUtils.readFileToString(file); } catch (IOException e) { System.err.println(e.toString()); System.exit(1); } return content; }
From source file:Main.java
public static void saveBitmap(Bitmap b) { String path = initPath();//from w ww .j ava 2 s .c om SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss"); String dataTake = sDateFormat.format(System.currentTimeMillis()); String jpegName = path + "/" + "myImage.jpg"; try { Log.e(TAG, "save pic"); FileOutputStream fout = new FileOutputStream(jpegName); BufferedOutputStream bos = new BufferedOutputStream(fout); b.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.toString()); } Log.e("camera", "pic saved jpegName: " + jpegName); }
From source file:dfki.sb.rabbitmqjava.RabbitMQObjectStreamServer.java
private static void processSendAndRecivePackets(QueueingConsumer consumer, Channel channel) throws InterruptedException, IOException { while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); BasicProperties props = delivery.getProperties(); BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()) .build();//from ww w . ja v a 2 s.c om try { byte[] body = delivery.getBody(); if (body.length == 0) { break; } else { Object obj = SerializationUtils.deserialize(body); if (obj instanceof MarketData) { MarketData response = sendMarketData((MarketData) obj); channel.basicPublish("", props.getReplyTo(), replyProps, SerializationUtils.serialize(response)); } else { QuoteRequest response = sendQuoteRequest((QuoteRequest) obj); channel.basicPublish("", props.getReplyTo(), replyProps, SerializationUtils.serialize(response)); } } } catch (IOException e) { System.out.println(" [.] " + e.toString()); } finally { channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } } }
From source file:Main.java
public static byte[] base64_decode(String s) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {//from www .j av a2s.c o m decode(s, bos); } catch (IOException e) { throw new RuntimeException(); } byte[] decodedBytes = bos.toByteArray(); try { bos.close(); bos = null; } catch (IOException ex) { System.err.println("Error while decoding BASE64: " + ex.toString()); } return decodedBytes; }
From source file:org.elegosproject.romupdater.DownloadManager.java
public static boolean checkHttpFile(String url) { try {//from w ww .j a v a 2 s . c o m HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); Log.i(TAG, "Testing " + url + "..."); URL theUrl = new URL(url); HttpURLConnection connection = (HttpURLConnection) theUrl.openConnection(); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { connection.disconnect(); } else { Log.i(TAG, "HTTP Response code: " + connection.getResponseCode()); return false; } } catch (IOException e) { Log.e(TAG, e.toString()); return false; } return true; }
From source file:Main.java
public static byte[] decode(String s) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {// w ww . j a va 2s . co m decode(s, bos); } catch (IOException e) { throw new RuntimeException(); } byte[] decodedBytes = bos.toByteArray(); try { bos.close(); bos = null; } catch (IOException ex) { System.err.println("Error while decoding BASE64: " + ex.toString()); } return decodedBytes; }
From source file:net.a2bsoft.buss.http.SendQuery.java
public static String sendQueryBusstuc(String query) { String ans = "No answer"; try {//from w w w . ja v a2 s . com List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("lang", "nor")); nameValuePairs.add(new BasicNameValuePair("quest", query)); Document doc = Jsoup.connect("http://www.idi.ntnu.no:80/~tagore/cgi-bin/busstuc/busq.cgi") .data("lang", "nor").data("quest", query).timeout(30000) .header("Content-type", "application/x-www-form-urlencoded").header("Accept", "text/plain") .post(); ans = doc.body().text(); } catch (IOException e) { ans = e.toString(); e.printStackTrace(); } return ans; }