Search in sources :

Example 91 with BufferedOutputStream

use of java.io.BufferedOutputStream in project platform_frameworks_base by android.

the class LocalTransport method sendBackupData.

@Override
public int sendBackupData(final int numBytes) {
    if (mSocket == null) {
        Log.w(TAG, "Attempted sendBackupData before performFullBackup");
        return TRANSPORT_ERROR;
    }
    mFullBackupSize += numBytes;
    if (mFullBackupSize > FULL_BACKUP_SIZE_QUOTA) {
        return TRANSPORT_QUOTA_EXCEEDED;
    }
    if (numBytes > mFullBackupBuffer.length) {
        mFullBackupBuffer = new byte[numBytes];
    }
    if (mFullBackupOutputStream == null) {
        FileOutputStream tarstream;
        try {
            File tarball = tarballFile(mFullTargetPackage);
            tarstream = new FileOutputStream(tarball);
        } catch (FileNotFoundException e) {
            return TRANSPORT_ERROR;
        }
        mFullBackupOutputStream = new BufferedOutputStream(tarstream);
    }
    int bytesLeft = numBytes;
    while (bytesLeft > 0) {
        try {
            int nRead = mSocketInputStream.read(mFullBackupBuffer, 0, bytesLeft);
            if (nRead < 0) {
                // Something went wrong if we expect data but saw EOD
                Log.w(TAG, "Unexpected EOD; failing backup");
                return TRANSPORT_ERROR;
            }
            mFullBackupOutputStream.write(mFullBackupBuffer, 0, nRead);
            bytesLeft -= nRead;
        } catch (IOException e) {
            Log.e(TAG, "Error handling backup data for " + mFullTargetPackage);
            return TRANSPORT_ERROR;
        }
    }
    if (DEBUG) {
        Log.v(TAG, "   stored " + numBytes + " of data");
    }
    return TRANSPORT_OK;
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 92 with BufferedOutputStream

use of java.io.BufferedOutputStream in project jstorm by alibaba.

the class MyScpClient method sendFiles.

private void sendFiles(Session sess, String[] files, String mode) throws IOException {
    byte[] buffer = new byte[8192];
    OutputStream os = new BufferedOutputStream(sess.getStdin(), 40000);
    InputStream is = new BufferedInputStream(sess.getStdout(), 512);
    readResponse(is);
    for (int i = 0; i < files.length; i++) {
        File f = new File(files[i]);
        long remain = f.length();
        String cline = "C" + mode + " " + remain + " " + f.getName() + "\n";
        os.write(cline.getBytes());
        os.flush();
        readResponse(is);
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            while (remain > 0) {
                int trans;
                if (remain > buffer.length)
                    trans = buffer.length;
                else
                    trans = (int) remain;
                if (fis.read(buffer, 0, trans) != trans)
                    throw new IOException("Cannot read enough from local file " + files[i]);
                os.write(buffer, 0, trans);
                remain -= trans;
            }
            fis.close();
        } catch (IOException e) {
            if (fis != null) {
                fis.close();
            }
            throw (e);
        }
        os.write(0);
        os.flush();
        readResponse(is);
    }
    os.write("E\n".getBytes());
    os.flush();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 93 with BufferedOutputStream

use of java.io.BufferedOutputStream in project jstorm by alibaba.

the class JStormUtilsTest method testJar.

public static void testJar(String id) {
    try {
        PathUtils.local_mkdirs(pidDir);
    } catch (IOException e) {
        LOG.error("Failed to rmr " + pidDir, e);
    }
    fillData();
    LOG.info("Finish load data");
    String pid = JStormUtils.process_pid();
    String pidFile = pidDir + File.separator + pid;
    try {
        PathUtils.touch(pidFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        LOG.error("Failed to touch " + pidFile, e);
    }
    try {
        DataOutputStream raf = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(pidFile), true)));
        raf.writeBytes(pid);
    } catch (Exception e) {
        LOG.error("", e);
    }
    while (true) {
        JStormUtils.sleepMs(1000);
        LOG.info(id + " is living");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) IOException(java.io.IOException)

Example 94 with BufferedOutputStream

use of java.io.BufferedOutputStream in project platform_frameworks_base by android.

the class ViewDebug method capture.

/** @hide */
public static void capture(View root, final OutputStream clientStream, View captureView) throws IOException {
    Bitmap b = performViewCapture(captureView, false);
    if (b == null) {
        Log.w("View", "Failed to create capture bitmap!");
        // Send an empty one so that it doesn't get stuck waiting for
        // something.
        b = Bitmap.createBitmap(root.getResources().getDisplayMetrics(), 1, 1, Bitmap.Config.ARGB_8888);
    }
    BufferedOutputStream out = null;
    try {
        out = new BufferedOutputStream(clientStream, 32 * 1024);
        b.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
    } finally {
        if (out != null) {
            out.close();
        }
        b.recycle();
    }
}
Also used : Bitmap(android.graphics.Bitmap) BufferedOutputStream(java.io.BufferedOutputStream)

Example 95 with BufferedOutputStream

use of java.io.BufferedOutputStream in project platform_frameworks_base by android.

the class FileRotator method writeFile.

private static void writeFile(File file, Writer writer) throws IOException {
    final FileOutputStream fos = new FileOutputStream(file);
    final BufferedOutputStream bos = new BufferedOutputStream(fos);
    try {
        writer.write(bos);
        bos.flush();
    } finally {
        FileUtils.sync(fos);
        IoUtils.closeQuietly(bos);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1219 FileOutputStream (java.io.FileOutputStream)861 IOException (java.io.IOException)617 File (java.io.File)519 OutputStream (java.io.OutputStream)350 BufferedInputStream (java.io.BufferedInputStream)238 InputStream (java.io.InputStream)166 DataOutputStream (java.io.DataOutputStream)158 FileInputStream (java.io.FileInputStream)145 ZipOutputStream (java.util.zip.ZipOutputStream)121 FileNotFoundException (java.io.FileNotFoundException)113 ZipEntry (java.util.zip.ZipEntry)108 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 ZipFile (java.util.zip.ZipFile)62 URL (java.net.URL)57 XmlSerializer (org.xmlpull.v1.XmlSerializer)57 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)56 ObjectOutputStream (java.io.ObjectOutputStream)54 GZIPOutputStream (java.util.zip.GZIPOutputStream)51 PrintStream (java.io.PrintStream)46