Code example for AuthenticationException

0
 
	private static void authenticate(HttpRequest request, Context context)
			throws AuthenticationException { 
		TVEyePreferences preferences = new TVEyePreferences(context);
		if (!preferences.hasCredentials())
			throw new AuthenticationException(CREDENTIALS_MISSING);
		else { 
			UsernamePasswordCredentials credentials = preferences
					.getCredentials(); 
			request.addHeader(new BasicSchemeFactory().newInstance(
					request.getParams()).authenticate(credentials, request));
		} 
	} 
 
	private static byte[] consumeStream(InputStream input) throws IOException {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		byte[] buffer = new byte[2048];
		int read;
		while ((read = input.read(buffer)) > -1) {
			output.write(buffer, 0, read);
		}