Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
master-4.0
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
master-4.0
Commits
d63fe19c
提交
d63fe19c
authored
1月 22, 2019
作者:
chenxinchang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
451f878b
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
319 行增加
和
35 行删除
+319
-35
EnumUtil.java
...zrqx.core/src/main/java/com/zrqx/core/enums/EnumUtil.java
+0
-5
FileInfo.java
...core/src/main/java/com/zrqx/core/model/file/FileInfo.java
+33
-0
CreateRandomCode.java
...in/java/com/zrqx/core/util/datatype/CreateRandomCode.java
+0
-26
PasswordUtil.java
...c/main/java/com/zrqx/core/util/datatype/PasswordUtil.java
+1
-3
VerifyUtil.java
...src/main/java/com/zrqx/core/util/datatype/VerifyUtil.java
+1
-1
QrCodeCreateUtil.java
...ain/java/com/zrqx/core/util/erweima/QrCodeCreateUtil.java
+188
-0
ZipUtil.java
...qx.core/src/main/java/com/zrqx/core/util/zip/ZipUtil.java
+96
-0
没有找到文件。
com.zrqx.core/src/main/java/com/zrqx/core/enums/EnumUtil.java
deleted
100644 → 0
浏览文件 @
451f878b
package
com
.
zrqx
.
core
.
enums
;
public
class
EnumUtil
{
}
com.zrqx.core/src/main/java/com/zrqx/core/model/file/FileInfo.java
0 → 100644
浏览文件 @
d63fe19c
package
com
.
zrqx
.
core
.
model
.
file
;
import
java.util.Date
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
FileInfo
{
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
@ApiModelProperty
(
value
=
"文件ID"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"文件名"
)
private
String
fileName
;
@ApiModelProperty
(
value
=
"内容类型"
)
private
String
contentType
;
@ApiModelProperty
(
value
=
"后缀名"
)
private
String
suffixName
;
@ApiModelProperty
(
value
=
"原文件名"
)
private
String
originalFileName
;
@ApiModelProperty
(
value
=
"存储路径"
)
private
String
path
;
@ApiModelProperty
(
value
=
"文件大小"
)
private
Long
size
;
@ApiModelProperty
(
value
=
"文件时长"
)
private
Long
time
;
@ApiModelProperty
(
value
=
"创建时间"
)
private
Date
createTime
;
}
com.zrqx.core/src/main/java/com/zrqx/core/util/datatype/CreateRandomCode.java
deleted
100644 → 0
浏览文件 @
451f878b
package
com
.
zrqx
.
core
.
util
.
datatype
;
import
java.util.Random
;
/**
* TODO 功能整合到StringUtils中
* @author lpf
* @date 2018年12月26日下午5:26:40
*/
public
class
CreateRandomCode
{
public
static
String
create
(){
String
chars
=
"ABCDEFGHIGKLMNOPQRSTUVWXYZ"
;
char
r1
=
chars
.
charAt
((
int
)(
Math
.
random
()
*
26
));
char
r2
=
chars
.
charAt
((
int
)(
Math
.
random
()
*
26
));
StringBuilder
sb
=
new
StringBuilder
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
13
;
i
++){
sb
.
append
(
random
.
nextInt
(
10
));
}
String
str
=
String
.
valueOf
(
r1
)+
sb
.
toString
();
return
str
;
}
}
com.zrqx.core/src/main/java/com/zrqx/core/util/PasswordUtil.java
→
com.zrqx.core/src/main/java/com/zrqx/core/util/
datatype/
PasswordUtil.java
浏览文件 @
d63fe19c
package
com
.
zrqx
.
core
.
util
;
package
com
.
zrqx
.
core
.
util
.
datatype
;
import
java.util.Random
;
import
com.zrqx.core.util.datatype.UUIDUtil
;
/**
* 随意有规则的字符串
* @author Administrator
...
...
com.zrqx.core/src/main/java/com/zrqx/core/util/VerifyUtil.java
→
com.zrqx.core/src/main/java/com/zrqx/core/util/
datatype/
VerifyUtil.java
浏览文件 @
d63fe19c
package
com
.
zrqx
.
core
.
util
;
package
com
.
zrqx
.
core
.
util
.
datatype
;
import
java.awt.Color
;
import
java.awt.Font
;
import
java.awt.Graphics
;
...
...
com.zrqx.core/src/main/java/com/zrqx/core/util/erweima/QrCodeCreateUtil.java
0 → 100644
浏览文件 @
d63fe19c
package
com
.
zrqx
.
core
.
util
.
erweima
;
import
java.awt.Color
;
import
java.awt.Graphics2D
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.Hashtable
;
import
javax.imageio.ImageIO
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.BinaryBitmap
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.LuminanceSource
;
import
com.google.zxing.ReaderException
;
import
com.google.zxing.Result
;
import
com.google.zxing.WriterException
;
import
com.google.zxing.client.j2se.BufferedImageLuminanceSource
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.common.HybridBinarizer
;
import
com.google.zxing.qrcode.QRCodeReader
;
import
com.google.zxing.qrcode.QRCodeWriter
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
/**
* 二维码生成和读的工具类
*
*/
public
class
QrCodeCreateUtil
{
private
static
String
TYPE
=
"JPEG"
;
private
static
int
SIZE
=
300
;
/**
* 生成包含字符串信息的二维码图片
*
* @param outputStream
* 文件输出流路径
* @param content
* 二维码携带信息
* @param qrCodeSize
* 二维码图片大小
* @param imageFormat
* 二维码的格式
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
OutputStream
outputStream
,
String
content
,
int
qrCodeSize
,
String
imageFormat
)
throws
WriterException
,
IOException
{
if
(
qrCodeSize
<
130
){
qrCodeSize
=
130
;
}
// 设置二维码纠错级别MAP
Hashtable
<
EncodeHintType
,
ErrorCorrectionLevel
>
hintMap
=
new
Hashtable
<
EncodeHintType
,
ErrorCorrectionLevel
>();
hintMap
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
ErrorCorrectionLevel
.
L
);
// 矫错级别
QRCodeWriter
qrCodeWriter
=
new
QRCodeWriter
();
// 创建比特矩阵(位矩阵)的QR码编码的字符串
BitMatrix
byteMatrix
=
qrCodeWriter
.
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
qrCodeSize
,
qrCodeSize
,
hintMap
);
// 使BufferedImage勾画QRCode (matrixWidth 是行二维码像素点)
int
matrixWidth
=
byteMatrix
.
getWidth
();
BufferedImage
image
=
new
BufferedImage
(
matrixWidth
-
50
,
matrixWidth
-
50
,
BufferedImage
.
TYPE_INT_RGB
);
image
.
createGraphics
();
Graphics2D
graphics
=
(
Graphics2D
)
image
.
getGraphics
();
graphics
.
setColor
(
Color
.
WHITE
);
graphics
.
fillRect
(
0
,
0
,
matrixWidth
,
matrixWidth
);
// 使用比特矩阵画并保存图像
graphics
.
setColor
(
Color
.
BLACK
);
for
(
int
i
=
0
;
i
<
matrixWidth
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrixWidth
;
j
++)
{
if
(
byteMatrix
.
get
(
i
,
j
))
{
graphics
.
fillRect
(
i
-
25
,
j
-
25
,
1
,
1
);
}
}
}
boolean
flag
=
ImageIO
.
write
(
image
,
imageFormat
,
outputStream
);
outputStream
.
close
();
return
flag
;
}
/**
* 生成包含字符串信息的二维码图片
*
* @param outputStream
* 文件输出流路径
* @param content
* 二维码携带信息
* @param qrCodeSize
* 二维码图片大小
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
OutputStream
outputStream
,
String
content
,
int
qrCodeSize
)
throws
WriterException
,
IOException
{
return
createQrCode
(
outputStream
,
content
,
qrCodeSize
,
TYPE
);
}
/**
* 生成包含字符串信息的二维码图片
*
* @param outputStream
* 文件输出流路径
* @param content
* 二维码携带信息
* @param imageFormat
* 二维码的格式
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
OutputStream
outputStream
,
String
content
,
String
imageFormat
)
throws
WriterException
,
IOException
{
return
createQrCode
(
outputStream
,
content
,
SIZE
,
imageFormat
);
}
/**
* 生成包含字符串信息的二维码图片
*
* @param outputStream
* 文件输出流路径
* @param content
* 二维码携带信息
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
OutputStream
outputStream
,
String
content
)
throws
WriterException
,
IOException
{
return
createQrCode
(
outputStream
,
content
,
SIZE
,
TYPE
);
}
/**
* 生成包含字符串信息的二维码图片
*
* @param filePath
* 文件输出路径
* @param content
* 二维码携带信息
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
String
filePath
,
String
content
)
throws
WriterException
,
IOException
{
return
createQrCode
(
new
FileOutputStream
(
new
File
(
filePath
)),
content
,
SIZE
,
TYPE
);
}
/**
* 生成包含字符串信息的二维码图片
*
* @param file
* 文件
* @param content
* 二维码携带信息
* @throws WriterException
* @throws IOException
*/
public
static
boolean
createQrCode
(
File
file
,
String
content
)
throws
WriterException
,
IOException
{
return
createQrCode
(
new
FileOutputStream
(
file
),
content
,
SIZE
,
TYPE
);
}
/**
* 读二维码并输出携带的信息
*/
public
static
String
readQrCode
(
InputStream
inputStream
)
throws
IOException
{
// 从输入流中获取字符串信息
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);
// 将图像转换为二进制位图源
LuminanceSource
source
=
new
BufferedImageLuminanceSource
(
image
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
QRCodeReader
reader
=
new
QRCodeReader
();
Result
result
=
null
;
try
{
result
=
reader
.
decode
(
bitmap
);
return
result
.
getText
();
}
catch
(
ReaderException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 测试代码
*
* @throws WriterException
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
,
WriterException
{
createQrCode
(
new
FileOutputStream
(
new
File
(
"d:\\qrcode.jpg"
)),
"WE11111111111111111111111111111111111111111111"
);
readQrCode
(
new
FileInputStream
(
new
File
(
"d:\\qrcode.jpg"
)));
}
}
\ No newline at end of file
com.zrqx.core/src/main/java/com/zrqx/core/util/zip/ZipUtil.java
0 → 100644
浏览文件 @
d63fe19c
package
com
.
zrqx
.
core
.
util
.
zip
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
com.zrqx.core.model.file.FileInfo
;
import
com.zrqx.core.util.datatype.UUIDUtil
;
public
class
ZipUtil
{
/**
*
* @param zipFileName
* 目的地Zip文件
* @param sourceFileName
* 源文件(待压缩的文件或文件夹)
* @throws Exception
*/
public
static
void
zip
(
String
zipFileName
,
String
sourceFileName
)
throws
Exception
{
// File zipFile = new File(zipFileName);
System
.
out
.
println
(
"压缩中..."
);
// 创建zip输出流
ZipOutputStream
out
=
new
ZipOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
zipFileName
)));
File
sourceFile
=
new
File
(
sourceFileName
);
// 调用函数
compress
(
out
,
sourceFile
,
sourceFile
.
getName
());
out
.
close
();
System
.
out
.
println
(
"压缩完成"
);
}
/**
*
* @param rootPath 文件要压缩到的文件夹
* @param list 要压缩的文件对象
* @return String 文件路径
* @throws Exception
*/
public
static
String
zip
(
String
rootPath
,
List
<
FileInfo
>
list
)
throws
Exception
{
// File zipFile = new File(zipFileName);
System
.
out
.
println
(
"压缩中..."
);
String
zipFileName
=
rootPath
+
UUIDUtil
.
getUUID
()
+
".zip"
;
// 创建zip输出流
ZipOutputStream
out
=
new
ZipOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
zipFileName
)));
for
(
FileInfo
file
:
list
)
{
String
filePath
=
rootPath
+
file
.
getPath
()
+
"/"
+
file
.
getFileName
()
+
file
.
getSuffixName
();
File
sourceFile
=
new
File
(
filePath
);
compress
(
out
,
sourceFile
,
sourceFile
.
getName
());
}
out
.
close
();
System
.
out
.
println
(
"压缩完成"
);
return
zipFileName
;
}
public
static
void
compress
(
ZipOutputStream
out
,
File
sourceFile
,
String
base
)
throws
Exception
{
// 如果路径为目录(文件夹)
if
(
sourceFile
.
isDirectory
())
{
// 取出文件夹中的文件(或子文件夹)
File
[]
flist
=
sourceFile
.
listFiles
();
if
(
flist
==
null
||
flist
.
length
==
0
)
{
// 如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
out
.
putNextEntry
(
new
ZipEntry
(
base
+
"/"
));
}
else
{
// 如果文件夹不为空,则递归调用compress,文件夹中的每一个文件(或文件夹)进行压缩
for
(
int
i
=
0
;
i
<
flist
.
length
;
i
++)
{
compress
(
out
,
flist
[
i
],
base
+
"/"
+
flist
[
i
].
getName
());
}
}
}
else
{
// 如果不是目录(文件夹),即为文件,则先写入目录进入点,之后将文件写入zip文件中
out
.
putNextEntry
(
new
ZipEntry
(
base
));
FileInputStream
fos
=
new
FileInputStream
(
sourceFile
);
BufferedInputStream
bis
=
new
BufferedInputStream
(
fos
);
int
tag
;
// 将源文件写入到zip文件中
while
((
tag
=
bis
.
read
())
!=
-
1
)
{
out
.
write
(
tag
);
}
bis
.
close
();
fos
.
close
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论