use of java.io.OutputStream in project enroscar by stanfy.
the class TestUtils method putCachedContent.
static void putCachedContent(final ImagesManager manager, final String url) throws Exception {
CacheRequest cacheRequest = manager.getImagesResponseCache().put(new URI(url), fakeConnection(new URL(url)));
OutputStream out = cacheRequest.getBody();
out.write(new byte[] { 1 });
out.close();
}
use of java.io.OutputStream in project platform_frameworks_base by android.
the class SamplingProfilerIntegration method writeSnapshotFile.
/**
* pass in PackageInfo to retrieve various values for snapshot header
*/
private static void writeSnapshotFile(String processName, PackageInfo packageInfo) {
if (!enabled) {
return;
}
samplingProfiler.stop();
/*
* We use the global start time combined with the process name
* as a unique ID. We can't use a counter because processes
* restart. This could result in some overlap if we capture
* two snapshots in rapid succession.
*/
String name = processName.replaceAll(":", ".");
String path = SNAPSHOT_DIR + "/" + name + "-" + startMillis + ".snapshot";
long start = System.currentTimeMillis();
OutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(path));
PrintStream out = new PrintStream(outputStream);
generateSnapshotHeader(name, packageInfo, out);
if (out.checkError()) {
throw new IOException();
}
BinaryHprofWriter.write(samplingProfiler.getHprofData(), outputStream);
} catch (IOException e) {
Log.e(TAG, "Error writing snapshot to " + path, e);
return;
} finally {
IoUtils.closeQuietly(outputStream);
}
// set file readable to the world so that SamplingProfilerService
// can put it to dropbox
new File(path).setReadable(true, false);
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "Wrote snapshot " + path + " in " + elapsed + "ms.");
samplingProfiler.start(samplingProfilerMilliseconds);
}
use of java.io.OutputStream in project platform_frameworks_base by android.
the class NekoLand method shareCat.
private void shareCat(Cat cat) {
final File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), getString(R.string.directory_name));
if (!dir.exists() && !dir.mkdirs()) {
Log.e("NekoLand", "save: error: can't create Pictures directory");
return;
}
final File png = new File(dir, cat.getName().replaceAll("[/ #:]+", "_") + ".png");
Bitmap bitmap = cat.createBitmap(EXPORT_BITMAP_SIZE, EXPORT_BITMAP_SIZE);
if (bitmap != null) {
try {
OutputStream os = new FileOutputStream(png);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, os);
os.close();
MediaScannerConnection.scanFile(this, new String[] { png.toString() }, new String[] { "image/png" }, null);
Uri uri = Uri.fromFile(png);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName());
intent.setType("image/png");
startActivity(Intent.createChooser(intent, null));
cat.logShare(this);
} catch (IOException e) {
Log.e("NekoLand", "save: error: " + e);
}
}
}
use of java.io.OutputStream in project platform_frameworks_base by android.
the class GlobalScreenshot method doInBackground.
@Override
protected Void doInBackground(Void... params) {
if (isCancelled()) {
return null;
}
// By default, AsyncTask sets the worker thread to have background thread priority, so bump
// it back up so that we save a little quicker.
Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
Context context = mParams.context;
Bitmap image = mParams.image;
Resources r = context.getResources();
try {
// Create screenshot directory if it doesn't exist
mScreenshotDir.mkdirs();
// media provider uses seconds for DATE_MODIFIED and DATE_ADDED, but milliseconds
// for DATE_TAKEN
long dateSeconds = mImageTime / 1000;
// Save
OutputStream out = new FileOutputStream(mImageFilePath);
image.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
// Save the screenshot to the MediaStore
ContentValues values = new ContentValues();
ContentResolver resolver = context.getContentResolver();
values.put(MediaStore.Images.ImageColumns.DATA, mImageFilePath);
values.put(MediaStore.Images.ImageColumns.TITLE, mImageFileName);
values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageFileName);
values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, mImageTime);
values.put(MediaStore.Images.ImageColumns.DATE_ADDED, dateSeconds);
values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, dateSeconds);
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
values.put(MediaStore.Images.ImageColumns.WIDTH, mImageWidth);
values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// Create a share intent
String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
// Create a share action for the notification
PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Intent chooserIntent = Intent.createChooser(sharingIntent, null, chooseAction.getIntentSender()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent shareAction = PendingIntent.getActivity(context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_share, r.getString(com.android.internal.R.string.share), shareAction);
mNotificationBuilder.addAction(shareActionBuilder.build());
// Create a delete action for the notification
PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class).putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_delete, r.getString(com.android.internal.R.string.delete), deleteAction);
mNotificationBuilder.addAction(deleteActionBuilder.build());
mParams.imageUri = uri;
mParams.image = null;
mParams.errorMsgResId = 0;
} catch (Exception e) {
// IOException/UnsupportedOperationException may be thrown if external storage is not
// mounted
mParams.clearImage();
mParams.errorMsgResId = R.string.screenshot_failed_to_save_text;
}
// Recycle the bitmap data
if (image != null) {
image.recycle();
}
return null;
}
use of java.io.OutputStream in project platform_frameworks_base by android.
the class ExifInterface method writeExif.
/**
* Writes the tags from this ExifInterface object into a jpeg stream,
* removing prior exif tags.
*
* @param jpegStream an InputStream containing a jpeg compressed image.
* @param exifOutStream an OutputStream to which the jpeg image with added
* exif tags will be written.
* @throws IOException
*/
public void writeExif(InputStream jpegStream, OutputStream exifOutStream) throws IOException {
if (jpegStream == null || exifOutStream == null) {
throw new IllegalArgumentException(NULL_ARGUMENT_STRING);
}
OutputStream s = getExifWriterStream(exifOutStream);
doExifStreamIO(jpegStream, s);
s.flush();
}
Aggregations