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;
}
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();
}
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");
}
}
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();
}
}
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);
}
}
Aggregations