List of usage examples for java.io InputStream read
public int read(byte b[]) throws IOException
b
. From source file:Main.java
@Deprecated private static void copy(InputStream in, File dst) throws IOException { FileOutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len;/*from ww w. j av a 2s. co m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static byte[] toByte(InputStream input) throws IOException { byte[] buf = new byte[1024]; int len = -1; ByteArrayOutputStream output = new ByteArrayOutputStream(); while ((len = input.read(buf)) != -1) { output.write(buf, 0, len);/* w w w. j av a 2s .c o m*/ } byte[] data = output.toByteArray(); output.close(); input.close(); return data; }
From source file:com.googlecode.download.maven.plugin.internal.SignatureUtils.java
static String computeSignatureAsString(File file, MessageDigest digest) throws IOException { InputStream fis = new FileInputStream(file); byte[] buffer = new byte[1024]; int numRead;//from w ww.j a v a2 s .c o m do { numRead = fis.read(buffer); if (numRead > 0) { digest.update(buffer, 0, numRead); } } while (numRead != -1); fis.close(); byte[] actualDigest = digest.digest(); return new String(Hex.encodeHex(actualDigest)); }
From source file:Main.java
static void copyFile(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;//from w w w.j a v a 2 s.com while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static OutputStream loadInputStreamToOutputStream(InputStream input, OutputStream output) { int BUFFER_SIZE = 1024 * 4; byte[] buffer = new byte[BUFFER_SIZE]; int n = 0;//w ww . j a v a 2 s .c o m try { while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } } catch (Exception e) { } return output; }
From source file:Main.java
public static void copyFileFromAssets(Context context, String fileName, File outputFile) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesCount; try {/*from w ww . j a v a 2 s . c o m*/ InputStream imageStream = context.getAssets().open(fileName); FileOutputStream fileOutputStream = new FileOutputStream(outputFile); while ((bytesCount = imageStream.read(buffer)) >= 0) { fileOutputStream.write(buffer, 0, bytesCount); } fileOutputStream.close(); imageStream.close(); } catch (IOException | Resources.NotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static byte[] readStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0;// w w w.j ava2 s . co m while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.close(); return outStream.toByteArray(); }
From source file:Main.java
public static byte[] readStream(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024 * 10]; int readlen;/* w ww.j a va2 s .com*/ while ((readlen = is.read(buf)) >= 0) { baos.write(buf, 0, readlen); } baos.close(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] readStream(InputStream in) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = in.read(buffer)) != -1) { outputStream.write(buffer, 0, len); }/*w ww . j a v a2s . co m*/ outputStream.close(); in.close(); return outputStream.toByteArray(); }
From source file:Main.java
private static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[8192]; int len = 0;// ww w. ja v a 2s. c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((len = inputStream.read(buffer)) != -1) { bos.write(buffer, 0, len); } bos.close(); return bos.toByteArray(); }