本文整理汇总了Java中android.util.Base64.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java Base64.DEFAULT属性的具体用法?Java Base64.DEFAULT怎么用?Java Base64.DEFAULT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.util.Base64
的用法示例。
在下文中一共展示了Base64.DEFAULT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: privateBase64Decoder
/**
* Private decoder in base64
*
* @param toDecode String to be encoded
* @param flags flags to decode the String
* @return decoded String in base64
*/
private static String privateBase64Decoder(String toDecode, int flags) {
if (flags == -1) {
flags = Base64.DEFAULT;
}
byte[] data1 = Base64.decode(toDecode, flags);
String decodedBase64 = null;
try {
decodedBase64 = new String(data1, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return decodedBase64;
}
示例2: getPathFromUri
/**
* Get an input stream based on file path or uri content://, http://, file://
*
* @param path path to file
* @return an input stream
* @throws IOException
*/
private InputStream getPathFromUri(String path) throws IOException {
if (path.startsWith("data:")) { // data:image/png;base64,[ENCODED_IMAGE]
String dataInfos = path.substring(0, path.indexOf(','));
dataInfos = dataInfos.substring(dataInfos.indexOf(':') + 1);
String baseEncoding = dataInfos.substring(dataInfos.indexOf(';') + 1);
// [ENCODED_IMAGE]
if("base64".equalsIgnoreCase(baseEncoding)) {
String img = path.substring(path.indexOf(',') + 1);
byte[] encodedData = img.getBytes();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(encodedData, 0, encodedData.length);
Base64InputStream base64InputStream = new Base64InputStream(byteArrayInputStream, Base64.DEFAULT);
return base64InputStream;
} else {
LOG.d(LOG_TAG, "Could not decode image. The found base encoding is " + baseEncoding);
}
}
if (path.startsWith("content:")) {
Uri uri = Uri.parse(path);
return mApp.getActivity().getContentResolver().openInputStream(uri);
}
if (path.startsWith(ASSET_URL_PREFIX)) {
String assetRelativePath = path.replace(ASSET_URL_PREFIX, "");
return mApp.getActivity().getAssets().open(assetRelativePath);
}
if (path.startsWith("http:") || path.startsWith("https:") || path.startsWith("file:")) {
URL url = new URL(path);
return url.openStream();
}
return new FileInputStream(path);
}
示例3: privateBase64Encoder
/**
* private Encoder in base64
*
* @param toEncode String to be encoded
* @param flags flags to encode the String
* @return encoded String in base64
*/
private static String privateBase64Encoder(String toEncode, int flags) {
byte[] data = null;
try {
data = toEncode.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
if (flags == -1) {
flags = Base64.DEFAULT;
}
return Base64.encodeToString(data, flags);
}