ICallbackHandler.HandleCallbacks(ICallback[]) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Récupérez ou affichez les informations demandées dans les rappels fournis.
[Android.Runtime.Register("handle", "([Ljavax/security/auth/callback/Callback;)V", "GetHandleCallbacks_arrayLjavax_security_auth_callback_Callback_Handler:Javax.Security.Auth.Callback.ICallbackHandlerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public void HandleCallbacks(Javax.Security.Auth.Callback.ICallback[]? callbacks);
[<Android.Runtime.Register("handle", "([Ljavax/security/auth/callback/Callback;)V", "GetHandleCallbacks_arrayLjavax_security_auth_callback_Callback_Handler:Javax.Security.Auth.Callback.ICallbackHandlerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member HandleCallbacks : Javax.Security.Auth.Callback.ICallback[] -> unit
Paramètres
- callbacks
- ICallback[]
tableau d’objets Callback fournis par un service de sécurité sous-jacent qui contient les informations demandées pour être récupérées ou affichées.
- Attributs
Exceptions
si une erreur liée aux E/S se produit
s’il CallbackHandler n’est pas en mesure de gérer un élément spécifique Callback
Remarques
Récupérez ou affichez les informations demandées dans les rappels fournis.
L’implémentation handle de la méthode vérifie la ou les instances de l’objet Callback transmis pour récupérer ou afficher les informations demandées. L’exemple suivant est fourni pour vous aider à illustrer l’apparence d’une implémentation de handle méthode. Cet exemple de code est destiné uniquement aux conseils. De nombreux détails, y compris la gestion appropriée des erreurs, sont laissés pour plus de simplicité.
{@code
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof TextOutputCallback) {
// display the message according to the specified type
TextOutputCallback toc = (TextOutputCallback)callbacks[i];
switch (toc.getMessageType()) {
case TextOutputCallback.INFORMATION:
System.out.println(toc.getMessage());
break;
case TextOutputCallback.ERROR:
System.out.println("ERROR: " + toc.getMessage());
break;
case TextOutputCallback.WARNING:
System.out.println("WARNING: " + toc.getMessage());
break;
default:
throw new IOException("Unsupported message type: " +
toc.getMessageType());
}
} else if (callbacks[i] instanceof NameCallback) {
// prompt the user for a username
NameCallback nc = (NameCallback)callbacks[i];
// ignore the provided defaultName
System.err.print(nc.getPrompt());
System.err.flush();
nc.setName((new BufferedReader
(new InputStreamReader(System.in))).readLine());
} else if (callbacks[i] instanceof PasswordCallback) {
// prompt the user for sensitive information
PasswordCallback pc = (PasswordCallback)callbacks[i];
System.err.print(pc.getPrompt());
System.err.flush();
pc.setPassword(readPassword(System.in));
} else {
throw new UnsupportedCallbackException
(callbacks[i], "Unrecognized Callback");
}
}
}
// Reads user password from given input stream.
private char[] readPassword(InputStream in) throws IOException {
// insert code to read a user password from the input stream
}
}
Les parties de cette page sont des modifications basées sur le travail créé et partagé par Android Open Source et utilisées en fonction des termes décrits dans la Creative Commons 2.5 Attribution License.