La méthode suivante permet de définir le type de transfert d'une connexion FTP. Fondamentalement, je voudrais valider la saisie de caractères (voir les commentaires).Validation des paramètres selon une référence fixe
Est-ce que ça va par-dessus bord? Y a-t-il une approche plus élégante? Comment abordez-vous la validation des paramètres en général? Tous les commentaires sont les bienvenus.
public void setTransferType(Character typeCharacter,
Character optionalSecondCharacter) throws NumberFormatException,
IOException {
// http://www.nsftools.com/tips/RawFTP.htm#TYPE
// Syntax: TYPE type-character [second-type-character]
//
// Sets the type of file to be transferred. type-character can be any
// of:
//
// * A - ASCII text
// * E - EBCDIC text
// * I - image (binary data)
// * L - local format
//
// For A and E, the second-type-character specifies how the text should
// be interpreted. It can be:
//
// * N - Non-print (not destined for printing). This is the default if
// second-type-character is omitted.
// * T - Telnet format control (<CR>, <FF>, etc.)
// * C - ASA Carriage Control
//
// For L, the second-type-character specifies the number of bits per
// byte on the local system, and may not be omitted.
final Set<Character> acceptedTypeCharacters = new HashSet<Character>(Arrays.asList(
new Character[] {'A','E','I','L'}
));
final Set<Character> acceptedOptionalSecondCharacters = new HashSet<Character>(Arrays.asList(
new Character[] {'N','T','C'}
));
if(acceptedTypeCharacters.contains(typeCharacter)) {
if(new Character('A').equals(typeCharacter) || new Character('E').equals(typeCharacter)){
if(acceptedOptionalSecondCharacters.contains(optionalSecondCharacter)) {
executeCommand("TYPE " + typeCharacter + " " + optionalSecondCharacter);
}
} else {
executeCommand("TYPE " + typeCharacter);
}
}
}