Reprint please indicate the source: Wang 亟亟 's way of Daniel
Number 5th when the old version of the tool to put out the class, and then this morning added a little content in, and then also a few button run down to see the effect.
Added two classes, a Mobile information class, a data format conversion class.
Phoneutil
Public classPhoneutil {/ * Get phone CPU information * / Public StaticString[]Getcpuinfo() {String str1 ="/proc/cpuinfo"; String str2 =""; String[] CpuInfo = {"",""};//1-CPU model//2-CPU frequencyString[] arrayofstring;Try{FileReader FR =NewFileReader (STR1); BufferedReader Localbufferedreader =NewBufferedReader (FR,8192); STR2 = Localbufferedreader.readline (); arrayofstring = Str2.split ("\\s+"); for(inti =2; i < arrayofstring.length; i++) {cpuinfo[0] = cpuinfo[0] + Arrayofstring[i] +" "; } str2 = Localbufferedreader.readline (); arrayofstring = Str2.split ("\\s+"); cpuinfo[1] + = arrayofstring[2]; Localbufferedreader.close (); }Catch(IOException e) {} log.i ("Phoneutil","Cpuinfo:"+ cpuinfo[0] +" "+ cpuinfo[1]);returnCpuInfo; }/ * Get phone model * / Public StaticStringGetmobilemodel(){returnAndroid.os.Build.MODEL; }/ * Get the SDK version * /@SuppressWarnings ("Deprecation") Public StaticStringgetsdkversion(){returnAndroid.os.Build.VERSION.SDK; }/ * Get the system version * / Public StaticStringGetrelease(){returnAndroid.os.Build.VERSION.RELEASE; }}
Dataconversionutil
Public classDataconversionutil {/*string Turn int*/ Public Static int Stringtoint(Stringvalue){returnInteger.valueof (value). Intvalue (); }/*int Turn string*/ Public StaticStringinttostring(int value){return NewInteger (value). ToString (); }/*string Turn float*/ Public Static float stringtofloat(Stringvalue){returnFloat.valueof (value). Floatvalue (); }/*float Turn string*/ Public StaticStringfloattostring(Stringvalue){return NewFloat (value). ToString (); }/ * String converted to hexadecimal string * / Public StaticStringStringtohex(Stringvalue) {Char[] chars ="0123456789ABCDEF". ToCharArray (); StringBuilder SB =NewStringBuilder ("");byte[] bs =value. GetBytes ();intBit for(inti =0; i < bs.length; i++) {bit = (Bs[i] &0x0f0) >>4; Sb.append (Chars[bit]); bit = Bs[i] &0x0f; Sb.append (Chars[bit]); Sb.append ("'); }returnSb.tostring (). Trim (); }/ * 16 binary conversion String * / Public StaticStringhextostring(Stringvalue) {String str ="0123456789ABCDEF";Char[] Hexs =value. ToCharArray ();byte[] bytes =New byte[value. Length ()/2];intN for(inti =0; i < bytes.length; i++) {n = str.indexof (hexs[2* I]) * -; n + = Str.indexof (hexs[2* i +1]); Bytes[i] = (byte) (N &0xFF); }return NewString (bytes); }/*bytes Convert to hexadecimal string * / Public StaticStringBytetohex(byte[]value) {String stmp=""; StringBuilder SB =NewStringBuilder (""); for(intn=0;n<value. length;n++) {stmp = Integer.tohexstring (value[N] &0xFF); Sb.append ((stmp.length () = =1)?"0"+STMP:STMP); Sb.append (" "); }returnSb.tostring (). toUpperCase (). Trim (); }/*bytes string conversion to byte array * / Public Static byte[]hexstr2bytes(Stringvalue) {intm=0, n=0;intL=value. Length ()/2; System. out. println (l);byte[] ret =New byte[L]; for(inti =0; I < L; i++) {m=i*2+1; n=m+1; Ret[i] = Byte.decode ("0x"+value. substring (i*2, m) +value. substring (m,n)); }returnRet } }
Analysis:
Our usual work in fact, such as (16, 2, etc.) of the format does not care, recently done something is encryption, decryption, lossy compression, lossless compression, conversion between various formats, so think or write a such class more practical.
Tips
Has the audience noticed the Intvalue () method? Do you understand what he's doing?
* Explanation: *valueof (int i) returns an integer instance representing the specified int value, and intvalue () returns the value of the integer as an int type. One returned is an instance object, and one is a value that is slightly different in the method parameter passing. This method is still very few, and then some of the time just feel that the application, looked at the realization.
Source Address: http://yunpan.cn/cdF4jBU8KTSRb access password 06a0
Have a nice weekend!!!!!
Have a problem or business need to contact QQ452270579 Thank you!!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Tool Class update second play, continue to accelerate!