本文整理了Java中android.util.Base64.encodeToString()
方法的一些代码示例,展示了Base64.encodeToString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encodeToString()
方法的具体详情如下:
包路径:android.util.Base64
类名称:Base64
方法名:encodeToString
[英]Base64-encode the given data and return a newly allocated String with the result.
[中]Base64对给定数据进行编码,并返回一个新分配的字符串和结果。
代码示例来源:origin: google/tink
private static String base64Encode(final byte[] input) {
return Base64.encodeToString(input, Base64.DEFAULT);
}
代码示例来源:origin: yanzhenjie/NoHttp
/**
* @return the data.
*/
public String getDataBase64() {
return Base64.encodeToString(data, Base64.DEFAULT);
}
代码示例来源:origin: igniterealtime/Smack
@Override
public String encodeToString(byte[] input, int offset, int len) {
return Base64.encodeToString(input, offset, len, BASE64_ENCODER_FLAGS);
}
代码示例来源:origin: orhanobut/hawk
String encodeBase64(byte[] bytes) {
return Base64.encodeToString(bytes, Base64.DEFAULT);
}
代码示例来源:origin: igniterealtime/Smack
@Override
public String encode(String string) {
try {
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 not supported", e);
}
}
代码示例来源:origin: facebook/stetho
private static String generateServerKey(String clientKey) {
try {
String serverKey = clientKey + SERVER_KEY_GUID;
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
sha1.update(Utf8Charset.encodeUTF8(serverKey));
return Base64.encodeToString(sha1.digest(), Base64.NO_WRAP);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: ACRA/acra
@Nullable
public static String serialize(@NonNull Serializable serializable) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ObjectOutputStream outputStream = new ObjectOutputStream(out)) {
outputStream.writeObject(serializable);
return Base64.encodeToString(out.toByteArray(), Base64.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: evernote/android-job
public static void writeByteArrayAttribute(XmlSerializer out, String name, byte[] value)
throws IOException {
if (value != null) {
out.attribute(null, name, Base64.encodeToString(value, Base64.DEFAULT));
}
}
代码示例来源:origin: facebook/facebook-android-sdk
@Override
public String call() {
View view = this.rootView.get();
if (view == null || view.getWidth() == 0 || view.getHeight() == 0) {
return "";
}
Bitmap bitmap = Bitmap.createBitmap(
view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// TODO: T25009391, Support better screenshot image quality by using file attachment.
bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream);
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
}
}
代码示例来源:origin: orhanobut/hawk
@Override public String encrypt(String key, String plainText) throws Exception {
Entity entity = Entity.create(key);
byte[] bytes = crypto.encrypt(plainText.getBytes(), entity);
return Base64.encodeToString(bytes, Base64.NO_WRAP);
}
代码示例来源:origin: hidroh/materialistic
@JavascriptInterface
public String getChunk(long begin, long end) {
try {
if (mRandomAccessFile == null) {
mRandomAccessFile = new RandomAccessFile(mFile, "r");
}
if (mRandomAccessFile != null) {
final int bufferSize = (int)(end - begin);
byte[] data = new byte[bufferSize];
mRandomAccessFile.seek(begin);
mRandomAccessFile.read(data);
return Base64.encodeToString(data, Base64.DEFAULT);
} else {
return "";
}
} catch (IOException e) {
Log.e("Exception", e.toString());
return "";
}
}
代码示例来源:origin: AltBeacon/android-beacon-library
/**
* Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon
* and base64 encodes them. This is useful for passing the telemetry to Google's backend
* services.
* @param beacon
* @return base64 encoded telemetry bytes
*/
@TargetApi(Build.VERSION_CODES.FROYO)
public String getBase64EncodedTelemetry(Beacon beacon) {
byte[] bytes = getTelemetryBytes(beacon);
if (bytes != null) {
String base64EncodedTelemetry = Base64.encodeToString(bytes, Base64.DEFAULT);
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Rehydrated telemetry bytes are :20 00 00 00 88 29 18 4d 00 00 18 4d 00 00
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Base64 telemetry bytes are :IAAAAIgpGE0AABhNAAA=
Log.d(TAG, "Base64 telemetry bytes are :"+base64EncodedTelemetry);
return base64EncodedTelemetry;
}
else {
return null;
}
}
代码示例来源:origin: gotev/android-upload-service
/**
* Sets the HTTP Basic Authentication header.
* @param username HTTP Basic Auth username
* @param password HTTP Basic Auth password
* @return self instance
*/
public B setBasicAuth(final String username, final String password) {
String auth = Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP);
httpParams.addHeader("Authorization", "Basic " + auth);
return self();
}
代码示例来源:origin: bumptech/glide
@SuppressWarnings("deprecation")
private String getBase64BitmapBytes(CompressFormat format) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable =
Preconditions.checkNotNull(ContextCompat.getDrawable(context, ResourceIds.raw.canonical));
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
bitmap.compress(format, 100, bos);
byte[] data = bos.toByteArray();
return Base64.encodeToString(data, /*flags=*/ 0);
}
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Base64-encode the given data and return a newly allocated String with the result.
*
* @param context
* @param type
* @return
*/
public static String Base64encoding(byte[] context, int type) {
String result = "";
if (getSdkVersion() > 7) {
result = Base64.encodeToString(context, type);
} else {
result = com.marshalchen.ua.common.commonUtils.urlUtils.Base64.encodeBytes(context);
}
return result;
}
代码示例来源:origin: LitePalFramework/LitePal
/**
* Encrypt and encode message using 256-bit AES with key generated from password.
*
*
* @param password used to generated key
* @param message the thing you want to encrypt assumed String UTF-8
* @return Base64 encoded CipherText
* @throws GeneralSecurityException if problems occur during encryption
*/
public static String encrypt(final String password, String message)
throws GeneralSecurityException {
try {
final SecretKeySpec key = generateKey(password);
log("message", message);
byte[] cipherText = encrypt(key, ivBytes, message.getBytes(CHARSET));
//NO_WRAP is important as was getting \n at the end
String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP);
log("Base64.NO_WRAP", encoded);
return encoded;
} catch (UnsupportedEncodingException e) {
if (DEBUG_LOG_ENABLED)
Log.e(TAG, "UnsupportedEncodingException ", e);
throw new GeneralSecurityException(e);
}
}
代码示例来源:origin: termux/termux-app
public void disabledTestSetClipboard() {
// Cannot run this as a unit test since Base64 is a android.util class.
enterString("\033]52;c;" + Base64.encodeToString("Hello, world".getBytes(), 0) + "\007");
}
代码示例来源:origin: yanzhenjie/NoHttp
@Override
public long replace(CacheEntity cacheEntity) {
SQLiteDatabase database = getWriter();
database.beginTransaction();
try {
ContentValues values = new ContentValues();
values.put(CacheSQLHelper.KEY, cacheEntity.getKey());
values.put(CacheSQLHelper.HEAD, encrypt(cacheEntity.getResponseHeadersJson()));
values.put(CacheSQLHelper.DATA, encrypt(Base64.encodeToString(cacheEntity.getData(), Base64.DEFAULT)));
values.put(CacheSQLHelper.LOCAL_EXPIRES, encrypt(Long.toString(cacheEntity.getLocalExpire())));
long result = database.replace(getTableName(), null, values);
database.setTransactionSuccessful();
return result;
} catch (Exception e) {
return -1;
} finally {
database.endTransaction();
closeDateBase(database);
}
}
代码示例来源:origin: facebook/facebook-android-sdk
private static String encodeUserInfo(UserInfo userInfo) {
Parcel parcel = Parcel.obtain();
parcel.writeValue(userInfo);
byte[] data = parcel.marshall();
parcel.recycle();
return Base64.encodeToString(data, Base64.DEFAULT);
}
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testPdfAndroidJavascriptBridgeGetChunk() throws IOException {
final String path = this.getClass().getClassLoader().getResource("file.txt").getPath();
final File file = new File(path);
final long size = file.length();
final String expected = Base64.encodeToString(Okio.buffer(Okio.source(file)).readByteArray(), Base64.DEFAULT);
final WebFragment.PdfAndroidJavascriptBridge bridge = new WebFragment.PdfAndroidJavascriptBridge(path, null);
assertEquals(expected, bridge.getChunk(0, size));
}
内容来源于网络,如有侵权,请联系作者删除!