List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
public static void closeInputStream(InputStream in) { if (in != null) { try {/* w w w . j a v a 2s . c om*/ in.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static byte[] readBytes(InputStream is) throws IOException { byte[] buffer; buffer = new byte[is.available()]; is.read(buffer);//from w w w . j a va 2 s. c o m is.close(); return buffer; }
From source file:Main.java
public static String readFile(Context context, String name) throws IOException { File file = context.getFileStreamPath(name); InputStream is = new FileInputStream(file); byte b[] = new byte[(int) file.length()]; is.read(b);// w w w .jav a 2s . c om is.close(); String string = new String(b); return string; }
From source file:Main.java
public static Bitmap returnBitmap(String url) { URL fileUrl = null;//from ww w. jav a2s. co m Bitmap bitmap = null; try { fileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) fileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:org.eclipse.lyo.testsuite.server.trsutils.HttpResponseUtil.java
/** * Marks an HTTP response as final and disposes of any system resources * referenced by the response./*w w w .j ava 2s . c o m*/ * <p> * Clients should aggressively call this method as soon as they no longer need the response to * reduce contention over possibly scarce system resources. * </p> * <p> * Clients should <strong>not</strong> attempt to access the HTTP response after calling this * method. * </p> * @param response the HTTP response to finalize */ public static void finalize(final HttpResponse response) { if (response == null) return; HttpEntity entity = response.getEntity(); try { if (entity != null) { InputStream is = entity.getContent(); if (is != null) { is.close(); } } } catch (IOException e) { /* ignored */ } }
From source file:Main.java
public static String readAsset(AssetManager assets, String path) throws IOException { InputStream is = assets.open(path); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer);//from ww w .j a v a 2s .com is.close(); return new String(buffer); }
From source file:Main.java
public static Document createDocument(InputStream is) throws SAXException, IOException { try {//from w ww . j a va 2 s . c om return docBuilder.parse(is); } finally { is.close(); } }
From source file:Main.java
public static Document openFile(File file) throws Exception { InputStream inputStream = new FileInputStream(file); Document result = loadFromStream(inputStream); inputStream.close(); return result; }
From source file:Main.java
public static void copyAssetFileToFiles(Context context, String root, String filename) throws IOException { InputStream is = context.getAssets().open(filename); byte[] buffer = new byte[is.available()]; is.read(buffer);//www . j a v a2 s . c o m is.close(); File tgtfile = new File(root + "/" + filename); tgtfile.createNewFile(); tgtfile.setExecutable(true); FileOutputStream os = new FileOutputStream(tgtfile); os.write(buffer); os.close(); }
From source file:Main.java
public static void closeQuietly(InputStream inputStream) { if (inputStream != null) { try {/*from w ww . java 2 s . c om*/ inputStream.close(); } catch (IOException e) { e.printStackTrace(); } finally { inputStream = null; } } }