String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg==";
// create a Base64OutputStream
StringWriter strwriter = new StringWriter();
BufferedWriter buffwriter = new BufferedWriter(strwriter);
Base64OutputStream b64_out = new Base64OutputStream(buffwriter);
byte[] b = str.getBytes();
// write the bytes in different lengths to test whether leftover
// data is persisted across calls to write
b64_out.write(b, 0, 33);
b64_out.write(b, 33, 1);
b64_out.write(b, 34, 1);
b64_out.write(b, 35, 2);
b64_out.write(b, 37, 3);
b64_out.write(b, 40, 3);
b64_out.write(b, 43, 3);
b64_out.write(b, 46, 5);
b64_out.write(b, 51, 4);
b64_out.write(b, 55, 5);
b64_out.write(b, 60, 6);
b64_out.write(b, 66, 10);
b64_out.write(b, 76, 51);
b64_out.write(b, 127, 150);
b64_out.write(b, 277, 22);
b64_out.write(b, 299, 21);
b64_out.write(b, 320, 2);
// remember to add padding characters (if necessary)
b64_out.close();
// compare the contents of the outputstream with the expected encoded string
assertEquals(strwriter.toString(), str_encoded);
}