LdapEncoder { public static String printBase64Binary(byte[] val) { Assert.notNull(val, "val must not be null!"); String encoded = DatatypeConverter.printBase64Binary(val); int length = encoded.length(); StringBuilder sb = new StringBuilder(length + length / RFC2849_MAX_BASE64_CHARS_PER_LINE); for (int i = 0, len = length; i < len; i++) { sb.append(encoded.charAt(i)); if ((i + 1) % RFC2849_MAX_BASE64_CHARS_PER_LINE == 0) { sb.append('\n'); sb.append(' '); } } return sb.toString(); } private  LdapEncoder(); static String filterEncode(String value); static String nameEncode(String value); static String nameDecode(String value); static String printBase64Binary(byte[] val); static byte[] parseBase64Binary(String val);  }
@Test public void printBase64WhenReallyLongThenNewLineStartsWithSpace() throws Exception { String toBase64Encode = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; String expected = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\n NTY3ODk="; String actual = LdapEncoder.printBase64Binary(toBase64Encode.getBytes("UTF-8")); assertThat(actual).isEqualTo(expected); }