List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:com.krawler.esp.utils.HttpPost.java
public static String GetResponse(String postdata) { try {/*from ww w . j a v a 2s. co m*/ String s = URLEncoder.encode(postdata, "UTF-8"); // URL u = new URL("http://google.com"); URL u = new URL("http://localhost:7070/service/soap/"); URLConnection uc = u.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setAllowUserInteraction(false); DataOutputStream dstream = new DataOutputStream(uc.getOutputStream()); // The POST line dstream.writeBytes(s); dstream.close(); // Read Response InputStream in = uc.getInputStream(); int x; while ((x = in.read()) != -1) { System.out.write(x); } in.close(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); StringBuffer buf = new StringBuffer(); String line; while ((line = r.readLine()) != null) { buf.append(line); } return buf.toString(); } catch (Exception e) { // throw e; return e.toString(); } }
From source file:de.nx42.maps4cim.util.Compression.java
/** * Reads the first file entry in a zip file and returns it's contents * as uncompressed byte-array//from ww w.jav a 2 s .co m * @param zipFile the zip file to read from * @return the first file entry (uncompressed) * @throws IOException if there is an error accessing the zip file */ public static byte[] readFirstZipEntry(File zipFile) throws IOException { // open zip ZipFile zf = new ZipFile(zipFile); Enumeration<ZipArchiveEntry> entries = zf.getEntries(); // read first entry to byte[] ZipArchiveEntry entry = entries.nextElement(); InputStream is = zf.getInputStream(entry); byte[] raw = ByteStreams.toByteArray(is); // close all streams and return byte[] is.close(); zf.close(); return raw; }
From source file:Main.java
public static X509Certificate base64StringToCertificate(String certificateString) throws CertificateException, IOException { if (certificateString == null) { throw new IllegalArgumentException("certificateString cannot be null"); }//from w w w. ja v a 2 s . c om byte[] encodedCert = Base64.decode(certificateString, Base64.DEFAULT); InputStream inStream = new ByteArrayInputStream(encodedCert); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); inStream.close(); return cert; }
From source file:Main.java
public static void inputToOutput(FileOutputStream outputStream, InputStream inputStream) throws IOException { byte[] buffer = new byte[1024]; int len;//from w w w. j a v a 2s . com while ((len = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } outputStream.close(); inputStream.close(); }
From source file:ua.np.printforms.JasperServerStubServInfoIT.java
private static String getStringFromInputStream(InputStream in) throws Exception { CachedOutputStream bos = new CachedOutputStream(); IOUtils.copy(in, bos);//from w ww. j a v a 2s .co m in.close(); bos.close(); return bos.getOut().toString(); }
From source file:com.digitalpebble.behemoth.languageidentification.LanguageIdProcessor.java
private static String loadLanguageProfile(String langCode) throws IOException { InputStream is = DetectorFactory.class.getClassLoader().getResourceAsStream("profiles/" + langCode); String profile = IOUtils.toString(is); is.close(); return profile; }
From source file:Main.java
public static void copy(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[1024]; int len;//from w w w. jav a 2 s . c om while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); in.close(); out.close(); }
From source file:Main.java
private static void loadAssetImage(ImageView view, String filename, int defaultIconId) { InputStream input = null; try {// w w w . ja va 2 s.c om input = view.getContext().getAssets().open(filename); Bitmap icon = BitmapFactory.decodeStream(input); view.setImageBitmap(icon); input.close(); } catch (Exception error) { view.setImageResource(defaultIconId); } finally { silentClose(input); } }
From source file:com.moz.fiji.mapreduce.TestingResources.java
/** * Loads a text resource by name.// ww w . j av a 2 s. c o m * * @param resourcePath Path of the resource to load. * @return the resource content, as a string. * @throws IOException on I/O error. */ public static String get(final String resourcePath) throws IOException { final InputStream istream = FijiTableLayouts.class.getClassLoader().getResourceAsStream(resourcePath); try { return IOUtils.toString(istream); } finally { istream.close(); } }
From source file:Utils.java
/** * Copy in stream to an out stream/*w w w.j ava2 s . com*/ * * @param in * @param out * @throws IOException */ public static void copyInputStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int len = in.read(buffer); while (len >= 0) { out.write(buffer, 0, len); len = in.read(buffer); } in.close(); out.close(); }