List of usage examples for java.io InputStream read
public int read(byte b[]) throws IOException
b
. From source file:Main.java
public static byte[] load(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len;//from www . j av a2s. c om while ((len = is.read(buffer)) != -1) baos.write(buffer, 0, len); baos.close(); is.close(); return baos.toByteArray(); }
From source file:Main.java
public static int getHistory(String extractPath, String md5) { StringBuilder reval = new StringBuilder(); try {/* w ww .j a v a2s. com*/ InputStream in = new FileInputStream(extractPath + "/history_" + md5); byte[] buf = new byte[1024]; int c = 0; while ((c = in.read(buf)) >= 0) { reval.append(new String(buf, 0, c)); } in.close(); } catch (IOException e) { e.printStackTrace(); return 1; } try { return Integer.parseInt(reval.toString()); } catch (Exception e) { return 0; } }
From source file:Main.java
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException { byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); }//w ww . ja va 2 s .c o m }
From source file:Main.java
private static String toString(InputStream is) throws IOException { byte[] bytes = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); int lidos;//from w ww . j a va2s . c om while ((lidos = is.read(bytes)) > 0) { baos.write(bytes, 0, lidos); } return new String(baos.toByteArray()); }
From source file:Main.java
public static void copy(InputStream input, OutputStream output, int bufferSize) throws IOException { final byte[] buffer = new byte[bufferSize]; int n;//from www.ja va 2 s. c o m while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } }
From source file:Main.java
public static ArrayList<String> getListSite(String extractPath, String md5) { ArrayList<String> listSite = new ArrayList<>(); StringBuilder reval = new StringBuilder(); try {//from www. j a va 2 s . c o m InputStream in = new FileInputStream(extractPath + "/site_map_" + md5); byte[] buf = new byte[1024]; int c = 0; while ((c = in.read(buf)) >= 0) { reval.append(new String(buf, 0, c)); } in.close(); } catch (IOException e) { e.printStackTrace(); return null; } String[] arrSite = reval.toString().split(";"); Collections.addAll(listSite, arrSite); return listSite; }
From source file:Main.java
public static String readAsset(Context c, String fileName) { try {//from w w w . j a va 2s . c om InputStream is = c.getAssets().open(fileName); byte[] buffer = new byte[is.available()]; //noinspection ResultOfMethodCallIgnored is.read(buffer); // buffer is exactly the right size, a guarantee of asset files return new String(buffer); } catch (IOException ignore) { } return null; }
From source file:Main.java
public static byte[] readInput(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int len = 0;/* w ww. j a va2 s . com*/ byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } out.close(); in.close(); return out.toByteArray(); }
From source file:Main.java
public static void copyFile(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len;//from ww w. jav a2 s .com while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
static private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read;//from w w w. j a v a 2 s . c o m // Copy from input stream to output stream while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }