/** * Checks if the length of string is less or equal than the provided * maximum. * * @param string the string to check * @param max the maximal length of the string * @exception WrongLengthOfStringException thrown if the string is longer * than the provided max length */ protected static void checkString(String string, int max) throws WrongLengthOfStringException { checkString(string, 0, max); }
/** * Checks if the length of the data of the string is less or equal than * the provided maximum; necessery for multibyte encodings. * Note that the length checked is the length wfter transforming * the string to series of octets, so two-byte strings will efectively * require space (max size) two-times the length of the string. * @param string the string to check * @param max the maximal length of the string * @param encoding the encoding of the string * @exception WrongLengthOfStringException thrown if the string is longer * than the provided max length * @exception UnsupportedEncodingException the required encoding isn't * supported */ protected static void checkString(String string, int max, String encoding) throws WrongLengthOfStringException, UnsupportedEncodingException { checkString(string, 0, max, encoding); }
/** * Checks if the length of string is greater or equal than provided * minimum and less or equal than the provided maximum. * * @param string the string to check * @param min the minimal length of the string * @param max the maximal length of the string * @throws WrongLengthOfStringException thrown if the string is shorter * than min length or longer than max length */ protected static void checkString(String string, int min, int max) throws WrongLengthOfStringException { int length = string == null ? 0 : string.length(); checkString(min, length, max); }
/** * Checks if the length of the data of the string is greater or equal * than provided minimum and less or equal than the provided maximum; * necessery for multibyte encodings. * * @param string the string to check * @param min the minimal length of the string * @param max the maximal length of the string * @param encoding the encoding of the string * @throws WrongLengthOfStringException thrown if the string is shorter * than min length or longer than max length * @exception UnsupportedEncodingException the required encoding isn't * supported */ protected static void checkString(String string, int min, int max, String encoding) throws WrongLengthOfStringException, UnsupportedEncodingException { byte[] stringBytes = string.getBytes(encoding); int length = stringBytes == null ? 0 : stringBytes.length; checkString(min, length, max); }