DEFAULT源码实例Demo

android.util.Base64#DEFAULT源码实例Demo

下面列出了android.util.Base64#DEFAULT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: weex   文件: ScreencastDispatcher.java
@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);
}
 
源代码2 项目: stetho   文件: ScreencastDispatcher.java
@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);
}
 
源代码3 项目: Dream-Catcher   文件: ResponseBodyFileManager.java
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;
  }
}
 
源代码4 项目: weex   文件: ResponseBodyFileManager.java
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;
  }
}
 
源代码5 项目: stetho   文件: ResponseBodyFileManager.java
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;
  }
}
 
/**
 * @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;
}
 
@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();
    }

}
 
点击广告?(赏赐笔者)
 方法所在类