List of usage examples for java.io InputStream read
public int read(byte b[]) throws IOException
b
. From source file:Main.java
public static String loadJSONFromAsset(Context context, String jsonFileName) throws IOException { AssetManager manager = context.getAssets(); InputStream is = manager.open(jsonFileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close();/*from www . j a v a 2 s. co m*/ return new String(buffer, "UTF-8"); }
From source file:Main.java
private static void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[12024]; int read;//from w w w.j a va 2s . co m while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }
From source file:Main.java
private static void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read;//from w w w . ja v a2 s . c om while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }
From source file:Main.java
public static String toString(InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] buffer = new byte[1024]; for (int i; (i = in.read(buffer)) != -1;) { out.append(new String(buffer, 0, i)); }/* w w w. ja v a2s.c o m*/ return out.toString(); }
From source file:Main.java
public static long getFileLen(File file) { long total = 0; try {/* w w w . java 2s . com*/ InputStream is = new FileInputStream(file); byte[] bytes = new byte[1024]; int len = 0; while ((len = is.read(bytes)) != -1) { total += len; } is.close(); } catch (Exception e) { } return total; }
From source file:Main.java
public static void copyFileStream(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[BUFFSIZE]; int n = 0;/*from w w w.j av a 2s . co m*/ while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } input.close(); output.close(); }
From source file:Main.java
public static void copy(InputStream inputstream, OutputStream outputstream) throws IOException { byte abyte0[] = new byte[50000]; do {//ww w. j a v a 2 s . co m int i = inputstream.read(abyte0); if (i > 0) { outputstream.write(abyte0, 0, i); } else { outputstream.close(); return; } } while (true); }
From source file:Main.java
public static JSONObject loadJsonFile(Context context, String fileName) throws IOException, JSONException { InputStream is = context.getAssets().open(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close();//www.jav a 2s .co m String jsonString = new String(buffer); return new JSONObject(jsonString); }
From source file:Main.java
public static String inputStream2String(InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); }/*from ww w .j a va2 s . c o m*/ return out.toString(); }
From source file:Main.java
/** * Slurps a InputStream into a String.//from w w w. j av a 2s . co m * @param in * @throws IOException */ public static String inputStreamToString(final InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); }