Java Code Examples for android.util.Base64#DEFAULT

The following examples show how to use android.util.Base64#DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScreencastDispatcher.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  if (!mIsRunning || mBitmap == null) {
    return;
  }
  int width = mBitmap.getWidth();
  int height = mBitmap.getHeight();
  mStream.reset();
  Base64OutputStream base64Stream = new Base64OutputStream(mStream, Base64.DEFAULT);
  // request format is either "jpeg" or "png"
  Bitmap.CompressFormat format = Bitmap.CompressFormat.valueOf(mRequest.format.toUpperCase());
  mBitmap.compress(format, mRequest.quality, base64Stream);
  mEvent.data = mStream.toString();
  mMetadata.pageScaleFactor = 1;
  mMetadata.deviceWidth = width;
  mMetadata.deviceHeight = height;
  mEvent.metadata = mMetadata;
  mPeer.invokeMethod("Page.screencastFrame", mEvent, null);
  mMainHandler.postDelayed(mEndAction, FRAME_DELAY);
}
 
Example 2
Source File: ScreencastDispatcher.java    From stetho with MIT License 6 votes vote down vote up
@Override
public void run() {
  if (!mIsRunning || mBitmap == null) {
    return;
  }
  int width = mBitmap.getWidth();
  int height = mBitmap.getHeight();
  mStream.reset();
  Base64OutputStream base64Stream = new Base64OutputStream(mStream, Base64.DEFAULT);
  // request format is either "jpeg" or "png"
  Bitmap.CompressFormat format = Bitmap.CompressFormat.valueOf(mRequest.format.toUpperCase());
  mBitmap.compress(format, mRequest.quality, base64Stream);
  mEvent.data = mStream.toString();
  mMetadata.pageScaleFactor = 1;
  mMetadata.deviceWidth = width;
  mMetadata.deviceHeight = height;
  mEvent.metadata = mMetadata;
  mPeer.invokeMethod("Page.screencastFrame", mEvent, null);
  mMainHandler.postDelayed(mEndAction, FRAME_DELAY);
}
 
Example 3
Source File: ResponseBodyFileManager.java    From Dream-Catcher with MIT License 5 votes vote down vote up
public OutputStream openResponseBodyFile(String requestId, boolean base64Encode)
    throws IOException {
  OutputStream out = mContext.openFileOutput(getFilename(requestId), Context.MODE_PRIVATE);
  out.write(base64Encode ? 1 : 0);
  if (base64Encode) {
    return new Base64OutputStream(out, Base64.DEFAULT);
  } else {
    return out;
  }
}
 
Example 4
Source File: ResponseBodyFileManager.java    From weex with Apache License 2.0 5 votes vote down vote up
public OutputStream openResponseBodyFile(String requestId, boolean base64Encode)
    throws IOException {
  OutputStream out = mContext.openFileOutput(getFilename(requestId), Context.MODE_PRIVATE);
  out.write(base64Encode ? 1 : 0);
  if (base64Encode) {
    return new Base64OutputStream(out, Base64.DEFAULT);
  } else {
    return out;
  }
}
 
Example 5
Source File: ResponseBodyFileManager.java    From stetho with MIT License 5 votes vote down vote up
public OutputStream openResponseBodyFile(String requestId, boolean base64Encode)
    throws IOException {
  OutputStream out = mContext.openFileOutput(getFilename(requestId), Context.MODE_PRIVATE);
  out.write(base64Encode ? 1 : 0);
  if (base64Encode) {
    return new Base64OutputStream(out, Base64.DEFAULT);
  } else {
    return out;
  }
}
 
Example 6
Source File: UrlStreamOpener.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
/**
 * @see http
 *      ://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/
 *      apache /xmlgraphics/util/uri/DataURIResolver.java
 */
private static InputStream openDataUriStream(String uri) {
    int commaPos = uri.indexOf(',');
    if (commaPos < 0) {
        PXLog.w(TAG, "Data uri is malformed: " + uri);
        return null;
    }

    String header = uri.substring(0, commaPos);
    String data = uri.substring(commaPos + 1);
    if (header.endsWith(";base64")) {
        byte[] bytes = data.getBytes();
        ByteArrayInputStream encodedStream = new ByteArrayInputStream(bytes);
        return new Base64InputStream(encodedStream, Base64.DEFAULT);
    } else {
        String encoding = "UTF-8";
        final int charsetpos = header.indexOf(";charset=");
        if (charsetpos > 0) {
            encoding = header.substring(charsetpos + 9);
        }
        try {
            return new ByteArrayInputStream(URLDecoder.decode(data, encoding)
                    .getBytes(encoding));
        } catch (Exception e) {
            PXLog.e(TAG, e, "Unable to decode data uri contents: " + uri);
        }
    }
    return null;
}
 
Example 7
Source File: UrlStreamOpenerTests.java    From pixate-freestyle-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    Context context = this.getContext();
    PixateFreestyle.init(context.getApplicationContext());

    // Grab the bitmap placed in the assets. We can use it to compare
    // results later.
    InputStream is = context.getAssets().open(IMAGE_ASSET);
    assetBitmap = BitmapFactory.decodeStream(is);
    is.close();

    Resources resources = context.getResources();

    int rawFileId = resources.getIdentifier(RAW_TEST_FILE, "raw", this.getContext().getPackageName());

    testFileContents = readStream(resources.openRawResource(rawFileId));

    // Create a document file.
    OutputStreamWriter writer =
            new OutputStreamWriter(getContext().openFileOutput(DOCUMENT_FILE, Context.MODE_PRIVATE));
    try {
        writer.write(testFileContents);
    } finally {
        writer.close();
    }

    // Learn the document file's file:// uri so we can test that scheme.
    documentFileUri = new File(context.getFilesDir(), DOCUMENT_FILE).toURI().toString();

    // Clean it up to make it look like someone would type it in css
    // (file:// instead of just file:/)
    if (documentFileUri.startsWith("file:/") && !documentFileUri.startsWith("file://")) {
        documentFileUri = documentFileUri.replace("file:", "file://");
    }

    // Create a temp file.
    tempFile = new File(context.getCacheDir(), TMP_FILE);
    writer = new OutputStreamWriter(new FileOutputStream(tempFile));
    try {
        writer.write(testFileContents);
    } finally {
        writer.close();
    }

    // Get a base64 of the test asset image bytes so we can do a data: call
    // and compare results.
    is = context.getAssets().open(IMAGE_ASSET);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    Base64OutputStream bos = new Base64OutputStream(output, Base64.DEFAULT);

    try {
        byte[] buffer = new byte[2048];
        int count = is.read(buffer);

        while (count > 0) {
            bos.write(buffer, 0, count);
            count = is.read(buffer);
        }

        assetBitmapBase64 = output.toString();

    } finally {
        is.close();
        bos.close();
    }

}