android.util.Base64 编码/解码标志参数
根据 Javadoc,android.util.Base64.decode() 采用两个参数:文本和“flags”。这些标志采用 int 形式并且(我引用):
flags 控制解码输出的某些功能。传递 DEFAULT 来解码标准 Base64。
首先,感谢决定编写模糊 Javadoc 的人。我看到 Base64 有一些枚举字符串,在实践中,我们一直使用 Base64.NO_WRAP 作为我们的标志。然而,在这个特定的实例中,我们需要使用两个标志:NO_WRAP 和 URL_SAFE。
我们如何指定这两个标志?我们尝试用管道(“|”)将它们分开,但没有成功。
import android.util.Base64;
public class Foo {
public static void main(String[] args) {
String urlSafeBase64EncodedString = getUrlSafeBase64EncodedString();
int flags = ????????; //Need both Base64.NO_WRAP and Base64.URL_SAFE
String decodedString = Base64.decode(urlSafeBase64EncodedString, flags);
}
}
感谢您抽出时间。
According to the Javadoc, android.util.Base64.decode() takes two parameters: the text, and "flags". These flags are in int form and (I quote):
flags controls certain features of the decoded output. Pass DEFAULT to decode standard Base64.
First off, thanks to whomever decided to write a vague Javadoc. I see that Base64 has some enumeration strings, and in practice, we have been using Base64.NO_WRAP as our flag. In this particular instance, however, we need to employ two flags: NO_WRAP, and URL_SAFE.
How do we specify both flags? We tried separating them with a pipe ('|'), and that didn't do it.
import android.util.Base64;
public class Foo {
public static void main(String[] args) {
String urlSafeBase64EncodedString = getUrlSafeBase64EncodedString();
int flags = ????????; //Need both Base64.NO_WRAP and Base64.URL_SAFE
String decodedString = Base64.decode(urlSafeBase64EncodedString, flags);
}
}
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递给函数的 int 标志通常定义为按位或运算以实现组合效果。
您通常可以通过查看常量值来判断,它们会变成 0 1 2 4 8 16 ..
至于您的问题,您可以使用以下内容进行标志定义:
int flags passed to functions are usually defined to be bitwise ORed to achieve a combined effect.
You can usually tell by looking at the constant values, they would go 0 1 2 4 8 16 ..
As for your question you can use the following for your flag definition:
对于
kotlin
你可以使用For
kotlin
you can use