List of usage examples for java.io OutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this output stream. From source file:Main.java
protected static void copyFile(InputStream inStream, OutputStream outStream) throws IOException { byte[] buf = new byte[2048]; int len;/* www. ja va2s . c o m*/ while ((len = inStream.read(buf)) > 0) { outStream.write(buf, 0, len); } }
From source file:Utils.java
public static void copyInputStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int len = in.read(buffer); while (len >= 0) { out.write(buffer, 0, len); len = in.read(buffer);//www. ja va 2s .co m } in.close(); out.close(); }
From source file:Main.java
/** * Copies a file from res/raw to destination (typically context.getFilesDir()) *///from w ww. j a va 2 s . c o m public static void copyInputFileStreamToFilesystem(InputStream in, String outputFilePathName) throws IOException { Log.i(TAG, "copyInputFileStreamToFilesystem() outputFilePathName: " + outputFilePathName); OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFilePathName)); byte[] buffer = new byte[4096]; int len = in.read(buffer); while (len != -1) { out.write(buffer, 0, len); len = in.read(buffer); } out.close(); }
From source file:ZipHelper.java
private static void streamCopy(InputStream is, OutputStream os) throws IOException { byte[] buffer = new byte[BUFFER_SIZE]; int len;//from w w w . java2 s .co m while ((len = is.read(buffer)) > 0) { os.write(buffer, 0, len); } }
From source file:Main.java
public static final void writeFix(OutputStream out, String s, int fix) throws IOException { if (fix <= 0) return;/*w w w . j av a 2 s . co m*/ byte[] b = s.getBytes(); if (b.length < fix) throw new IOException(); out.write(b, 0, fix); }
From source file:Main.java
/** * Dump the database file to external storage * * @param packageName/*from ww w . j ava 2s .c om*/ * @param fileName * @throws IOException */ public static void dumpDatabase(String packageName, String fileName) throws IOException { File dbFile = new File("/data/data/" + packageName + "/databases/" + fileName); if (dbFile.exists()) { FileInputStream fis = new FileInputStream(dbFile); String outFileName = Environment.getExternalStorageDirectory() + "/" + fileName; OutputStream output = new FileOutputStream(outFileName); byte[] buffer = new byte[1024]; int length; while ((length = fis.read(buffer)) > 0) { output.write(buffer, 0, length); } output.flush(); output.close(); fis.close(); } }
From source file:Main.java
public static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); // set params int sessionId = packageInstaller.createSession(params); PackageInstaller.Session session = packageInstaller.openSession(sessionId); OutputStream out = session.openWrite("COSU", 0, -1); byte[] buffer = new byte[65536]; int c;/*from w ww . j a v a 2 s . com*/ while ((c = in.read(buffer)) != -1) { out.write(buffer, 0, c); } session.fsync(out); in.close(); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
From source file:Main.java
/** * Copies all of the bytes from {@code in} to {@code out}. Neither stream is closed. * Returns the total number of bytes transferred. *//*from w w w .j ava 2 s .co m*/ public static int copy(InputStream in, OutputStream out) throws IOException { int total = 0; byte[] buffer = new byte[8192]; int c; while ((c = in.read(buffer)) != -1) { total += c; out.write(buffer, 0, c); } return total; }
From source file:Main.java
/** * Copy the content of the input stream into the output stream, using a * temporary byte array buffer whose size is defined by * {@link #FILE_BUFFER_SIZE}.//from w w w.j a v a 2 s . com * * @param in * The input stream to copy from. * @param out * The output stream to copy to. * * @throws java.io.IOException * If any error occurs during the copy. */ public static void copyFile(InputStream in, OutputStream out, long length) throws IOException { long totalRead = 0; byte[] b = new byte[FILE_BUFFER_SIZE]; int read; while ((read = in.read(b)) > 0) { out.write(b, 0, read); out.flush(); totalRead += read; if (totalRead >= length) break; } }
From source file:Main.java
public static void copyStream(InputStream is, OutputStream os) throws IOException { byte[] bytes = new byte[BUFFER_SIZE]; for (;;) {// ww w. j a v a 2 s. c o m int count = is.read(bytes, 0, BUFFER_SIZE); if (count == -1) break; os.write(bytes, 0, count); } }