Class ServerUtil

java.lang.Object
kz.greetgo.util.ServerUtil

public class ServerUtil extends Object
  • Constructor Details

    • ServerUtil

      public ServerUtil()
  • Method Details

    • firstUpper

      public static String firstUpper(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(InputStream in, 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(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 String streamToStr(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 String readFile(File file)
      Reads file to string as UTF-8 text
      Parameters:
      file - reading file
      Returns:
      read text from file
    • copyStreamsAndCloseIn

      public static OutputStream copyStreamsAndCloseIn(InputStream in, 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 String extractPackage(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 File resolveFile(String srcDir, String className, 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 String extractName(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(File file)
      Deletes a file or folder with all its contents
      Parameters:
      file - deletable file or folder
    • deleteRecursively

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

      public static byte[] javaSerialize(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 String trim(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 String trimLeft(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 String trimRight(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 Annotation> T getAnnotation(Method method, 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 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