Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
common
Commits
ce55671f
Commit
ce55671f
authored
Apr 26, 2020
by
张永
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.linkfern.com/key/common.git
parents
6f644eb1
2a73609a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1194 additions
and
1158 deletions
+1194
-1158
pom.xml
pom.xml
+125
-120
FileUtil.java
src/main/java/com/egolm/common/FileUtil.java
+8
-28
FtpUtil.java
src/main/java/com/egolm/common/FtpUtil.java
+206
-206
HttpUtil.java
src/main/java/com/egolm/common/HttpUtil.java
+5
-4
StringUtil.java
src/main/java/com/egolm/common/StringUtil.java
+2
-1
JdbcTemplate.java
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
+682
-633
ReverseUtil.java
src/main/java/com/egolm/common/jdbc/dialect/ReverseUtil.java
+166
-166
No files found.
pom.xml
View file @
ce55671f
...
...
@@ -104,6 +104,11 @@
<artifactId>
javax.mail
</artifactId>
<version>
1.6.1
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.62
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/egolm/common/FileUtil.java
View file @
ce55671f
...
...
@@ -14,7 +14,6 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.io.Writer
;
...
...
@@ -363,18 +362,23 @@ public class FileUtil {
public
static
byte
[]
streamToBytes
(
InputStream
instream
)
{
byte
[]
bytes
=
null
;
ByteArrayOutputStream
baos
=
null
;
try
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
102400
);
baos
=
new
ByteArrayOutputStream
(
102400
);
byte
[]
b
=
new
byte
[
102400
];
int
n
;
while
((
n
=
instream
.
read
(
b
))
!=
-
1
)
{
baos
.
write
(
b
,
0
,
n
);
}
instream
.
close
();
baos
.
close
();
bytes
=
baos
.
toByteArray
();
}
catch
(
Exception
e
)
{
throw
new
FileUtilException
(
"将输入流转换为字节数组异常"
,
e
);
}
finally
{
try
{
baos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
bytes
;
}
...
...
@@ -549,30 +553,6 @@ public class FileUtil {
}
/**
*
* @Title: inputStreamToFile
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param ins
* @param: @param file
* @return: void
* @throws
*/
public
static
void
inputStreamToFile
(
InputStream
ins
,
File
file
)
{
try
{
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
ins
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
os
.
close
();
ins
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
Object
fileToObject
(
File
file
)
{
FileInputStream
fis
=
null
;
ObjectInputStream
ois
=
null
;
...
...
src/main/java/com/egolm/common/FtpUtil.java
View file @
ce55671f
src/main/java/com/egolm/common/HttpUtil.java
View file @
ce55671f
...
...
@@ -13,6 +13,7 @@ import java.net.URLEncoder;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -104,8 +105,8 @@ public class HttpUtil {
System
.
out
.
println
(
requestUrl
);
connection
=
createConnection
(
requestUrl
,
proxy
);
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestProperty
(
"Accept-Charset"
,
charset
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
//
connection.setRequestProperty("Accept-Charset", charset);
//
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if
(
header
!=
null
)
{
for
(
String
key
:
header
.
keySet
())
{
connection
.
setRequestProperty
(
key
,
header
.
get
(
key
));
...
...
@@ -177,6 +178,7 @@ public class HttpUtil {
try
{
bytes
=
FileUtil
.
streamToBytes
(
connection
.
getInputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
bytes
=
FileUtil
.
streamToBytes
(
connection
.
getErrorStream
());
}
Map
<
String
,
List
<
String
>>
responseHeaders
=
connection
.
getHeaderFields
();
...
...
@@ -258,8 +260,7 @@ public class HttpUtil {
for
(
Object
key
:
parameters
.
keySet
())
{
Object
val
=
parameters
.
get
(
key
);
String
sKey
=
String
.
valueOf
(
key
);
Object
[]
sVals
=
(
val
==
null
?
null
:
(
val
instanceof
Object
[]
?
(
Object
[])
val
:
new
Object
[]
{
val
}));
Object
[]
sVals
=
(
val
==
null
?
null
:
(
val
instanceof
Object
[]
?
(
Object
[])
val
:
(
val
instanceof
Collection
<?>
?
((
Collection
<?>)
val
).
toArray
()
:
new
Object
[]
{
val
})));
if
(
sVals
!=
null
&&
sVals
.
length
>
0
)
{
for
(
Object
sVal
:
sVals
)
{
if
(
StringUtil
.
isNotEmpty
(
sVal
))
{
...
...
src/main/java/com/egolm/common/StringUtil.java
View file @
ce55671f
...
...
@@ -1001,7 +1001,8 @@ public class StringUtil {
public
static
String
[]
searchNumber
(
String
string
)
{
List
<
String
>
numbers
=
new
ArrayList
<
String
>();
Pattern
pattern
=
Pattern
.
compile
(
"[\\d]+(\\.?[\\d]+)?"
);
String
regexText
=
"\\d+(\\.\\d+)?"
;
Pattern
pattern
=
Pattern
.
compile
(
regexText
);
Matcher
matcher
=
pattern
.
matcher
(
string
);
while
(
matcher
.
find
())
{
numbers
.
add
(
matcher
.
group
(
0
));
...
...
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
View file @
ce55671f
...
...
@@ -2,6 +2,8 @@ package com.egolm.common.jdbc;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.sql.CallableStatement
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
...
...
@@ -24,6 +26,7 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
import
org.springframework.jdbc.support.KeyHolder
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.GsonUtil
;
import
com.egolm.common.ReflexUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.Util
;
...
...
@@ -487,19 +490,14 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
public
ResultMutil
executeMutil
(
final
String
sql
,
final
Object
...
args
)
{
showSql
(
sql
,
args
);
Map
<
Integer
,
OutParameter
>
out
=
new
HashMap
<
Integer
,
OutParameter
>();
return
super
.
execute
(
new
CallableStatementCreator
()
{
public
CallableStatement
createCallableStatement
(
final
Connection
con
)
throws
SQLException
{
final
CallableStatement
cs
=
con
.
prepareCall
(
sql
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Integer
index
=
i
+
1
;
Object
arg
=
args
[
i
];
if
(
arg
!=
null
&&
arg
instanceof
OutParameter
)
{
out
.
put
(
index
,
(
OutParameter
)
arg
);
}
else
{
cs
.
setObject
(
index
,
arg
);
}
}
return
cs
;
}
},
new
CallableStatementCallback
<
ResultMutil
>()
{
...
...
@@ -521,11 +519,6 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
cs
.
getMoreResults
();
}
}
if
(
out
.
size
()
>
0
)
{
for
(
Integer
key
:
out
.
keySet
())
{
out
.
get
(
key
).
setValue
(
cs
.
getObject
(
key
));
}
}
return
new
ResultMutil
(
datas
,
counts
);
}
});
...
...
@@ -533,11 +526,21 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
public
List
<
Object
>
exec
(
final
String
sql
,
final
Object
...
args
)
{
showSql
(
sql
,
args
);
Map
<
Integer
,
OutParameter
>
out
=
new
HashMap
<
Integer
,
OutParameter
>();
return
super
.
execute
(
new
CallableStatementCreator
()
{
public
CallableStatement
createCallableStatement
(
final
Connection
con
)
throws
SQLException
{
final
CallableStatement
cs
=
con
.
prepareCall
(
sql
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
cs
.
setObject
(
i
+
1
,
args
[
i
]);
Integer
index
=
i
+
1
;
Object
arg
=
args
[
i
];
if
(
arg
!=
null
&&
arg
instanceof
OutParameter
)
{
OutParameter
outArg
=
(
OutParameter
)
arg
;
outArg
.
setValue
(
null
);
cs
.
registerOutParameter
(
index
,
outArg
.
getSqlType
());
out
.
put
(
index
,
outArg
);
}
else
{
cs
.
setObject
(
index
,
arg
);
}
}
return
cs
;
}
...
...
@@ -559,19 +562,26 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
cs
.
getMoreResults
();
}
}
if
(
out
.
size
()
>
0
)
{
for
(
Integer
key
:
out
.
keySet
())
{
Object
value
=
cs
.
getObject
(
key
);
out
.
get
(
key
).
setValue
(
value
);
logger
.
debug
(
"Parameter out: index="
+
key
+
", value="
+
value
);
}
}
return
datas
;
}
});
}
public
static
class
OutParameter
{
private
final
int
type
;
private
final
int
sqlType
;
private
Object
value
;
public
OutParameter
(
int
type
)
{
this
.
type
=
type
;
public
OutParameter
(
int
sqlType
)
{
this
.
sqlType
=
sqlType
;
}
public
int
get
Type
()
{
return
type
;
public
int
get
SqlType
()
{
return
sqlType
;
}
public
Object
getValue
()
{
return
value
;
...
...
@@ -579,6 +589,45 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
public
void
setValue
(
Object
value
)
{
this
.
value
=
value
;
}
public
<
T
>
T
getValue
(
Class
<
T
>
requireType
)
{
return
Util
.
objTo
(
this
.
getValue
(),
requireType
);
}
public
String
getString
()
{
return
this
.
getValue
(
String
.
class
);
}
public
Date
getDate
()
{
return
this
.
getValue
(
Date
.
class
);
}
public
Number
getNumber
()
{
return
(
Number
)
value
;
}
public
Long
getLong
()
{
return
this
.
getValue
(
Long
.
class
);
}
public
Integer
getInteger
()
{
return
this
.
getValue
(
Integer
.
class
);
}
public
BigDecimal
getBigDecimal
()
{
return
this
.
getValue
(
BigDecimal
.
class
);
}
public
BigInteger
getBigInteger
()
{
return
this
.
getValue
(
BigInteger
.
class
);
}
public
Double
getDouble
()
{
return
this
.
getValue
(
Double
.
class
);
}
public
Float
getFloat
()
{
return
this
.
getValue
(
Float
.
class
);
}
public
Short
getShort
()
{
return
this
.
getValue
(
Short
.
class
);
}
public
Byte
getByte
()
{
return
this
.
getValue
(
Byte
.
class
);
}
public
Boolean
getBoolean
()
{
return
this
.
getValue
(
Boolean
.
class
);
}
}
public
synchronized
String
getNumber
(
String
...
args
)
{
...
...
@@ -625,7 +674,7 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
if
(
sql_level
==
1
)
{
logger
.
debug
(
sql
);
}
else
if
(
sql_level
>
1
)
{
logger
.
debug
(
sql
+
" "
+
StringUtil
.
toJson
(
args
));
logger
.
debug
(
sql
+
" "
+
GsonUtil
.
toJson
(
args
));
}
}
...
...
src/main/java/com/egolm/common/jdbc/dialect/ReverseUtil.java
View file @
ce55671f
...
...
@@ -151,7 +151,7 @@ public class ReverseUtil {
return
"BigDecimal"
;
}
else
if
(
sqlType
.
startsWith
(
"double"
)
||
sqlType
.
startsWith
(
"real"
)
||
sqlType
.
startsWith
(
"money"
)
||
sqlType
.
startsWith
(
"smallmoney"
)){
return
"Double"
;
}
else
if
(
sqlType
.
startsWith
(
"varchar"
)
||
sqlType
.
startsWith
(
"char"
)
||
sqlType
.
startsWith
(
"nvarchar"
)
||
sqlType
.
startsWith
(
"nchar"
)
||
sqlType
.
startsWith
(
"text"
)
||
sqlType
.
startsWith
(
"longtext"
)
){
}
else
if
(
sqlType
.
startsWith
(
"varchar"
)
||
sqlType
.
startsWith
(
"char"
)
||
sqlType
.
startsWith
(
"nvarchar"
)
||
sqlType
.
startsWith
(
"nchar"
)
||
sqlType
.
startsWith
(
"text"
)
||
sqlType
.
startsWith
(
"longtext"
)
||
sqlType
.
startsWith
(
"mediumtext"
)){
return
"String"
;
}
else
if
(
sqlType
.
startsWith
(
"datetime"
)
||
sqlType
.
startsWith
(
"date"
)
||
sqlType
.
startsWith
(
"timestamp"
)){
return
"Date"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment