List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
public static void close(InputStream stream) { if (stream != null) { try {// www.ja v a2 s . com stream.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
/** * check asset exists//ww w . j a v a 2 s . c om * * @param context * @param assetFilePath * @return */ public static boolean exists(final Context context, final String assetFilePath) { boolean bAssetOk = false; try { InputStream stream = context.getAssets().open(assetFilePath); stream.close(); bAssetOk = true; } catch (Exception e) { } return bAssetOk; }
From source file:Main.java
/** * Close a InputStream passed in.//from w w w .j av a 2 s . co m * * @param stream - InputStream to be closed. */ public static void closeInputStream(InputStream stream, String tag) { if (stream != null) { try { stream.close(); } catch (IOException e) { Log.e(tag, "Exception occured when closing InputStream." + e); } } }
From source file:Main.java
static void close(InputStream inputStream) { if (inputStream != null) { try {/*w w w . j a v a 2 s. c om*/ inputStream.close(); } catch (IOException e) { // Do nothing } } }
From source file:Main.java
/** * close inputStream/*from ww w . j a va 2 s .c o m*/ * * @param s */ private static void closeInputStream(InputStream s) { if (s == null) { return; } try { s.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } }
From source file:Main.java
public static Bitmap getImageFromAssetsFile(Context context, String fileName) { Bitmap image = null;//from w ww . ja va 2s .co m AssetManager am = context.getResources().getAssets(); try { InputStream is = am.open(fileName); image = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return image; }
From source file:Main.java
/** * //www. j a va 2s . com * @param data */ private static String readFromFile(String filename) { File file = new File(filename); byte b[] = null; try { if (file.exists()) { b = new byte[(int) file.length()]; InputStream fi = new FileInputStream(file); fi.read(b); fi.close(); } } catch (Exception e) { return null; } if (null != b) { return new String(b); } return null; }
From source file:Main.java
public static String fromFile(File f) throws IOException { InputStream is = new FileInputStream(f); byte[] bs = new byte[is.available()]; is.read(bs);//from w w w. ja v a2 s . c o m is.close(); return new String(bs); }
From source file:Main.java
public static boolean backupExist(String File) throws IOException { try {/*from w w w. ja v a2 s.co m*/ InputStream in = new FileInputStream(File); if (in != null) { in.close(); } } catch (IOException ex) { return false; } return true; }
From source file:Main.java
public static Bitmap getbmFromAssetsFile(Resources res, String fileName) { if (res == null) return null; Bitmap bm = null;/*from w w w .j ava 2 s.c o m*/ AssetManager am = res.getAssets(); try { InputStream is = am.open(fileName); bm = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bm; }