Package kz.greetgo.util
Class ServerUtil
java.lang.Object
kz.greetgo.util.ServerUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendToSB(InputStream in, StringBuilder sb) Read stream encoded as UTF-8 and add to the resulting stringsbstatic StringbytesToHex(byte[] bytes) Converts an array of bytes into their hexadecimal representationstatic OutputStreamcopyStreamsAndCloseIn(InputStream in, OutputStream out) Copies one stream into another, and after copy closes input stream.static voiddeleteRecursively(File file) Deletes a file or folder with all its contentsstatic voiddeleteRecursively(String fileFullName) Deletes a file or folder with all its contentsstatic voiddummyCheck(boolean tmp) The check which does not perform anythingstatic StringextractName(String className) Extracts class name from the full name of the classstatic StringextractPackage(String className) Extract the package name from the full name of the classstatic StringfirstUpper(String str) Raise the first letter in upper casestatic <T> Tfnn(T... tt) Return the first element that is not equal tonullstatic <T extends Annotation>
TgetAnnotation(Method method, Class<T> annotation) Returns the annotation of the method checking the presence of this annotation at all inherited methods if they arestatic <T> TjavaDeserialize(byte[] bytes) Performs java-serialization of the object and returns the resulting objectstatic byte[]javaSerialize(Object object) Performs java-serialization of the object and returns the data resulting after serializationstatic voidjustOne(int value) Check the argument for equality to one.static <T> TnotNull(T t) Checks that the element was not null, otherwise generates NullPointerExceptionstatic StringReads file to string as UTF-8 textstatic FileresolveFile(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.static byte[]Reads a stream to the end to bytes array, closes a stream, and returns that was readstatic StringReads and closes the stream, and converts the read information into a string, assuming that it represented in coding UTF-8static StringTrims the string on both sides, i.static StringTrims the srting on the left, i.static StringTrims the srting on the right, i.
-
Constructor Details
-
ServerUtil
public ServerUtil()
-
-
Method Details
-
firstUpper
Raise the first letter in upper case- Parameters:
str- source line- Returns:
- string with a capital first letter
-
fnn
Return the first element that is not equal tonull- 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
Read stream encoded as UTF-8 and add to the resulting stringsb- Parameters:
in- readable streamsb- dedication to add a string
-
streamToByteArray
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
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
Reads file to string as UTF-8 text- Parameters:
file- reading file- Returns:
- read text from file
-
copyStreamsAndCloseIn
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 readingout- 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
Extract the package name from the full name of the class- Parameters:
className- full name of the class- Returns:
- package name
-
resolveFile
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 areclassName- full name of the classextension- extension (ifnull,.javais used)- Returns:
- formed file
-
extractName
Extracts class name from the full name of the class- Parameters:
className- full name of the class- Returns:
- class name without the package
-
deleteRecursively
Deletes a file or folder with all its contents- Parameters:
file- deletable file or folder
-
deleteRecursively
Deletes a file or folder with all its contents- Parameters:
fileFullName- path to the file or folder
-
javaSerialize
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
Trims the string on both sides, i. e. deletes whitespace at the beginning and end of the string and returns the result. Atnullthere are no errors -nullis returned- Parameters:
str- string to trim- Returns:
- string after trimming
-
trimLeft
Trims the srting on the left, i. e. deletes whitespace at the beginning of the string. Atnullthere are no errors -nullis returned- Parameters:
str- string to trim- Returns:
- string after trimming
-
trimRight
Trims the srting on the right, i. e. deletes whitespace at the end of the string. Atnullthere are no errors -nullis returned- Parameters:
str- string to trim- Returns:
- string after trimming
-
getAnnotation
Returns the annotation of the method checking the presence of this annotation at all inherited methods if they are- Parameters:
method- source methodannotation- class of required annotation- Returns:
- the value of required annotation, or
nullif such annotation is not found
-
bytesToHex
Converts an array of bytes into their hexadecimal representation- Parameters:
bytes- source array of bytes ornull- Returns:
- hexadecimal representation of the bytes in the array, or an empty string, if
transmitted
nullinstead of array of bytes
-