Package kz.greetgo.util
Class ServerUtil
- java.lang.Object
-
- kz.greetgo.util.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 voidappendToSB(java.io.InputStream in, java.lang.StringBuilder sb)Read stream encoded as UTF-8 and add to the resulting stringsbstatic java.lang.StringbytesToHex(byte[] bytes)Converts an array of bytes into their hexadecimal representationstatic java.io.OutputStreamcopyStreamsAndCloseIn(java.io.InputStream in, java.io.OutputStream out)Copies one stream into another, and after copy closes input stream.static voiddeleteRecursively(java.io.File file)Deletes a file or folder with all its contentsstatic voiddeleteRecursively(java.lang.String fileFullName)Deletes a file or folder with all its contentsstatic voiddummyCheck(boolean tmp)The check which does not perform anythingstatic java.lang.StringextractName(java.lang.String className)Extracts class name from the full name of the classstatic java.lang.StringextractPackage(java.lang.String className)Extract the package name from the full name of the classstatic java.lang.StringfirstUpper(java.lang.String str)Raise the first letter in upper casestatic <T> Tfnn(T... tt)Return the first element that is not equal tonullstatic <T extends java.lang.annotation.Annotation>
TgetAnnotation(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 arestatic <T> TjavaDeserialize(byte[] bytes)Performs java-serialization of the object and returns the resulting objectstatic byte[]javaSerialize(java.lang.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 java.lang.StringreadFile(java.io.File file)Reads file to string as UTF-8 textstatic java.io.FileresolveFile(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 readstatic java.lang.StringstreamToStr(java.io.InputStream in)Reads and closes the stream, and converts the read information into a string, assuming that it represented in coding UTF-8static java.lang.Stringtrim(java.lang.String str)Trims the string on both sides, i.static java.lang.StringtrimLeft(java.lang.String str)Trims the srting on the left, i.static java.lang.StringtrimRight(java.lang.String str)Trims the srting on the right, i.
-
-
-
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 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
public static void appendToSB(java.io.InputStream in, java.lang.StringBuilder sb)Read stream encoded as UTF-8 and add to the resulting stringsb- Parameters:
in- readable streamsb- 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 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
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 areclassName- full name of the classextension- extension (ifnull,.javais 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. Atnullthere are no errors -nullis 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. Atnullthere are no errors -nullis 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. Atnullthere are no errors -nullis 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 methodannotation- class of required annotation- Returns:
- the value of required annotation, or
nullif 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 ornull- Returns:
- hexadecimal representation of the bytes in the array, or an empty string, if
transmitted
nullinstead of array of bytes
-
-