Class ServerUtil


  • public class ServerUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ServerUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendToSB​(java.io.InputStream in, java.lang.StringBuilder sb)
      Read stream encoded as UTF-8 and add to the resulting string sb
      static java.lang.String bytesToHex​(byte[] bytes)
      Converts an array of bytes into their hexadecimal representation
      static java.io.OutputStream copyStreamsAndCloseIn​(java.io.InputStream in, java.io.OutputStream out)
      Copies one stream into another, and after copy closes input stream.
      static void deleteRecursively​(java.io.File file)
      Deletes a file or folder with all its contents
      static void deleteRecursively​(java.lang.String fileFullName)
      Deletes a file or folder with all its contents
      static void dummyCheck​(boolean tmp)
      The check which does not perform anything
      static java.lang.String extractName​(java.lang.String className)
      Extracts class name from the full name of the class
      static java.lang.String extractPackage​(java.lang.String className)
      Extract the package name from the full name of the class
      static java.lang.String firstUpper​(java.lang.String str)
      Raise the first letter in upper case
      static <T> T fnn​(T... tt)
      Return the first element that is not equal to null
      static <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.reflect.Method method, java.lang.Class<T> annotation)
      Returns the annotation of the method checking the presence of this annotation at all inherited methods if they are
      static <T> T javaDeserialize​(byte[] bytes)
      Performs java-serialization of the object and returns the resulting object
      static byte[] javaSerialize​(java.lang.Object object)
      Performs java-serialization of the object and returns the data resulting after serialization
      static void justOne​(int value)
      Check the argument for equality to one.
      static <T> T notNull​(T t)
      Checks that the element was not null, otherwise generates NullPointerException
      static java.lang.String readFile​(java.io.File file)
      Reads file to string as UTF-8 text
      static java.io.File resolveFile​(java.lang.String srcDir, java.lang.String className, java.lang.String extension)
      Forms the source file (but does not create it) for a specified source-folder and with name of the class.
      static byte[] streamToByteArray​(java.io.InputStream in)
      Reads a stream to the end to bytes array, closes a stream, and returns that was read
      static java.lang.String streamToStr​(java.io.InputStream in)
      Reads and closes the stream, and converts the read information into a string, assuming that it represented in coding UTF-8
      static java.lang.String trim​(java.lang.String str)
      Trims the string on both sides, i.
      static java.lang.String trimLeft​(java.lang.String str)
      Trims the srting on the left, i.
      static java.lang.String trimRight​(java.lang.String str)
      Trims the srting on the right, i.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ServerUtil

        public ServerUtil()
    • Method Detail

      • firstUpper

        public static java.lang.String firstUpper​(java.lang.String str)
        Raise the first letter in upper case
        Parameters:
        str - source line
        Returns:
        string with a capital first letter
      • fnn

        @SafeVarargs
        public static <T> T fnn​(T... tt)
        Return the first element that is not equal to null
        Parameters:
        tt - element list
        Returns:
        the first not-null-element
      • dummyCheck

        public static void dummyCheck​(boolean tmp)
        The check which does not perform anything
      • notNull

        public static <T> T notNull​(T t)
        Checks that the element was not null, otherwise generates NullPointerException
        Parameters:
        t - coverage element
        Returns:
        coverage element, that exactly is not null
      • appendToSB

        public static void appendToSB​(java.io.InputStream in,
                                      java.lang.StringBuilder sb)
        Read stream encoded as UTF-8 and add to the resulting string sb
        Parameters:
        in - readable stream
        sb - dedication to add a string
      • streamToByteArray

        public static byte[] streamToByteArray​(java.io.InputStream in)
        Reads a stream to the end to bytes array, closes a stream, and returns that was read
        Parameters:
        in - readable stream
        Returns:
        the array of read bytes
      • streamToStr

        public static java.lang.String streamToStr​(java.io.InputStream in)
        Reads and closes the stream, and converts the read information into a string, assuming that it represented in coding UTF-8
        Parameters:
        in - readable stream
        Returns:
        resulting string
      • readFile

        public static java.lang.String readFile​(java.io.File file)
        Reads file to string as UTF-8 text
        Parameters:
        file - reading file
        Returns:
        read text from file
      • copyStreamsAndCloseIn

        public static java.io.OutputStream copyStreamsAndCloseIn​(java.io.InputStream in,
                                                                 java.io.OutputStream out)
        Copies one stream into another, and after copy closes input stream. Copy buffer size is equal to 4 Kb
        Parameters:
        in - readable stream, which is closed after reading
        out - output stream
        Returns:
        output stream
      • justOne

        public static void justOne​(int value)
        Check the argument for equality to one. If the check is failed - generates exception
        Parameters:
        value - argument checking for one
      • extractPackage

        public static java.lang.String extractPackage​(java.lang.String className)
        Extract the package name from the full name of the class
        Parameters:
        className - full name of the class
        Returns:
        package name
      • resolveFile

        public static java.io.File resolveFile​(java.lang.String srcDir,
                                               java.lang.String className,
                                               java.lang.String extension)
        Forms the source file (but does not create it) for a specified source-folder and with name of the class. Also the extension can be specified. By default, the extension is .java
        Parameters:
        srcDir - the directory where the source codes are
        className - full name of the class
        extension - extension (if null, .java is used)
        Returns:
        formed file
      • extractName

        public static java.lang.String extractName​(java.lang.String className)
        Extracts class name from the full name of the class
        Parameters:
        className - full name of the class
        Returns:
        class name without the package
      • deleteRecursively

        public static void deleteRecursively​(java.io.File file)
        Deletes a file or folder with all its contents
        Parameters:
        file - deletable file or folder
      • deleteRecursively

        public static void deleteRecursively​(java.lang.String fileFullName)
        Deletes a file or folder with all its contents
        Parameters:
        fileFullName - path to the file or folder
      • javaSerialize

        public static byte[] javaSerialize​(java.lang.Object object)
        Performs java-serialization of the object and returns the data resulting after serialization
        Parameters:
        object - serializable object
        Returns:
        serializable data
      • javaDeserialize

        public static <T> T javaDeserialize​(byte[] bytes)
        Performs java-serialization of the object and returns the resulting object
        Parameters:
        bytes - previously serialized data
        Returns:
        object after deserialize
      • trim

        public static java.lang.String trim​(java.lang.String str)
        Trims the string on both sides, i. e. deletes whitespace at the beginning and end of the string and returns the result. At null there are no errors - null is returned
        Parameters:
        str - string to trim
        Returns:
        string after trimming
      • trimLeft

        public static java.lang.String trimLeft​(java.lang.String str)
        Trims the srting on the left, i. e. deletes whitespace at the beginning of the string. At null there are no errors - null is returned
        Parameters:
        str - string to trim
        Returns:
        string after trimming
      • trimRight

        public static java.lang.String trimRight​(java.lang.String str)
        Trims the srting on the right, i. e. deletes whitespace at the end of the string. At null there are no errors - null is returned
        Parameters:
        str - string to trim
        Returns:
        string after trimming
      • getAnnotation

        public static <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.reflect.Method method,
                                                                                  java.lang.Class<T> annotation)
        Returns the annotation of the method checking the presence of this annotation at all inherited methods if they are
        Parameters:
        method - source method
        annotation - class of required annotation
        Returns:
        the value of required annotation, or null if such annotation is not found
      • bytesToHex

        public static java.lang.String bytesToHex​(byte[] bytes)
        Converts an array of bytes into their hexadecimal representation
        Parameters:
        bytes - source array of bytes or null
        Returns:
        hexadecimal representation of the bytes in the array, or an empty string, if transmitted null instead of array of bytes