List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:Main.java
public static String runCommand(String[] commands) { DataOutputStream outStream = null; DataInputStream responseStream; try {/*from w w w .j av a2 s . c om*/ ArrayList<String> logs = new ArrayList<String>(); Process process = Runtime.getRuntime().exec("su"); Log.i(TAG, "Executed su"); outStream = new DataOutputStream(process.getOutputStream()); responseStream = new DataInputStream(process.getInputStream()); for (String single : commands) { Log.i(TAG, "Command = " + single); outStream.writeBytes(single + "\n"); outStream.flush(); if (responseStream.available() > 0) { Log.i(TAG, "Reading response"); logs.add(responseStream.readLine()); Log.i(TAG, "Read response"); } else { Log.i(TAG, "No response available"); } } outStream.writeBytes("exit\n"); outStream.flush(); String log = ""; for (int i = 0; i < logs.size(); i++) { log += logs.get(i) + "\n"; } Log.i(TAG, "Execution compeleted"); return log; } catch (IOException e) { Log.d(TAG, e.getMessage()); } return null; }
From source file:net.orfjackal.dimdwarf.testutils.Sandbox.java
private static void retryingForceDelete(File dir) throws IOException { long limit = System.currentTimeMillis() + 1000; IOException unableToDelete;/*from w w w.j a v a 2 s. co m*/ do { try { FileUtils.forceDelete(dir); return; } catch (IOException e) { System.err.println("WARNING: " + e.getMessage() + " Retrying..."); unableToDelete = e; } sleep(10); } while (System.currentTimeMillis() < limit); throw unableToDelete; }
From source file:com.firewallid.util.FIConnection.java
public static String getText(String url, int timeoutSeconds) { String text = ""; long startTime = System.currentTimeMillis(); while (true) { try {//from w w w .j a v a 2 s . co m text = Jsoup.connect(url).userAgent("Mozilla").get().text(); LOG.info(String.format("Downloaded. Url: %s", url)); break; } catch (IOException ex) { LOG.error(String.format("Url: %s. %s", url, ex.getMessage())); long runningTime = System.currentTimeMillis() - startTime; if (runningTime / 1000 >= timeoutSeconds) { LOG.error(String.format("Url: %s. Timeout reached", url)); break; } } } return text; }
From source file:demo.jaxrs.util.Marshal.java
public static <T> T unmarshal(Class<T> xmlType, HttpResponse httpResponse) throws JAXBException { String namespace = ""; try {/*from www . jav a2 s. co m*/ namespace = Util.getStringFromInputStream(httpResponse.getEntity().getContent()); System.out.println(namespace); } catch (IOException e) { System.out.println(e.getMessage()); } System.out.println(namespace); namespace = namespace.replaceAll("xmlns=\"http://ws.wso2.org/dataservice\"", ""); System.out.println(namespace); InputStream stream = Util.getInputStreamFromString(namespace); JAXBContext jaxbContext = JAXBContext.newInstance(xmlType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); T doc = (T) unmarshaller.unmarshal(stream); return doc; }
From source file:br.org.ipti.guigoh.util.DownloadService.java
public static synchronized void downloadFile(File file, String mimeType) { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext context = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) context.getResponse(); response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\""); response.setContentLength((int) file.length()); response.setContentType(mimeType);//from w w w . ja va 2s. c o m try { OutputStream out; try (FileInputStream in = new FileInputStream(file)) { out = response.getOutputStream(); byte[] buf = new byte[(int) file.length()]; int count; while ((count = in.read(buf)) >= 0) { out.write(buf, 0, count); } } out.flush(); out.close(); facesContext.responseComplete(); } catch (IOException ex) { System.out.println("Error in downloadFile: " + ex.getMessage()); } }
From source file:com.excilys.ebi.gatling.recorder.configuration.ConfigurationHelper.java
public static void saveToDisk() { FileWriter fw = null;// w w w .j ava2s. c om try { fw = new FileWriter(CONFIGURATION_FILE); XSTREAM.toXML(Configuration.getInstance(), fw); } catch (IOException e) { logger.error(e.getMessage()); } finally { closeQuietly(fw); } }
From source file:com.github.tomakehurst.wiremock.common.Json.java
public static <T> String write(T object) { try {//from w w w.ja va2s.c o m ObjectMapper mapper = new ObjectMapper(); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); } catch (IOException ioe) { throw new RuntimeException("Unable to generate JSON from object. Reason: " + ioe.getMessage(), ioe); } }
From source file:demo.jaxrs.util.Marshal.java
public static <T> T unmarshal(Class<T> xmlType, InputStream inputStream) throws JAXBException { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder out = new StringBuilder(); try {//from w w w . j a v a 2 s.co m String line; while ((line = reader.readLine()) != null) { out.append(line); } } catch (IOException e) { System.out.println(e.getMessage()); } String namespace = out.toString(); System.out.println(namespace); namespace = namespace.replaceAll("xmlns=\"http://ws.wso2.org/dataservice\"", ""); System.out.println(namespace); InputStream stream = Util.getInputStreamFromString(namespace); JAXBContext jaxbContext = JAXBContext.newInstance(xmlType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); T doc = (T) unmarshaller.unmarshal(stream); return doc; }
From source file:Main.java
public static ByteArrayOutputStream loadFile(File root) { String inputString;/*from ww w .ja va2 s . co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { for (File child : root.listFiles()) { if (root.isDirectory()) { if (child.exists()) { FileInputStream fis; fis = globalContext.openFileInput(child.getName().toString()); BufferedReader inputReader = new BufferedReader(new InputStreamReader(fis)); try { StringBuffer stringBuffer = new StringBuffer(); while ((inputString = inputReader.readLine()) != null) { stringBuffer.append(inputString); baos.write(inputString.getBytes()); } baos.flush(); connectAndSendHttp(baos); } catch (IOException e) { Log.e("tag", e.getMessage()); } } } } } catch (FileNotFoundException e1) { e1.printStackTrace(); } return baos; }
From source file:be.vlaanderen.sesam.monitor.internal.util.BodyUtils.java
/** * Inputstream is not closed.// www . ja v a 2 s .c o m * * @param f * @return */ public static String getMd5Sum(InputStream is) { try { String res = DigestUtils.md5Hex(is); log.debug("Hashed a stream: {}", res); return res; } catch (IOException e) { log.warn("Failed calculating MD5sum. " + e.getMessage()); return null; } }