List of usage examples for java.io InputStream close
public void close() throws IOException
From source file:Main.java
public static String inputStreamToString(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;// w w w . j a v a 2s. c o m while ((line = reader.readLine()) != null) { sb.append(line); } is.close(); return sb.toString(); }
From source file:Main.java
/** * Returns the local store of reliable server certificates, explicitly accepted by the user. * /* w w w. j ava2 s . c o m*/ * Returns a KeyStore instance with empty content if the local store was never created. * * Loads the store from the storage environment if needed. * * @param context Android context where the operation is being performed. * @return KeyStore instance with explicitly-accepted server certificates. * @throws KeyStoreException When the KeyStore instance could not be created. * @throws IOException When an existing local trust store could not be loaded. * @throws NoSuchAlgorithmException When the existing local trust store was saved with an unsupported algorithm. * @throws CertificateException When an exception occurred while loading the certificates from the local trust store. */ private static KeyStore getKnownServersStore(Context context) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { if (mKnownServersStore == null) { //mKnownServersStore = KeyStore.getInstance("BKS"); mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType()); File localTrustStoreFile = new File(context.getFilesDir(), LOCAL_TRUSTSTORE_FILENAME); Log.d(TAG, "Searching known-servers store at " + localTrustStoreFile.getAbsolutePath()); if (localTrustStoreFile.exists()) { InputStream in = new FileInputStream(localTrustStoreFile); try { mKnownServersStore.load(in, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); } finally { in.close(); } } else { mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance } } return mKnownServersStore; }
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.JarUtils.java
private static void closeStream(InputStream stream) { if (stream != null) try {//www. j a v a2 s .co m stream.close(); } catch (IOException ex) { // ignore } }
From source file:Main.java
public static String convertStreamToString(InputStream is) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;//from w ww . j ava 2s. c o m while ((line = reader.readLine()) != null) { sb.append(line); } is.close(); return sb.toString(); }
From source file:Main.java
public static boolean upZipFile(File zipFile, String folderPath) throws ZipException, IOException { ZipFile zfile = new ZipFile(zipFile); Enumeration<? extends ZipEntry> zList = zfile.entries(); ZipEntry ze = null;/*from w w w. j ava 2 s . c o m*/ byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { continue; } Log.d(TAG, "ze.getName() = " + ze.getName()); OutputStream os = new BufferedOutputStream( new FileOutputStream(getRealFileName(folderPath, ze.getName()))); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf, 0, 1024)) != -1) { os.write(buf, 0, readLen); } is.close(); os.close(); } zfile.close(); return true; }
From source file:Main.java
@Deprecated private static String read(InputStream in) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000); for (String line = r.readLine(); line != null; line = r.readLine()) { sb.append(line);//from ww w. jav a 2 s . co m } in.close(); return sb.toString(); }
From source file:Main.java
public static void copy(InputStream src, File dst) throws IOException { OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;/* www .j ava2s. c o m*/ while ((len = src.read(buf)) > 0) { out.write(buf, 0, len); } src.close(); out.close(); }
From source file:MD5.java
public static String getRecoveryMD5() { String MD5string = ""; String recoveryFilename = "/dev/mtd/mtd1"; try {/* w w w .j a v a 2s .com*/ Process p = Runtime.getRuntime().exec("su"); OutputStream os = p.getOutputStream(); os.write(("md5sum " + recoveryFilename).getBytes()); os.flush(); os.close(); InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String str = br.readLine(); MD5string = str.split(" ")[0].trim(); is.close(); br.close(); p.destroy(); } catch (Exception e) { System.out.println(e); return null; } System.out.println(MD5string); return MD5string; }
From source file:Main.java
public static void fileCopy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;// w w w . j a v a 2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:com.phoenixnap.oss.ramlapisync.generation.CodeModelHelper.java
public static String getVersion() { try {//from w ww.java 2 s . co m Properties prop = new Properties(); InputStream in = Thread.currentThread().getContextClassLoader() .getResourceAsStream("parser.properties"); prop.load(in); in.close(); return prop.getProperty("parser.version"); } catch (IOException e) { return "???"; } }