Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
adaptation-master
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
adaptation-master
Commits
0d7f231f
提交
0d7f231f
authored
12月 20, 2019
作者:
zhangshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
zs
上级
bab5dbbc
显示空白字符变更
内嵌
并排
正在显示
19 个修改的文件
包含
237 行增加
和
388 行删除
+237
-388
DBManageController.java
...aptationmaster/adaptor/controller/DBManageController.java
+6
-0
DBRecordController.java
...aptationmaster/adaptor/controller/DBRecordController.java
+1
-5
InspectController.java
...daptationmaster/adaptor/controller/InspectController.java
+3
-5
Test.java
...va/com/zjty/adaptationmaster/adaptor/controller/Test.java
+24
-0
WebSocketServer.java
.../adaptationmaster/adaptor/controller/WebSocketServer.java
+5
-1
MiddlewareManagement.java
...adaptationmaster/adaptor/entity/MiddlewareManagement.java
+2
-0
Project.java
...ava/com/zjty/adaptationmaster/adaptor/entity/Project.java
+6
-0
DBRecordDao.java
...zjty/adaptationmaster/adaptor/repository/DBRecordDao.java
+4
-1
DBManageService.java
...jty/adaptationmaster/adaptor/service/DBManageService.java
+3
-0
DBRecordService.java
...jty/adaptationmaster/adaptor/service/DBRecordService.java
+0
-1
AdaptationServiceImpl.java
...ionmaster/adaptor/service/Impl/AdaptationServiceImpl.java
+1
-1
DBManageServiceImpl.java
...ationmaster/adaptor/service/Impl/DBManageServiceImpl.java
+54
-0
DBRecordServiceImpl.java
...ationmaster/adaptor/service/Impl/DBRecordServiceImpl.java
+4
-35
FileUploadServiceImpl.java
...ionmaster/adaptor/service/Impl/FileUploadServiceImpl.java
+1
-1
ServerResponse.java
...m/zjty/adaptationmaster/base/response/ServerResponse.java
+1
-0
FileUtil.java
src/main/java/com/zjty/adaptationmaster/utils/FileUtil.java
+54
-330
FileZip.java
src/main/java/com/zjty/adaptationmaster/utils/FileZip.java
+51
-0
Regular.java
src/main/java/com/zjty/adaptationmaster/utils/Regular.java
+3
-3
Test4.java
src/test/java/com/zjty/adaptationmaster/Test4.java
+14
-5
没有找到文件。
src/main/java/com/zjty/adaptationmaster/adaptor/controller/DBManageController.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
controller
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBDeleteResponse
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBManage
;
import
com.zjty.adaptationmaster.adaptor.service.DBManageService
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
...
...
@@ -27,4 +28,9 @@ public class DBManageController {
public
ServerResponse
findDatabaseManagement
(){
return
databaseService
.
findDatabase
();
}
@PutMapping
(
"/deleteDB"
)
public
ServerResponse
deleteDB
(
@RequestBody
DBDeleteResponse
dbDeleteResponse
){
return
databaseService
.
deleteDB
(
dbDeleteResponse
);
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/controller/DBRecordController.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
controller
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBDeleteResponse
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBRecordPage
;
import
com.zjty.adaptationmaster.adaptor.service.DBRecordService
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
...
...
@@ -21,8 +20,5 @@ public class DBRecordController {
return
dbRecordService
.
pageFind
(
dbRecordPage
);
}
@PutMapping
(
"deleteDB"
)
public
ServerResponse
deleteDB
(
@RequestBody
DBDeleteResponse
dbDeleteResponse
){
return
dbRecordService
.
deleteDB
(
dbDeleteResponse
);
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/controller/InspectController.java
浏览文件 @
0d7f231f
...
...
@@ -4,17 +4,15 @@ import com.zjty.adaptationmaster.adaptor.entity.Project;
import
com.zjty.adaptationmaster.adaptor.service.InspectService
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
"/inspect"
)
public
class
InspectController
{
@Autowired
private
InspectService
inspectService
;
@
Ge
tMapping
(
"/inspect"
)
public
ServerResponse
inspect
(
Project
projectId
){
@
Pu
tMapping
(
"/inspect"
)
public
ServerResponse
inspect
(
@RequestBody
Project
projectId
){
return
inspectService
.
inspect
(
projectId
);
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/controller/Test.java
0 → 100644
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.IOException
;
@RestController
@RequestMapping
(
"/send"
)
public
class
Test
{
@PutMapping
(
"/test/{uuid}"
)
public
ServerResponse
test
(
@PathVariable
String
uuid
){
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"message"
,
"这是后台返回的消息!"
);
try
{
WebSocketServer
.
sendIn
(
uuid
,
JSONObject
.
toJSONString
(
jo
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
ServerResponse
.
success
();
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/controller/WebSocketServer.java
浏览文件 @
0d7f231f
...
...
@@ -27,7 +27,9 @@ public class WebSocketServer {
public
void
onOpen
(
Session
session
,
@PathParam
(
"uuid"
)
String
uuid
){
this
.
session
=
session
;
this
.
uuid
=
uuid
;
System
.
out
.
println
(
this
.
uuid
+
"\t"
+
this
.
session
);
//session.getOpenSessions().
logger
.
info
(
"uuid:"
+
uuid
);
map
.
put
(
uuid
,
this
);
try
{
sendMessage
(
"连接成功"
);
...
...
@@ -73,6 +75,8 @@ public class WebSocketServer {
e
.
printStackTrace
();
}
}
public
static
void
sendIn
(
String
sessionId
,
String
message
)
throws
IOException
{
map
.
get
(
sessionId
).
sendMessage
(
message
);
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/entity/MiddlewareManagement.java
浏览文件 @
0d7f231f
...
...
@@ -28,6 +28,8 @@ public class MiddlewareManagement {
private
String
ip
;
//中间件ip
private
String
type
;
//类型
private
String
port
;
//端口号
@Temporal
(
TemporalType
.
TIMESTAMP
)
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/entity/Project.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
entity
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
...
...
@@ -18,6 +19,7 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@JsonIgnoreProperties
(
value
=
{
"hibernateLazyInitializer"
,
"handler"
})
public
class
Project
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
...
...
@@ -26,6 +28,10 @@ public class Project {
@Column
(
unique
=
true
)
private
String
projectName
;
//项目名称
private
String
sourceDB
;
//原数据库
private
String
createTypeDB
;
//目标数据库
private
String
createMiddleware
;
//目标中间件
private
String
codeUrl
;
//当前源码源码路径
private
Integer
status
=
1
;
//状态(0:删除 1:未删除)
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/repository/DBRecordDao.java
浏览文件 @
0d7f231f
...
...
@@ -7,10 +7,13 @@ import org.springframework.data.jpa.repository.Modifying;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.query.Param
;
import
java.util.List
;
public
interface
DBRecordDao
extends
JpaRepository
<
DBRecord
,
Integer
>,
JpaSpecificationExecutor
{
@Query
(
"update DBRecord d set d.status =:status where d.dbName =:dbName"
)
@Modifying
@Query
(
"update DBRecord d set d.status =:status where d.dbName =:dbName"
)
void
delete
(
@Param
(
value
=
"dbName"
)
String
dbName
,
@Param
(
value
=
"status"
)
Integer
status
);
List
<
DBRecord
>
findDBRecordsByStatus
(
Integer
status
);
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/DBManageService.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
service
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBDeleteResponse
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBManage
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
...
...
@@ -11,4 +12,6 @@ public interface DBManageService {
ServerResponse
deleteDatabase
(
Integer
id
);
ServerResponse
findDatabase
();
ServerResponse
deleteDB
(
DBDeleteResponse
dbDeleteResponse
);
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/DBRecordService.java
浏览文件 @
0d7f231f
...
...
@@ -9,5 +9,4 @@ public interface DBRecordService {
ServerResponse
pageFind
(
DBRecordPage
dbRecordPage
);
ServerResponse
deleteDB
(
DBDeleteResponse
dbDeleteResponse
);
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/AdaptationServiceImpl.java
浏览文件 @
0d7f231f
...
...
@@ -64,7 +64,7 @@ public class AdaptationServiceImpl implements AdaptationService {
FileUtil
fileUtil
=
new
FileUtil
();
project
.
setCodeUrl
(
Const
.
UPLOAD_LOCATION
+
File
.
separator
+
project
.
getProjectName
());
try
{
fileUtil
.
un
zip
(
path
,
project
.
getCodeUrl
());
fileUtil
.
un
Zip
(
new
File
(
path
)
,
project
.
getCodeUrl
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/DBManageServiceImpl.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
adaptor
.
service
.
Impl
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBDeleteResponse
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBManage
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBRecord
;
import
com.zjty.adaptationmaster.adaptor.repository.DBManageDao
;
import
com.zjty.adaptationmaster.adaptor.repository.DBRecordDao
;
import
com.zjty.adaptationmaster.adaptor.service.DBManageService
;
import
com.zjty.adaptationmaster.base.response.ServerResponse
;
import
com.zjty.adaptationmaster.utils.Regular
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
@Service
public
class
DBManageServiceImpl
implements
DBManageService
{
@Autowired
private
DBManageDao
databaseDao
;
@Autowired
private
DBRecordDao
dbRecordDao
;
@Value
(
"${highgo.driver}"
)
private
String
highgoDriver
;
@Value
(
"${highgo.connectionType}"
)
private
String
highgoConnnectionType
;
@Value
(
"${highgo.dbName}"
)
private
String
highgoDBName
;
/**
* 新增数据库配置文件
...
...
@@ -49,4 +67,40 @@ public class DBManageServiceImpl implements DBManageService {
return
ServerResponse
.
success
(
databaseDao
.
findDatabaseManagementByStatus
(
1
));
}
/**
* 数据库删除
* @param dbDeleteResponse
* @return
*/
@Override
@Transactional
public
ServerResponse
deleteDB
(
DBDeleteResponse
dbDeleteResponse
)
{
DBManage
dbManage
=
databaseDao
.
findDBManageByIdAndStatus
(
dbDeleteResponse
.
getId
(),
1
);
if
(
dbDeleteResponse
.
getDbType
().
equals
(
"highgo"
)){
dbManage
.
setDatabaseName
(
highgoDBName
);
dbManage
.
setDriver
(
highgoDriver
);
dbManage
.
setConnectionType
(
highgoConnnectionType
);
}
Connection
connection
=
Regular
.
databaseConnection
(
dbManage
);
if
(
connection
!=
null
)
{
PreparedStatement
preparedStatement
=
null
;
try
{
String
findDB
=
"DROP DATABASE IF EXISTS "
+
dbDeleteResponse
.
getDbName
()+
";"
;
preparedStatement
=
connection
.
prepareStatement
(
findDB
);
preparedStatement
.
execute
();
dbRecordDao
.
delete
(
dbDeleteResponse
.
getDbName
(),
0
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
preparedStatement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ServerResponse
.
success
();
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/DBRecordServiceImpl.java
浏览文件 @
0d7f231f
...
...
@@ -35,10 +35,10 @@ public class DBRecordServiceImpl implements DBRecordService {
public
ServerResponse
pageFind
(
DBRecordPage
dbRecordPage
)
{
Specification
<
DBRecord
>
specifications
=
Specifications
.<
DBRecord
>
and
()
.
eq
(
dbRecordPage
.
getCreateType
()
!=
null
,
"createType"
,
dbRecordPage
.
getCreateType
())
.
eq
(
dbRecordPage
.
getUserName
()
!=
null
,
"userName"
,
dbRecordPage
.
getUserName
())
//
.eq(dbRecordPage.getUserName() != null,"userName",dbRecordPage.getUserName())
.
eq
(
"status"
,
1
)
.
build
();
Integer
page
=
dbRecordPage
.
getPage
();
/*
Integer page = dbRecordPage.getPage();
Integer size = dbRecordPage.getSize();
if(page == null || page <= 0){
page = 1;
...
...
@@ -50,38 +50,7 @@ public class DBRecordServiceImpl implements DBRecordService {
long count = dbRecordDao.count(specifications);
if(count < 0){
return ServerResponse.error();
}
return
ServerResponse
.
success
(
new
DBRecordReturn
(
count
,
dbRecordDao
.
findAll
(
specifications
,
pageable
).
getContent
()));
}
/**
* 数据库删除
* @param dbDeleteResponse
* @return
*/
@Override
@Transactional
public
ServerResponse
deleteDB
(
DBDeleteResponse
dbDeleteResponse
)
{
DBManage
dbManage
=
dbManageDao
.
findDBManageByIdAndStatus
(
dbDeleteResponse
.
getId
(),
1
);
Connection
connection
=
Regular
.
databaseConnection
(
dbManage
);
if
(
connection
!=
null
)
{
PreparedStatement
preparedStatement
=
null
;
try
{
String
findDB
=
"DROP DATABASE IF EXISTS "
+
dbDeleteResponse
.
getDbName
()+
";"
;
preparedStatement
=
connection
.
prepareStatement
(
findDB
);
preparedStatement
.
execute
();
dbRecordDao
.
delete
(
dbDeleteResponse
.
getDbName
(),
0
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
preparedStatement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ServerResponse
.
success
();
}*/
return
ServerResponse
.
success
(
dbRecordDao
.
findAll
(
specifications
));
}
}
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/FileUploadServiceImpl.java
浏览文件 @
0d7f231f
...
...
@@ -32,7 +32,7 @@ public class FileUploadServiceImpl implements FileUploadService {
BufferedOutputStream
bos
=
null
;
FileReturn
fileReturn
=
new
FileReturn
();
String
sourceName
=
multipartFile
.
getOriginalFilename
();
String
suffix
=
sourceName
.
substring
(
sourceName
.
lastIndexOf
(
"."
)
+
1
);
String
suffix
=
sourceName
.
substring
(
sourceName
.
lastIndexOf
(
"."
));
String
fileName
=
UUID
.
randomUUID
().
toString
()
+
suffix
;
//不存在该目录,创建目录
File
file
=
new
File
(
"/sqlFile/uploads"
);
...
...
src/main/java/com/zjty/adaptationmaster/base/response/ServerResponse.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
base
.
response
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.zjty.adaptationmaster.utils.HttpClientUtil
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
src/main/java/com/zjty/adaptationmaster/utils/FileUtil.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
utils
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Enumeration
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
org.apache.tools.tar.TarEntry
;
import
org.apache.tools.tar.TarOutputStream
;
import
org.apache.tools.zip.ZipEntry
;
import
org.apache.tools.zip.ZipFile
;
import
org.apache.tools.zip.ZipOutputStream
;
public
class
FileUtil
{
private
static
final
int
BUFFEREDSIZE
=
1024
;
/**
* 解压zip格式的压缩文件到当前文件夹
*
* @param zipFileName
* @throws Exception
*/
@SuppressWarnings
(
"unchecked"
)
public
synchronized
void
unzipFile
(
String
zipFileName
)
throws
Exception
{
try
{
File
f
=
new
File
(
zipFileName
);
ZipFile
zipFile
=
new
ZipFile
(
zipFileName
);
if
((!
f
.
exists
())
&&
(
f
.
length
()
<=
0
))
{
throw
new
Exception
(
"要解压的文件不存在!"
);
}
String
strPath
,
gbkPath
,
strtemp
;
File
tempFile
=
new
File
(
f
.
getParent
());
strPath
=
tempFile
.
getAbsolutePath
();
java
.
util
.
Enumeration
e
=
zipFile
.
getEntries
();
while
(
e
.
hasMoreElements
())
{
org
.
apache
.
tools
.
zip
.
ZipEntry
zipEnt
=
(
ZipEntry
)
e
.
nextElement
();
gbkPath
=
zipEnt
.
getName
();
if
(
zipEnt
.
isDirectory
())
{
strtemp
=
strPath
+
"/"
+
gbkPath
;
File
dir
=
new
File
(
strtemp
);
dir
.
mkdirs
();
continue
;
}
else
{
//读写文件
InputStream
is
=
zipFile
.
getInputStream
(
zipEnt
);
BufferedInputStream
bis
=
new
BufferedInputStream
(
is
);
gbkPath
=
zipEnt
.
getName
();
strtemp
=
strPath
+
"/"
+
gbkPath
;
//建目录
String
strsubdir
=
gbkPath
;
for
(
int
i
=
0
;
i
<
strsubdir
.
length
();
i
++)
{
if
(
strsubdir
.
substring
(
i
,
i
+
1
).
equalsIgnoreCase
(
"/"
))
{
String
temp
=
strPath
+
"/"
+
strsubdir
.
substring
(
0
,
i
);
File
subdir
=
new
File
(
temp
);
if
(!
subdir
.
exists
())
subdir
.
mkdir
();
}
}
FileOutputStream
fos
=
new
FileOutputStream
(
strtemp
);
BufferedOutputStream
bos
=
new
BufferedOutputStream
(
fos
);
int
c
;
while
((
c
=
bis
.
read
())
!=
-
1
)
{
bos
.
write
((
byte
)
c
);
}
bos
.
close
();
fos
.
close
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
static
int
BUFFER_SIZE
=
1024
;
/**
* 解压zip格式的压缩文件到指定位置
*
* @param zipFileName 压缩文件
* @param extPlace 解压目录
* @throws Exception
* zip解压
* @param srcFile zip源文件
* @param destDirPath 解压后的目标文件夹
* @throws RuntimeException 解压失败会抛出运行时异常
*/
@SuppressWarnings
(
"unchecked"
)
public
synchronized
void
unzip
(
String
zipFileName
,
String
extPlace
)
throws
Exception
{
public
static
void
unZip
(
File
srcFile
,
String
destDirPath
)
throws
RuntimeException
{
long
start
=
System
.
currentTimeMillis
();
// 判断源文件是否存在
if
(!
srcFile
.
exists
())
{
throw
new
RuntimeException
(
srcFile
.
getPath
()
+
"所指文件不存在"
);
}
// 开始解压
ZipFile
zipFile
=
null
;
try
{
(
new
File
(
extPlace
)).
mkdirs
();
File
f
=
new
File
(
zipFileName
);
ZipFile
zipFile
=
new
ZipFile
(
zipFileName
);
if
((!
f
.
exists
())
&&
(
f
.
length
()
<=
0
))
{
throw
new
Exception
(
"要解压的文件不存在!"
);
}
String
strPath
,
gbkPath
,
strtemp
;
File
tempFile
=
new
File
(
extPlace
);
strPath
=
tempFile
.
getAbsolutePath
();
java
.
util
.
Enumeration
e
=
zipFile
.
getEntries
();
while
(
e
.
hasMoreElements
())
{
org
.
apache
.
tools
.
zip
.
ZipEntry
zipEnt
=
(
ZipEntry
)
e
.
nextElement
();
gbkPath
=
zipEnt
.
getName
();
if
(
zipEnt
.
isDirectory
())
{
strtemp
=
strPath
+
File
.
separator
+
gbkPath
;
File
dir
=
new
File
(
strtemp
);
zipFile
=
new
ZipFile
(
srcFile
);
Enumeration
<?>
entries
=
zipFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
ZipEntry
entry
=
(
ZipEntry
)
entries
.
nextElement
();
System
.
out
.
println
(
"解压"
+
entry
.
getName
());
// 如果是文件夹,就创建个文件夹
if
(
entry
.
isDirectory
())
{
String
dirPath
=
destDirPath
+
"/"
+
entry
.
getName
();
File
dir
=
new
File
(
dirPath
);
dir
.
mkdirs
();
continue
;
}
else
{
//读写文件
InputStream
is
=
zipFile
.
getInputStream
(
zipEnt
);
BufferedInputStream
bis
=
new
BufferedInputStream
(
is
);
gbkPath
=
zipEnt
.
getName
();
strtemp
=
strPath
+
File
.
separator
+
gbkPath
;
//建目录
String
strsubdir
=
gbkPath
;
for
(
int
i
=
0
;
i
<
strsubdir
.
length
();
i
++)
{
if
(
strsubdir
.
substring
(
i
,
i
+
1
).
equalsIgnoreCase
(
"/"
))
{
String
temp
=
strPath
+
File
.
separator
+
strsubdir
.
substring
(
0
,
i
);
File
subdir
=
new
File
(
temp
);
if
(!
subdir
.
exists
())
subdir
.
mkdir
();
}
}
FileOutputStream
fos
=
new
FileOutputStream
(
strtemp
);
BufferedOutputStream
bos
=
new
BufferedOutputStream
(
fos
);
int
c
;
while
((
c
=
bis
.
read
())
!=
-
1
)
{
bos
.
write
((
byte
)
c
);
}
bos
.
close
();
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去
File
targetFile
=
new
File
(
destDirPath
+
"/"
+
entry
.
getName
());
// 保证这个文件的父文件夹必须要存在
if
(!
targetFile
.
getParentFile
().
exists
()){
targetFile
.
getParentFile
().
mkdirs
();
}
targetFile
.
createNewFile
();
// 将压缩文件内容写入到这个文件中
InputStream
is
=
zipFile
.
getInputStream
(
entry
);
FileOutputStream
fos
=
new
FileOutputStream
(
targetFile
);
int
len
;
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
);
}
// 关流顺序,先打开的后关闭
fos
.
close
();
is
.
close
();
}
}
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"解压完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
/**
* 解压zip格式的压缩文件到指定位置
*
* @param zipFileName 压缩文件
* @param extPlace 解压目录
* @throws Exception
*/
@SuppressWarnings
(
"unchecked"
)
public
synchronized
void
unzip
(
String
zipFileName
,
String
extPlace
,
boolean
whether
)
throws
Exception
{
try
{
(
new
File
(
extPlace
)).
mkdirs
();
File
f
=
new
File
(
zipFileName
);
ZipFile
zipFile
=
new
ZipFile
(
zipFileName
);
if
((!
f
.
exists
())
&&
(
f
.
length
()
<=
0
))
{
throw
new
Exception
(
"要解压的文件不存在!"
);
}
String
strPath
,
gbkPath
,
strtemp
;
File
tempFile
=
new
File
(
extPlace
);
strPath
=
tempFile
.
getAbsolutePath
();
java
.
util
.
Enumeration
e
=
zipFile
.
getEntries
();
while
(
e
.
hasMoreElements
())
{
org
.
apache
.
tools
.
zip
.
ZipEntry
zipEnt
=
(
ZipEntry
)
e
.
nextElement
();
gbkPath
=
zipEnt
.
getName
();
if
(
zipEnt
.
isDirectory
())
{
strtemp
=
strPath
+
File
.
separator
+
gbkPath
;
File
dir
=
new
File
(
strtemp
);
dir
.
mkdirs
();
continue
;
}
else
{
//读写文件
InputStream
is
=
zipFile
.
getInputStream
(
zipEnt
);
BufferedInputStream
bis
=
new
BufferedInputStream
(
is
);
gbkPath
=
zipEnt
.
getName
();
strtemp
=
strPath
+
File
.
separator
+
gbkPath
;
//建目录
String
strsubdir
=
gbkPath
;
for
(
int
i
=
0
;
i
<
strsubdir
.
length
();
i
++)
{
if
(
strsubdir
.
substring
(
i
,
i
+
1
).
equalsIgnoreCase
(
"/"
))
{
String
temp
=
strPath
+
File
.
separator
+
strsubdir
.
substring
(
0
,
i
);
File
subdir
=
new
File
(
temp
);
if
(!
subdir
.
exists
())
subdir
.
mkdir
();
}
}
FileOutputStream
fos
=
new
FileOutputStream
(
strtemp
);
BufferedOutputStream
bos
=
new
BufferedOutputStream
(
fos
);
int
c
;
while
((
c
=
bis
.
read
())
!=
-
1
)
{
bos
.
write
((
byte
)
c
);
}
bos
.
close
();
fos
.
close
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
/**
* 压缩zip格式的压缩文件
*
* @param inputFilename 压缩的文件或文件夹及详细路径
* @param zipFilename 输出文件名称及详细路径
* @throws IOException
*/
public
synchronized
void
zip
(
String
inputFilename
,
String
zipFilename
)
throws
IOException
{
zip
(
new
File
(
inputFilename
),
zipFilename
);
}
/**
* 压缩zip格式的压缩文件
*
* @param inputFile 需压缩文件
* @param zipFilename 输出文件及详细路径
* @throws IOException
*/
public
synchronized
void
zip
(
File
inputFile
,
String
zipFilename
)
throws
IOException
{
ZipOutputStream
out
=
new
ZipOutputStream
(
new
FileOutputStream
(
zipFilename
));
try
{
zip
(
inputFile
,
out
,
""
);
}
catch
(
IOException
e
)
{
throw
e
;
throw
new
RuntimeException
(
"unzip error from ZipUtils"
,
e
);
}
finally
{
out
.
close
();
}
}
/**
* 压缩zip格式的压缩文件
*
* @param inputFile 需压缩文件
* @param out 输出压缩文件
* @param base 结束标识
* @throws IOException
*/
@SuppressWarnings
(
"unused"
)
private
synchronized
void
zip
(
File
inputFile
,
ZipOutputStream
out
,
String
base
)
throws
IOException
{
if
(
inputFile
.
isDirectory
())
{
File
[]
inputFiles
=
inputFile
.
listFiles
();
out
.
putNextEntry
(
new
ZipEntry
(
base
+
"/"
));
base
=
base
.
length
()
==
0
?
""
:
base
+
"/"
;
for
(
int
i
=
0
;
i
<
inputFiles
.
length
;
i
++)
{
zip
(
inputFiles
[
i
],
out
,
base
+
inputFiles
[
i
].
getName
());
}
}
else
{
if
(
base
.
length
()
>
0
)
{
out
.
putNextEntry
(
new
ZipEntry
(
base
));
}
else
{
out
.
putNextEntry
(
new
ZipEntry
(
inputFile
.
getName
()));
}
FileInputStream
in
=
new
FileInputStream
(
inputFile
);
if
(
zipFile
!=
null
){
try
{
int
c
;
byte
[]
by
=
new
byte
[
BUFFEREDSIZE
];
while
((
c
=
in
.
read
(
by
))
!=
-
1
)
{
out
.
write
(
by
,
0
,
c
);
}
zipFile
.
close
();
}
catch
(
IOException
e
)
{
throw
e
;
}
finally
{
in
.
close
();
e
.
printStackTrace
();
}
}
}
/**
* 解压tar格式的压缩文件到指定目录下
*
* @param tarFileName 压缩文件
* @param extPlace 解压目录
* @throws Exception
*/
public
synchronized
void
untar
(
String
tarFileName
,
String
extPlace
)
throws
Exception
{
}
/**
* 压缩tar格式的压缩文件
*
* @param inputFilename 压缩文件
* @param tarFilename 输出路径
* @throws IOException
*/
public
synchronized
void
tar
(
String
inputFilename
,
String
tarFilename
)
throws
IOException
{
tar
(
new
File
(
inputFilename
),
tarFilename
);
}
public
static
void
main
(
String
[]
args
)
{
/**
* 压缩tar格式的压缩文件
*
* @param inputFile 压缩文件
* @param tarFilename 输出路径
* @throws IOException
*/
public
synchronized
void
tar
(
File
inputFile
,
String
tarFilename
)
throws
IOException
{
TarOutputStream
out
=
new
TarOutputStream
(
new
FileOutputStream
(
tarFilename
));
String
filePath
=
"C:\\Users\\wyl\\Desktop\\alllib.zip"
;
String
path
=
"C:\\Users\\wyl\\Desktop\\unZip"
;
try
{
tar
(
inputFile
,
out
,
""
);
}
catch
(
IOException
e
)
{
throw
e
;
}
finally
{
out
.
close
();
}
}
/**
* 压缩tar格式的压缩文件
*
* @param inputFile 压缩文件
* @param out 输出文件
* @param base 结束标识
* @throws IOException
*/
@SuppressWarnings
(
"unused"
)
private
synchronized
void
tar
(
File
inputFile
,
TarOutputStream
out
,
String
base
)
throws
IOException
{
if
(
inputFile
.
isDirectory
())
{
File
[]
inputFiles
=
inputFile
.
listFiles
();
out
.
putNextEntry
(
new
TarEntry
(
base
+
"/"
));
base
=
base
.
length
()
==
0
?
""
:
base
+
"/"
;
for
(
int
i
=
0
;
i
<
inputFiles
.
length
;
i
++)
{
tar
(
inputFiles
[
i
],
out
,
base
+
inputFiles
[
i
].
getName
());
}
}
else
{
if
(
base
.
length
()
>
0
)
{
out
.
putNextEntry
(
new
TarEntry
(
base
));
}
else
{
out
.
putNextEntry
(
new
TarEntry
(
inputFile
.
getName
()));
}
FileInputStream
in
=
new
FileInputStream
(
inputFile
);
try
{
int
c
;
byte
[]
by
=
new
byte
[
BUFFEREDSIZE
];
while
((
c
=
in
.
read
(
by
))
!=
-
1
)
{
out
.
write
(
by
,
0
,
c
);
}
}
catch
(
IOException
e
)
{
throw
e
;
}
finally
{
in
.
close
();
}
unZip
(
new
File
(
filePath
),
path
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/* <!-- ant -->
maven 坐标
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.9.7</version>
</dependency>
*/
}
src/main/java/com/zjty/adaptationmaster/utils/FileZip.java
0 → 100644
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
.
utils
;
import
java.io.*
;
import
java.nio.charset.Charset
;
import
java.util.Enumeration
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
public
class
FileZip
{
public
static
void
unZipFiles
(
File
zipFile
,
String
descDir
)
throws
IOException
{
File
pathFile
=
new
File
(
descDir
);
if
(!
pathFile
.
exists
())
{
pathFile
.
mkdirs
();
}
//解决zip文件中有中文目录或者中文文件
ZipFile
zip
=
new
ZipFile
(
zipFile
,
Charset
.
forName
(
"GBK"
));
for
(
Enumeration
entries
=
zip
.
entries
();
entries
.
hasMoreElements
();)
{
ZipEntry
entry
=
(
ZipEntry
)
entries
.
nextElement
();
String
zipEntryName
=
entry
.
getName
();
InputStream
in
=
zip
.
getInputStream
(
entry
);
String
outPath
=
(
descDir
+
zipEntryName
).
replaceAll
(
"\\*"
,
"/"
);;
//判断路径是否存在,不存在则创建文件路径
File
file
=
new
File
(
outPath
.
substring
(
0
,
outPath
.
lastIndexOf
(
'/'
)));
if
(!
file
.
exists
())
{
file
.
mkdirs
();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if
(
new
File
(
outPath
).
isDirectory
())
{
continue
;
}
//输出文件路径信息
System
.
out
.
println
(
outPath
);
OutputStream
out
=
new
FileOutputStream
(
outPath
);
byte
[]
buf1
=
new
byte
[
1024
];
int
len
;
while
((
len
=
in
.
read
(
buf1
))>
0
)
{
out
.
write
(
buf1
,
0
,
len
);
}
in
.
close
();
out
.
close
();
}
zip
.
close
();
//**原博忘记关了,所以我在做完这些操作后想要删除文件时,一直已占用,必须关掉服务器才可以**
System
.
out
.
println
(
"******************解压完毕********************"
);
}
}
src/main/java/com/zjty/adaptationmaster/utils/Regular.java
浏览文件 @
0d7f231f
...
...
@@ -235,8 +235,8 @@ public class Regular {
* 大小写都替换
*/
public
static
String
replaceLowerAndUpper
(
String
s
,
String
upper
,
String
replacement
){
s
=
s
.
replace
All
(
upper
,
replacement
);
s
=
s
.
replace
All
(
upper
.
toLowerCase
(),
replacement
);
s
=
s
.
replace
(
upper
,
replacement
);
s
=
s
.
replace
(
upper
.
toLowerCase
(),
replacement
);
return
s
;
}
...
...
@@ -289,6 +289,6 @@ public class Regular {
public
static
void
main
(
String
[]
args
)
{
mySqlRegular
(
"
C:\\Users\\admin\\Desktop\\database\\new_debug.sql"
,
"new_debug
"
);
mySqlRegular
(
"
D:\\sqlFile\\uploads\\63c6e098-73fd-4999-b289-b3d120a07e87.sql"
,
"test11111
"
);
}
}
src/test/java/com/zjty/adaptationmaster/Test4.java
浏览文件 @
0d7f231f
package
com
.
zjty
.
adaptationmaster
;
import
com.zjty.adaptationmaster.adaptor.entity.db.DBManage
;
import
com.zjty.adaptationmaster.utils.Regular
;
import
org.postgresql.copy.CopyManager
;
import
org.postgresql.core.BaseConnection
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
public
class
Test4
{
public
static
void
main
(
String
[]
args
)
{
String
s
=
"123)456)789)0"
;
String
[]
array
=
s
.
split
(
"\\)"
);
for
(
String
si:
array
){
System
.
out
.
println
(
si
);
}
String
s
=
"\"record_alarm\" bit(1) DEFAULT NULL,"
;
System
.
out
.
println
(
s
.
replaceAll
(
"bit(1)"
,
"boolean"
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论