List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:Main.java
public static void saveBitmapToFile(Bitmap bitmap, String _file) throws IOException { BufferedOutputStream os = null; try {//from w w w . j av a 2s . c o m File file = new File(_file); // String _filePath_file.replace(File.separatorChar + // file.getName(), ""); int end = _file.lastIndexOf(File.separator); String _filePath = _file.substring(0, end); File filePath = new File(_filePath); if (!filePath.exists()) { filePath.mkdirs(); } file.createNewFile(); os = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.e("TAG_ERROR", e.getMessage(), e); } } } }
From source file:Main.java
public static String readInStream(InputStream inStream) { try {/*from w w w .ja v a 2 s. c o m*/ ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[512]; int length = -1; while ((length = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, length); } outStream.close(); inStream.close(); return outStream.toString(); } catch (IOException e) { Log.i("FileTest", e.getMessage()); } return null; }
From source file:com.sg2net.utilities.ListaCAP.json.JsonUtilties.java
public static void serializeTo(Collection<Comune> comuni, File file) { try {//from w ww. ja va2s .co m JSONMapper.writeValue(file, comuni); } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
From source file:fm.audiobox.core.utils.MD5Checksum.java
/** * Calculate checksum of a File using MD5 algorithm *//*w w w. j a v a 2 s. c o m*/ public static String checkSum(InputStream is) throws NoSuchAlgorithmException { String checksum = null; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.reset(); // Using MessageDigest update() method to provide input byte[] buffer = new byte[8192]; int numOfBytesRead; while ((numOfBytesRead = is.read(buffer)) > 0) { md.update(buffer, 0, numOfBytesRead); } byte[] hash = md.digest(); checksum = new String(Hex.encodeHex(hash)); } catch (IOException ex) { logger.error(ex.getMessage()); } return checksum; }
From source file:Main.java
/** * Convert a bitmap to a byte array//from w ww .j a v a 2 s .co m * @param path the path to the picture on the phone * @return the image in a byte array */ public static byte[] picToByte(Bitmap bitmap) { if (bitmap == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 10, baos); byte[] ba = baos.toByteArray(); try { baos.close(); } catch (IOException e) { Log.e("Error", "Error closing output stream" + e.getMessage()); return null; } return ba; }
From source file:Main.java
/** * /*w w w .j av a 2 s .co m*/ * @param aFile * @return */ public static String getLastLines(String filename, int number) { File aFile = new File(filename); StringBuilder contents = new StringBuilder(); LinkedList<String> ll = new LinkedList<String>(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while ((line = input.readLine()) != null) { ll.add(line); } } finally { input.close(); } } catch (IOException ex) { Log.e(TAG, ex.getMessage()); } if ((ll.size() - number) <= 0) { Log.e(TAG, "Requested number of lines exceeds lines of file"); return "Requested number of lines exceeds lines of file"; } for (int i = (ll.size() - 1); i >= (ll.size() - number); i--) { contents.append(ll.get(i - 1)); contents.append("\n"); } return contents.toString(); }
From source file:Main.java
static String downloadUrl(String myurl) throws IOException { InputStream is = null;/*from ww w . j av a 2s. com*/ try { URL url = new URL(myurl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Basic cm9vdDpvcmllbnRkYg=="); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("GET"); conn.setDoInput(true); //start conn.connect(); int response = conn.getResponseCode(); Log.e("The response is: ", "" + response); is = conn.getInputStream(); //converte inputStream in stringa String contentAsString = readIt(is); return contentAsString; } catch (IOException e) { Log.e("HTTP", e.getMessage()); return null; } finally { if (is != null) { is.close(); } } }
From source file:es.deustotech.piramide.utils.net.RestClient.java
public static HttpEntity connect(String url, HttpEntity httpEntity) { final DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.content-charset", "UTF-8"); httpClient.setParams(params);//from w w w . j ava2 s .com final HttpGet httpGet = new HttpGet(url); //request object HttpResponse response = null; try { response = httpClient.execute(httpGet); } catch (ClientProtocolException cpe) { Log.d(Constants.TAG, cpe.getMessage()); } catch (IOException ioe) { Log.d(Constants.TAG, ioe.getMessage()); } return httpEntity = response.getEntity(); }
From source file:de.javagl.jgltf.model.io.JsonUtils.java
/** * Creates a formatted (pretty-printed, indented) representation of * the given JSON string. The details of the formatting are not * specified. If there is any error during this process, then a * warning will be printed and the given string will be returned. * //from w ww. ja v a 2 s. c o m * @param jsonString The input JSON string * @return The formatted JSON string */ public static String format(String jsonString) { ObjectMapper mapper = new ObjectMapper(); try { Object object = mapper.readValue(jsonString, Object.class); String formattedJsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); return formattedJsonString; } catch (IOException e) { logger.warning(e.getMessage()); return jsonString; } }
From source file:com.santiagolizardo.madcommander.util.io.FileOperations.java
public static boolean copy(InputStream is, File file) { try {/*from w w w . j a v a2s . c om*/ try (FileOutputStream fos = new FileOutputStream(file)) { IOUtils.copy(is, fos); is.close(); } return true; } catch (IOException e) { logger.warning(e.getMessage()); return false; } }