本文整理匯總了Java中java.util.Base64.getUrlDecoder方法的典型用法代碼示例。如果您正苦於以下問題:Java Base64.getUrlDecoder方法的具體用法?Java Base64.getUrlDecoder怎麽用?Java Base64.getUrlDecoder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Base64
的用法示例。
在下文中一共展示了Base64.getUrlDecoder方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.util.Base64; //導入方法依賴的package包/類
public static void main(String[] args) {
Base64.Decoder b64decoder = Base64.getUrlDecoder();
final Undertow server = Undertow.builder()
.addHttpListener(8083, "localhost")
.setHandler(exchange -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
String credential = exchange.getRequestHeaders().getFirst("X-Bouncr-Credential");
String[] tokens = credential.split("\\.", 3);
String json = new String(b64decoder.decode(tokens[1]));
exchange.getResponseSender().send("Server1\n"
+ "profile=" + json + "\n"
);
})
.build();
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
server.start();
}
示例2: FakedHttpWrapper
import java.util.Base64; //導入方法依賴的package包/類
public FakedHttpWrapper(boolean requestMode) {
this.requestMode = requestMode;
this.encoder = Base64.getUrlEncoder();
this.decoder = Base64.getUrlDecoder();
}
示例3: testMalformedPadding
import java.util.Base64; //導入方法依賴的package包/類
private static void testMalformedPadding() throws Throwable {
Object[] data = new Object[] {
"$=#", "", 0, // illegal ending unit
"A", "", 0, // dangling single byte
"A=", "", 0,
"A==", "", 0,
"QUJDA", "ABC", 4,
"QUJDA=", "ABC", 4,
"QUJDA==", "ABC", 4,
"=", "", 0, // unnecessary padding
"QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD"
"AA=", "", 0, // incomplete padding
"QQ=", "", 0,
"QQ=N", "", 0, // incorrect padding
"QQ=?", "", 0,
"QUJDQQ=", "ABC", 4,
"QUJDQQ=N", "ABC", 4,
"QUJDQQ=?", "ABC", 4,
};
Base64.Decoder[] decs = new Base64.Decoder[] {
Base64.getDecoder(),
Base64.getUrlDecoder(),
Base64.getMimeDecoder()
};
for (Base64.Decoder dec : decs) {
for (int i = 0; i < data.length; i += 3) {
final String srcStr = (String)data[i];
final byte[] srcBytes = srcStr.getBytes("ASCII");
final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes);
byte[] expected = ((String)data[i + 1]).getBytes("ASCII");
int pos = (Integer)data[i + 2];
// decode(byte[])
checkIAE(() -> dec.decode(srcBytes));
// decode(String)
checkIAE(() -> dec.decode(srcStr));
// decode(ByteBuffer)
checkIAE(() -> dec.decode(srcBB));
// wrap stream
checkIOE(new Testable() {
public void test() throws IOException {
try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) {
while (is.read() != -1);
}
}});
}
}
}
示例4: testMalformedPadding
import java.util.Base64; //導入方法依賴的package包/類
private static void testMalformedPadding() throws Throwable {
Object[] data = new Object[] {
"$=#", "", 0, // illegal ending unit
"A", "", 0, // dangling single byte
"A=", "", 0,
"A==", "", 0,
"QUJDA", "ABC", 4,
"QUJDA=", "ABC", 4,
"QUJDA==", "ABC", 4,
"=", "", 0, // unnecessary padding
"QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD"
"AA=", "", 0, // incomplete padding
"QQ=", "", 0,
"QQ=N", "", 0, // incorrect padding
"QQ=?", "", 0,
"QUJDQQ=", "ABC", 4,
"QUJDQQ=N", "ABC", 4,
"QUJDQQ=?", "ABC", 4,
};
Base64.Decoder[] decs = new Base64.Decoder[] {
Base64.getDecoder(),
Base64.getUrlDecoder(),
Base64.getMimeDecoder()
};
for (Base64.Decoder dec : decs) {
for (int i = 0; i < data.length; i += 3) {
final String srcStr = (String)data[i];
final byte[] srcBytes = srcStr.getBytes("ASCII");
final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes);
byte[] expected = ((String)data[i + 1]).getBytes("ASCII");
int pos = (Integer)data[i + 2];
// decode(byte[])
checkIAE(() -> dec.decode(srcBytes));
// decode(String)
checkIAE(() -> dec.decode(srcStr));
// decode(ByteBuffer)
checkIAE(() -> dec.decode(srcBB));
// wrap stream
checkIOE(new Testable() {
public void test() throws IOException {
try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) {
while (is.read() != -1);
}
}});
}
}
// anything left after padding is "invalid"/IAE, if
// not MIME. In case of MIME, non-base64 character(s)
// is ignored.
checkIAE(() -> Base64.getDecoder().decode("AA==\u00D2"));
checkIAE(() -> Base64.getUrlDecoder().decode("AA==\u00D2"));
Base64.getMimeDecoder().decode("AA==\u00D2");
}