android.util.Base64InputStream Java Examples

The following examples show how to use android.util.Base64InputStream. 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: ImageStoreManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Just to test if using the ByteArrayInputStream isn't missing something
 */
@Test
public void itDoesNotAddLineBreaks_whenBase64InputStream() throws IOException {
  byte[] exampleString = "dGVzdA==".getBytes();
  Base64InputStream inputStream =
      new Base64InputStream(new ByteArrayInputStream(exampleString), Base64.NO_WRAP);
  assertEquals("dGVzdA==", invokeConversion(inputStream));
}
 
Example #2
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;
}