Search in sources :

Example 66 with OutputStream

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();
}
Also used : CacheRequest(java.net.CacheRequest) OutputStream(java.io.OutputStream) URI(java.net.URI) URL(java.net.URL)

Example 67 with OutputStream

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);
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 68 with OutputStream

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);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) Uri(android.net.Uri)

Example 69 with OutputStream

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;
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) Date(java.util.Date) Notification(android.app.Notification) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 70 with OutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream)

Aggregations

OutputStream (java.io.OutputStream)4178 IOException (java.io.IOException)1673 FileOutputStream (java.io.FileOutputStream)1331 InputStream (java.io.InputStream)1304 File (java.io.File)925 ByteArrayOutputStream (java.io.ByteArrayOutputStream)830 Test (org.junit.Test)735 BufferedOutputStream (java.io.BufferedOutputStream)477 FileInputStream (java.io.FileInputStream)431 Socket (java.net.Socket)375 ByteArrayInputStream (java.io.ByteArrayInputStream)233 URL (java.net.URL)231 OutputStreamWriter (java.io.OutputStreamWriter)230 HttpURLConnection (java.net.HttpURLConnection)189 BufferedInputStream (java.io.BufferedInputStream)178 InputStreamReader (java.io.InputStreamReader)176 BufferedReader (java.io.BufferedReader)159 FileNotFoundException (java.io.FileNotFoundException)158 GZIPOutputStream (java.util.zip.GZIPOutputStream)157 Path (java.nio.file.Path)155