List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:mx.bigdata.cfdi.security.KeyLoader.java
private static byte[] getBytes(InputStream in, char[] passwd) throws Exception { try {// ww w.j a va2 s. co m PKCS8Key pkcs8 = new PKCS8Key(in, passwd); return pkcs8.getDecryptedBytes(); } finally { in.close(); } }
From source file:Main.java
/** * @param url//w ww . j a va2 s. com * @return */ public static Bitmap getBitMapFromURL(URL url) { Bitmap mBitmap = null; try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); conn.getContentLength(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); mBitmap = BitmapFactory.decodeStream(bis); bis.close(); is.close(); } catch (Exception e) { Log.e("Exception in MapScrollActivity.getBitmapFromURL", "" + e.getMessage()); e.printStackTrace(); } return mBitmap; }
From source file:com.music.tools.SongDBDownloader.java
private static String getResponseAsString(String urlString, HttpClient client, HttpContext ctx) throws IOException { HttpUriRequest req = new HttpGet(urlString); InputStream is = client.execute(req, ctx).getEntity().getContent(); String result = CharStreams.toString(new InputStreamReader(is)); is.close(); req.abort();/* w w w .ja v a 2 s . co m*/ return result; }
From source file:com.cyberway.issue.httpclient.SingleHttpConnectionManager.java
static void finishLast(HttpConnection conn) { // copied from superclass because it wasn't made available to subclasses InputStream lastResponse = conn.getLastResponseInputStream(); if (lastResponse != null) { conn.setLastResponseInputStream(null); try {/*w ww.ja v a2s . c o m*/ lastResponse.close(); } catch (IOException ioe) { //FIXME: badness - close to force reconnect. conn.close(); } } }
From source file:com.googlecode.fascinator.common.MimeTypeUtil.java
/** * Gets the MIME type for the specified input stream * /*w ww . j av a 2 s . com*/ * @param in an input stream * @return MIME type */ public static String getMimeType(InputStream in) { try { byte[] inBytes = IOUtil.readBytes(in, identifier.getMinArrayLength()); in.close(); return identifier.identify(inBytes, null, null); } catch (IOException ioe) { log.warn("Failed to detect MIME type (InputStream): {}", toPrintable(ioe)); } return DEFAULT_MIME_TYPE; }
From source file:Main.java
public static Node getNode(String text) throws Exception { Node ret = null;/*from w ww . j a va 2s. c o m*/ // Transform the text representation to DOM DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); fact.setNamespaceAware(true); java.io.InputStream xmlstr = new java.io.ByteArrayInputStream(text.getBytes()); DocumentBuilder builder = fact.newDocumentBuilder(); org.w3c.dom.Document doc = builder.parse(xmlstr); xmlstr.close(); ret = doc.getDocumentElement(); return (ret); }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsTestUtil.java
public static byte[] getBytes(InputStream inputStream) throws IOException { byte[] fileBytes = null; try {/* ww w . j a va 2s . c om*/ fileBytes = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } return fileBytes; }
From source file:com.splout.db.common.CompressorUtil.java
public static void uncompress(File file, File dest) throws IOException { ZipFile zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(dest, entry.getName()); entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out);/*from w ww. java 2 s . c o m*/ in.close(); out.close(); } }
From source file:Main.java
/** Loads properties into a file. * <P>This assumes the file was written with the * <code>Properties.store()</code> method. *//*from w w w . j av a 2 s . c o m*/ public static void load(Properties p, URL url) throws IOException { InputStream in = null; try { in = url.openStream(); p.load(in); } finally { if (in != null) { try { in.close(); } catch (Throwable t) { } } } }
From source file:Main.java
public static Bitmap loadBitmap(Context mContext, int id) { final InputStream is = mContext.getResources().openRawResource(id); Bitmap bitmap = null;/*from w ww . j a va 2 s . c o m*/ try { bitmap = BitmapFactory.decodeStream(is); } finally { try { is.close(); } catch (final IOException e) { // Ignore. } } return bitmap; }