forked from LiangYuen/Pi4j-RC522
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert.java
75 lines (72 loc) · 1.6 KB
/
Convert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.liangyuen.util;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
public class Convert
{
public static Object String2Object(String strValue,int type)
{
Object value=null;
switch(type)
{
case Types.INTEGER:
value=Integer.parseInt(strValue);
break;
case Types.VARCHAR:
case Types.CHAR:
case Types.NVARCHAR:
value=strValue;
break;
case Types.DOUBLE:
value=Double.parseDouble(strValue);
break;
case Types.FLOAT:
value=Float.parseFloat(strValue);
break;
case Types.BOOLEAN:
value=Boolean.parseBoolean(strValue);
break;
case Types.DATE:
value=Date.valueOf(strValue);
break;
case Types.DECIMAL:
case Types.NUMERIC:
value=new BigDecimal(strValue);
break;
case Types.BIGINT:
value=new BigInteger(strValue);
break;
case Types.TIMESTAMP:
value=Timestamp.valueOf(strValue);
break;
case Types.TIME:
value=Time.valueOf(strValue);
break;
case Types.SMALLINT:
value=Integer.parseInt(strValue);
break;
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
value=strValue;
break;
}
return value;
}
public static String bytesToHex(byte[] bytes)
{
final char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++)
{
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
}