android.util.Base64OutputStream

Here are the examples of the java api class android.util.Base64OutputStream taken from open source projects.

1. JsonStreamerEntity#writeToFromFile()

Project: RestVolley
File: JsonStreamerEntity.java
private void writeToFromFile(OutputStream os, FileWrapper wrapper) throws IOException {
    writeMetaData(os, wrapper.file.getName(), wrapper.contentType);
    int bytesRead;
    FileInputStream in = new FileInputStream(wrapper.file);
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);
    while ((bytesRead = in.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }
    if (bos != null) {
        bos.close();
    }
    endMetaData(os);
    if (in != null) {
        in.close();
    }
}

2. JsonStreamerEntity#writeToFromStream()

Project: RestVolley
File: JsonStreamerEntity.java
private void writeToFromStream(OutputStream os, StreamWrapper entry) throws IOException {
    writeMetaData(os, entry.name, entry.contentType);
    int bytesRead;
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);
    while ((bytesRead = entry.inputStream.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }
    if (bos != null) {
        bos.close();
    }
    endMetaData(os);
    if (entry.autoClose) {
        if (entry.inputStream != null) {
            entry.inputStream.close();
        }
    }
}

3. UrlStreamOpenerTests#setUp()

Project: pixate-freestyle-android
File: UrlStreamOpenerTests.java
@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();
    // (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();
    }
}