@Test public void mapped() throws Exception { String input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; byte [] expectedBytes = { (byte) 0, (byte) 16, (byte) 131, (byte) 16, (byte) 81, (byte) 135, (byte) 32, (byte) 146, (byte) 139, (byte) 48, (byte) 211, (byte) 143, (byte) 65, (byte) 20, (byte) 147, (byte) 81, (byte) 85, (byte) 151, (byte) 97, (byte) 150, (byte) 155, (byte) 113, (byte) 215, (byte) 159, (byte) 130, (byte) 24, (byte) 163, (byte) 146, (byte) 89, (byte) 167, (byte) 162, (byte) 154, (byte) 171, (byte) 178, (byte) 219, (byte) 175, (byte) 195, (byte) 28, (byte) 179, (byte) 211, (byte) 93, (byte) 183, (byte) 227, (byte) 158, (byte) 187, (byte) 243, (byte) 223, (byte) 191}; ByteBuffer expected = ByteBuffer.wrap(expectedBytes); ByteBuffer out = Base64Util.decode(input); assertEquals(out, expected); }
private static int mapped(int ch) { if ((ch & 0x40) != 0) { if ((ch & 0x20) != 0) { assert ch >= 'a'; assert ch <= 'z'; return ch - 71; } else { assert ch >= 'A'; assert ch <= 'Z'; return ch - 65; } } else if ((ch & 0x20) != 0) { if ((ch & 0x10) != 0) { if ((ch & 0x08) != 0 && (ch & 0x04) != 0) { assert ch == '='; return 0; } else { assert ch >= '0'; assert ch <= '9'; return ch + 4; } } else { if ((ch & 0x04) != 0) { assert ch == '/'; return 63; } else { assert ch == '+'; return 62; } } } else { LOG.warning("Invalid BASE64 string"); throw new IllegalArgumentException("Invalid BASE64 string"); } }
Base64Util { private static int mapped(int ch) { if ((ch & 0x40) != 0) { if ((ch & 0x20) != 0) { assert ch >= 'a'; assert ch <= 'z'; return ch - 71; } else { assert ch >= 'A'; assert ch <= 'Z'; return ch - 65; } } else if ((ch & 0x20) != 0) { if ((ch & 0x10) != 0) { if ((ch & 0x08) != 0 && (ch & 0x04) != 0) { assert ch == '='; return 0; } else { assert ch >= '0'; assert ch <= '9'; return ch + 4; } } else { if ((ch & 0x04) != 0) { assert ch == '/'; return 63; } else { assert ch == '+'; return 62; } } } else { LOG.warning("Invalid BASE64 string"); throw new IllegalArgumentException("Invalid BASE64 string"); } } }
Base64Util { private static int mapped(int ch) { if ((ch & 0x40) != 0) { if ((ch & 0x20) != 0) { assert ch >= 'a'; assert ch <= 'z'; return ch - 71; } else { assert ch >= 'A'; assert ch <= 'Z'; return ch - 65; } } else if ((ch & 0x20) != 0) { if ((ch & 0x10) != 0) { if ((ch & 0x08) != 0 && (ch & 0x04) != 0) { assert ch == '='; return 0; } else { assert ch >= '0'; assert ch <= '9'; return ch + 4; } } else { if ((ch & 0x04) != 0) { assert ch == '/'; return 63; } else { assert ch == '+'; return 62; } } } else { LOG.warning("Invalid BASE64 string"); throw new IllegalArgumentException("Invalid BASE64 string"); } } @Deprecated private  Base64Util(); }
Base64Util { private static int mapped(int ch) { if ((ch & 0x40) != 0) { if ((ch & 0x20) != 0) { assert ch >= 'a'; assert ch <= 'z'; return ch - 71; } else { assert ch >= 'A'; assert ch <= 'Z'; return ch - 65; } } else if ((ch & 0x20) != 0) { if ((ch & 0x10) != 0) { if ((ch & 0x08) != 0 && (ch & 0x04) != 0) { assert ch == '='; return 0; } else { assert ch >= '0'; assert ch <= '9'; return ch + 4; } } else { if ((ch & 0x04) != 0) { assert ch == '/'; return 63; } else { assert ch == '+'; return 62; } } } else { LOG.warning("Invalid BASE64 string"); throw new IllegalArgumentException("Invalid BASE64 string"); } } @Deprecated private  Base64Util(); static String encode(ByteBuffer decoded); static ByteBuffer decode(String encoded); }
Base64Util { private static int mapped(int ch) { if ((ch & 0x40) != 0) { if ((ch & 0x20) != 0) { assert ch >= 'a'; assert ch <= 'z'; return ch - 71; } else { assert ch >= 'A'; assert ch <= 'Z'; return ch - 65; } } else if ((ch & 0x20) != 0) { if ((ch & 0x10) != 0) { if ((ch & 0x08) != 0 && (ch & 0x04) != 0) { assert ch == '='; return 0; } else { assert ch >= '0'; assert ch <= '9'; return ch + 4; } } else { if ((ch & 0x04) != 0) { assert ch == '/'; return 63; } else { assert ch == '+'; return 62; } } } else { LOG.warning("Invalid BASE64 string"); throw new IllegalArgumentException("Invalid BASE64 string"); } } @Deprecated private  Base64Util(); static String encode(ByteBuffer decoded); static ByteBuffer decode(String encoded);  }