List of usage examples for java.io InputStream read
public int read(byte b[]) throws IOException
b
. From source file:Main.java
private static void copyFileUsingStream(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[1024]; int read;//from ww w . ja v a2s.c o m while ((read = in.read(buf)) != -1) { out.write(buf, 0, read); } }
From source file:Main.java
private static void readFromAndWriteTo(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[EIGHT_KILO]; int bytesRead = in.read(buf); while (bytesRead >= 0) { out.write(buf, 0, bytesRead);//from ww w .jav a2s . c o m bytesRead = in.read(buf); } }
From source file:Main.java
private static void copy(InputStream in, OutputStream out) throws IOException { byte[] b = new byte[1024]; int read;// w ww .j a va 2 s .c om while ((read = in.read(b)) != -1) { out.write(b, 0, read); } }
From source file:Main.java
static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException { long count = 0; int n;//from w w w . ja va2 s . com while (EOF != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; }
From source file:Main.java
public static String slurp(InputStream in) throws IOException { StringBuilder sb = new StringBuilder(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { sb.append(new String(b, 0, n)); }//from ww w . j a v a 2 s .co m return sb.toString(); }
From source file:Main.java
public static String extractAssetToString(Context context, String file) { String json;/*from w w w. ja v a 2s . c om*/ try { InputStream is = context.getAssets().open(file); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new String(buffer, "UTF-8"); } catch (IOException ex) { ex.printStackTrace(); return null; } return json; }
From source file:Main.java
public static void writeExtractedFileToDisk(InputStream in, OutputStream outs) throws IOException { byte[] buffer = new byte[1024]; int length;/* w w w. ja v a2s .c o m*/ while ((length = in.read(buffer)) > 0) { outs.write(buffer, 0, length); } outs.flush(); outs.close(); in.close(); }
From source file:co.edu.unal.arqdsoft.presentacion.JSON.java
/** * * @param is/*from ww w. ja v a 2s. c om*/ * @return */ public static String getTemplate(InputStream is) { try { byte[] charr = new byte[is.available()]; is.read(charr); String text = new String(charr, "UTF-8"); text = text.replace("\n", "").replace("\r", "").replace(" ", "").replace("\"", "'"); return text; } catch (IOException ex) { Logger.getLogger(JSON.class.getName()).log(Level.SEVERE, null, ex); return ""; } }
From source file:in.co.sneh.model.CargaExcelRuralModel.java
public static boolean processFile(String path, FileItemStream item) { try {// w w w .j ava 2 s. c o m File f = new File(path + File.separator + "exceles" + File.separator); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception e) { System.out.println(e.getMessage()); } return false; }
From source file:Main.java
public static String readAssetsFileString(Context context, String fileName) { String str = null;// w ww. j a v a2 s . co m try { InputStream is = context.getAssets().open(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); str = new String(buffer); } catch (IOException e) { e.printStackTrace(); } return str; }