protected void applyHttpBasicAuthentication(URLConnection connection,
String username, String password) {
String combined = username + ":" + password;
try {
ByteArrayOutputStream baout = new ByteArrayOutputStream(combined.length() * 2);
Base64EncodeStream base64 = new Base64EncodeStream(baout);
base64.write(combined.getBytes());
base64.close();
connection.setRequestProperty("Authorization",
"Basic " + new String(baout.toByteArray()));
} catch (IOException e) {
//won't happen. We're operating in-memory.
throw new RuntimeException("Error during base64 encodation of username/password");