📄 base64test.java
字号:
public void testTriplets() {
assertEquals("AAAA",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)0 })));
assertEquals("AAAB",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)1 })));
assertEquals("AAAC",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)2 })));
assertEquals("AAAD",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)3 })));
assertEquals("AAAE",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)4 })));
assertEquals("AAAF",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)5 })));
assertEquals("AAAG",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)6 })));
assertEquals("AAAH",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)7 })));
assertEquals("AAAI",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)8 })));
assertEquals("AAAJ",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)9 })));
assertEquals("AAAK",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)10 })));
assertEquals("AAAL",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)11 })));
assertEquals("AAAM",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)12 })));
assertEquals("AAAN",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)13 })));
assertEquals("AAAO",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)14 })));
assertEquals("AAAP",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)15 })));
assertEquals("AAAQ",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)16 })));
assertEquals("AAAR",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)17 })));
assertEquals("AAAS",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)18 })));
assertEquals("AAAT",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)19 })));
assertEquals("AAAU",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)20 })));
assertEquals("AAAV",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)21 })));
assertEquals("AAAW",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)22 })));
assertEquals("AAAX",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)23 })));
assertEquals("AAAY",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)24 })));
assertEquals("AAAZ",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)25 })));
assertEquals("AAAa",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)26 })));
assertEquals("AAAb",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)27 })));
assertEquals("AAAc",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)28 })));
assertEquals("AAAd",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)29 })));
assertEquals("AAAe",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)30 })));
assertEquals("AAAf",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)31 })));
assertEquals("AAAg",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)32 })));
assertEquals("AAAh",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)33 })));
assertEquals("AAAi",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)34 })));
assertEquals("AAAj",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)35 })));
assertEquals("AAAk",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)36 })));
assertEquals("AAAl",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)37 })));
assertEquals("AAAm",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)38 })));
assertEquals("AAAn",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)39 })));
assertEquals("AAAo",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)40 })));
assertEquals("AAAp",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)41 })));
assertEquals("AAAq",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)42 })));
assertEquals("AAAr",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)43 })));
assertEquals("AAAs",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)44 })));
assertEquals("AAAt",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)45 })));
assertEquals("AAAu",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)46 })));
assertEquals("AAAv",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)47 })));
assertEquals("AAAw",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)48 })));
assertEquals("AAAx",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)49 })));
assertEquals("AAAy",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)50 })));
assertEquals("AAAz",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)51 })));
assertEquals("AAA0",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)52 })));
assertEquals("AAA1",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)53 })));
assertEquals("AAA2",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)54 })));
assertEquals("AAA3",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)55 })));
assertEquals("AAA4",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)56 })));
assertEquals("AAA5",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)57 })));
assertEquals("AAA6",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)58 })));
assertEquals("AAA7",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)59 })));
assertEquals("AAA8",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)60 })));
assertEquals("AAA9",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)61 })));
assertEquals("AAA+",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)62 })));
assertEquals("AAA/",new String(Base64.encodeBase64(new byte[] { (byte)0, (byte)0, (byte)63 })));
}
public void testTripletsChunked() {
assertEquals("AAAA\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)0 })));
assertEquals("AAAB\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)1 })));
assertEquals("AAAC\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)2 })));
assertEquals("AAAD\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)3 })));
assertEquals("AAAE\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)4 })));
assertEquals("AAAF\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)5 })));
assertEquals("AAAG\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)6 })));
assertEquals("AAAH\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)7 })));
assertEquals("AAAI\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)8 })));
assertEquals("AAAJ\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)9 })));
assertEquals("AAAK\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)10 })));
assertEquals("AAAL\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)11 })));
assertEquals("AAAM\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)12 })));
assertEquals("AAAN\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)13 })));
assertEquals("AAAO\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)14 })));
assertEquals("AAAP\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)15 })));
assertEquals("AAAQ\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)16 })));
assertEquals("AAAR\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)17 })));
assertEquals("AAAS\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)18 })));
assertEquals("AAAT\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)19 })));
assertEquals("AAAU\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)20 })));
assertEquals("AAAV\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)21 })));
assertEquals("AAAW\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)22 })));
assertEquals("AAAX\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)23 })));
assertEquals("AAAY\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)24 })));
assertEquals("AAAZ\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)25 })));
assertEquals("AAAa\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)26 })));
assertEquals("AAAb\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)27 })));
assertEquals("AAAc\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)28 })));
assertEquals("AAAd\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)29 })));
assertEquals("AAAe\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)30 })));
assertEquals("AAAf\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)31 })));
assertEquals("AAAg\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)32 })));
assertEquals("AAAh\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)33 })));
assertEquals("AAAi\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)34 })));
assertEquals("AAAj\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)35 })));
assertEquals("AAAk\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)36 })));
assertEquals("AAAl\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)37 })));
assertEquals("AAAm\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)38 })));
assertEquals("AAAn\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)39 })));
assertEquals("AAAo\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)40 })));
assertEquals("AAAp\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)41 })));
assertEquals("AAAq\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)42 })));
assertEquals("AAAr\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)43 })));
assertEquals("AAAs\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)44 })));
assertEquals("AAAt\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)45 })));
assertEquals("AAAu\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)46 })));
assertEquals("AAAv\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)47 })));
assertEquals("AAAw\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)48 })));
assertEquals("AAAx\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)49 })));
assertEquals("AAAy\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)50 })));
assertEquals("AAAz\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)51 })));
assertEquals("AAA0\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)52 })));
assertEquals("AAA1\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)53 })));
assertEquals("AAA2\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)54 })));
assertEquals("AAA3\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)55 })));
assertEquals("AAA4\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)56 })));
assertEquals("AAA5\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)57 })));
assertEquals("AAA6\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)58 })));
assertEquals("AAA7\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)59 })));
assertEquals("AAA8\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)60 })));
assertEquals("AAA9\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)61 })));
assertEquals("AAA+\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)62 })));
assertEquals("AAA/\r\n",new String(Base64.encodeBase64Chunked(new byte[] { (byte)0, (byte)0, (byte)63 })));
}
public void testKnownEncodings() {
assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==",new String(Base64.encodeBase64("The quick brown fox jumped over the lazy dogs.".getBytes())));
assertEquals("YmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJs\r\nYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFo\r\nIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBi\r\nbGFoIGJsYWg=\r\n",new String(Base64.encodeBase64Chunked("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah".getBytes())));
assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==",new String(Base64.encodeBase64("It was the best of times, it was the worst of times.".getBytes())));
assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==",new String(Base64.encodeBase64("http://jakarta.apache.org/commmons".getBytes())));
assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==",new String(Base64.encodeBase64("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes())));
assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=",new String(Base64.encodeBase64("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }".getBytes())));
assertEquals("eHl6enkh",new String(Base64.encodeBase64("xyzzy!".getBytes())));
}
public void testKnownDecodings() {
assertEquals("The quick brown fox jumped over the lazy dogs.",new String(Base64.decodeBase64("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
assertEquals("It was the best of times, it was the worst of times.",new String(Base64.decodeBase64("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes())));
assertEquals("http://jakarta.apache.org/commmons",new String(Base64.decodeBase64("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes())));
assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",new String(Base64.decodeBase64("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes())));
assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }",new String(Base64.decodeBase64("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=".getBytes())));
assertEquals("xyzzy!",new String(Base64.decodeBase64("eHl6enkh".getBytes())));
}
public void testNonBase64Test() throws Exception {
byte[] bArray = { '%' };
assertFalse( "Invalid Base64 array was incorrectly validated as " +
"an array of Base64 encoded data",
Base64.isArrayByteBase64( bArray ) );
boolean exceptionThrown = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -