.. java:import:: java.io ByteArrayInputStream .. java:import:: java.io InputStream .. java:import:: java.io UnsupportedEncodingException .. java:import:: java.security MessageDigest .. java:import:: java.security NoSuchAlgorithmException .. java:import:: java.security SecureRandom .. java:import:: java.text DecimalFormat .. java:import:: java.util Scanner .. java:import:: java.util.regex Pattern .. java:import:: org.apache.commons.codec.binary Base32 .. java:import:: org.caosdb.server CaosDBServer .. java:import:: org.caosdb.server ServerProperties .. java:import:: org.caosdb.server.entity Message .. java:import:: org.jdom2 Document .. java:import:: org.jdom2 Element .. java:import:: org.jdom2.output Format .. java:import:: org.jdom2.output XMLOutputter Utils ===== .. java:package:: org.caosdb.server.utils :noindex: .. java:type:: public class Utils Utility functions. Fields ------ EMAIL_PATTERN ^^^^^^^^^^^^^ .. java:field:: public static final Pattern EMAIL_PATTERN :outertype: Utils Regular expression pattern that checks a mail for RFC822 compliance. Taken from: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html This belongs to the perl module "Mail::RFC822::Address". It is copyright 2001-2002 by Paul Warren. The license can be found here: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address/Mail-RFC822-Address.html#copyright%20and%20license Methods ------- InputStream2String ^^^^^^^^^^^^^^^^^^ .. java:method:: public static String InputStream2String(InputStream is) :outertype: Utils Helper function calling InputStream2String for charset UTF-8. InputStream2String ^^^^^^^^^^^^^^^^^^ .. java:method:: public static String InputStream2String(InputStream is, String charset) :outertype: Utils Return a string from the input stream is up to the next LF (line feed, \\A) character. :param is: The input stream :return: The detected string or an empty string if the stream has become empty. String2InputStream ^^^^^^^^^^^^^^^^^^ .. java:method:: public static InputStream String2InputStream(String s) throws UnsupportedEncodingException :outertype: Utils Helper function to convert a String into an UTF-8 encoded ByteArrayInputStream. URLDecodeWithUTF8 ^^^^^^^^^^^^^^^^^ .. java:method:: public static String URLDecodeWithUTF8(String string) :outertype: Utils Exception-free decoding of URI-encoded Strings with UTF-8. Any UnsupportedEncodingException will terminate the server since this would by no means be an acceptable run-time environment if UTF-8 is not available. :param string: :return: decoded string. **See also:** :java:ref:`{@linkUtils.URLEncodeWithUTF8(String)}` URLEncodeWithUTF8 ^^^^^^^^^^^^^^^^^ .. java:method:: public static String URLEncodeWithUTF8(String string) :outertype: Utils Exception-free URI-encoding of strings using UTF-8. Any UnsupportedEncodingException will terminate the server since this would by no means be an acceptable run-time environment if UTF-8 is not available. :param string: :return: encoded string. **See also:** :java:ref:`{@linkUtils.URLDecodeWithUTF8(String)}` checkPasswordStrength ^^^^^^^^^^^^^^^^^^^^^ .. java:method:: public static void checkPasswordStrength(String password) throws Message :outertype: Utils Determines the strength of a password. Currently this just throws an error when the String `password` does not at least contain - An uppercase char - A lowercase char - A number - A punctuation char and if the length is not at least 8 characters. correcthorsebatterystaple is also rejected. :param password: The password to be checked. document2String ^^^^^^^^^^^^^^^ .. java:method:: public static String document2String(Document document) :outertype: Utils Converts a Document into a String. For debugging purposes. :param document: :return: String representation of the document. element2String ^^^^^^^^^^^^^^ .. java:method:: public static String element2String(Element e) :outertype: Utils Converts an Element into a String. For debugging purposes. :param e: The Element :return: String representation of the element. getReadableByteSize ^^^^^^^^^^^^^^^^^^^ .. java:method:: public static String getReadableByteSize(Long fssize) :outertype: Utils Converts file sizes to human readably sizes. For example, getReadableByteSize(2048) == "2KiB". getSecureFilename ^^^^^^^^^^^^^^^^^ .. java:method:: public static String getSecureFilename(int byteSize) :outertype: Utils Generate a secure filename (base32 letters and numbers). Very similar to getUID, but uses cryptographic random number instead, also nicely formats the resulting string. :param byteSize: How many bytes of random bits shall be generated. :return: The filename as a String. getUID ^^^^^^ .. java:method:: public static String getUID() :outertype: Utils Generate a UID (Hexadecimal). Currently this generates two random long numbers and concatenates their hex representations. This function is thread-safe. :return: The UID as a String. hash ^^^^ .. java:method:: public static String hash(MessageDigest md, String string, String salt, int it) :outertype: Utils :param alg: The hashing algorithm implementation. :param string: The string to be hashed. :param salt: Cryptographic salt. :param it: Number of iterations. Zero and negative integers don't make any sense. Therefore, if it<=1 the hashing is done once. :return: Hashed string, or null if string is null isRFC822Compliant ^^^^^^^^^^^^^^^^^ .. java:method:: public static boolean isRFC822Compliant(String email) :outertype: Utils Check if email is RFC822 compliant. :param email: :return: true when the email given by the String email is RFC822 compliant. log ^^^ .. java:method:: public static double log(int base, Long x) :outertype: Utils Intended to compute the maximum exponent for the required conversion. sha512 ^^^^^^ .. java:method:: public static String sha512(String string, String salt, int it) :outertype: Utils This function returns the SHA512 hash of a given string, salt and number of iterations. This function terminates the application completely with an error code when this hashing algorithm is not available. :param string: The string to be hashed. :param salt: Cryptographic salt. :param it: Number of iterations. Zero and negative integers don't make any sense. Therefore, if it<=1 the hashing is done once. :return: Hashed string, or null if string is null