List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
/** * @param url/*from w ww . ja v a2 s. c o m*/ * @param sampleSize * @return * @throws FileNotFoundException * @throws IOException */ public static Bitmap downsampleBitmap(URL url, int sampleSize) throws FileNotFoundException, IOException { Bitmap resizedBitmap; BitmapFactory.Options outBitmap = new BitmapFactory.Options(); outBitmap.inJustDecodeBounds = false; // the decoder will return a bitmap outBitmap.inSampleSize = sampleSize; InputStream is = url.openStream(); resizedBitmap = BitmapFactory.decodeStream(is, null, outBitmap); is.close(); return resizedBitmap; }
From source file:Main.java
public static void close(InputStream closeable) { if (closeable != null) try {/*from ww w .jav a 2s . c o m*/ closeable.close(); } catch (Exception ignored) { } }
From source file:Main.java
public static void fileCopy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); try {//w w w .j a va 2s .c o m saveToFile(in, dst); } finally { in.close(); } }
From source file:Main.java
public static final void close(final InputStream in) { if (in != null) { try {//from w ww .j a v a2 s .c o m in.close(); } catch (IOException e) { // silent } } }
From source file:Main.java
public static String AssetJSONFile(String filename, AssetManager manager) throws IOException { String json = null;//from w ww . ja v a2s .c o m InputStream is = manager.open(filename); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new String(buffer, "UTF-8"); return json; }
From source file:Main.java
public static Properties loadPropertyInstance(String filePath, String fileName) { try {/*from w w w .j a va 2 s. c o m*/ File d = new File(filePath); if (!d.exists()) { d.mkdirs(); } File f = new File(d, fileName); if (!f.exists()) { f.createNewFile(); } Properties p = new Properties(); InputStream is = new FileInputStream(f); p.load(is); is.close(); return p; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String readData(Context mContext, String key, int resId) { Properties props = new Properties(); try {//from w w w . j a v a 2 s . c o m InputStream in = new BufferedInputStream(mContext.getResources().openRawResource(resId)); props.load(in); in.close(); String value = props.getProperty(key); return value; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String readAssertsFile(Context context, String name) { try {//w w w .j a v a 2 s . co m AssetManager assetManager = context.getResources().getAssets(); InputStream inputStream = assetManager.open(name); String result = readInputStream(inputStream); inputStream.close(); return result; } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static Document openUrl(String location) throws Exception { URL url = new URL(location); //System.out.println(url); URLConnection con = url.openConnection(); InputStream responseStream = con.getInputStream(); Document result = loadFromStream(responseStream); responseStream.close(); return result; }
From source file:Main.java
public static byte[] readFileFromAsset(String fileName) throws IOException { AssetManager assetMgr = context.getAssets(); InputStream is = assetMgr.open(fileName); int size = is.available(); byte[] content = new byte[size]; is.read(content);/* w w w. j av a 2s .c o m*/ is.close(); return content; }