Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
f89af689
Commit
f89af689
authored
Apr 22, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩处理
parent
dd6816b1
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
477 additions
and
35 deletions
+477
-35
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+49
-4
ZipHelper.java
.../src/main/java/com/yanzuoguang/util/helper/ZipHelper.java
+319
-0
ProcessData.java
...rc/main/java/com/yanzuoguang/util/thread/ProcessData.java
+91
-0
RunProcess.java
...src/main/java/com/yanzuoguang/util/thread/RunProcess.java
+14
-0
HttpFileHelper.java
...ain/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
+4
-31
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
f89af689
...
@@ -2,12 +2,14 @@ package com.yanzuoguang.util.helper;
...
@@ -2,12 +2,14 @@ package com.yanzuoguang.util.helper;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.thread.ProcessData
;
import
com.yanzuoguang.util.thread.RunProcess
;
import
java.io.BufferedReader
;
import
java.io.*
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
/**
/**
* HTTP请求工具类
* HTTP请求工具类
...
@@ -112,4 +114,47 @@ public class HttpHelper {
...
@@ -112,4 +114,47 @@ public class HttpHelper {
}
}
return
result
;
return
result
;
}
}
/**
* 下载文件
*
* @param serverFileName 下载的服务器文件路径
* @param localFileName 保存的文件路径
* @throws IOException
*/
public
static
void
downToLocal
(
String
serverFileName
,
String
localFileName
)
throws
IOException
{
downToLocal
(
serverFileName
,
localFileName
,
null
);
}
/**
* 下载文件
*
* @param serverFileName 下载的服务器文件路径
* @param localFileName 保存的文件路径
* @param runProcess 进度处理
* @throws IOException
*/
public
static
void
downToLocal
(
String
serverFileName
,
String
localFileName
,
RunProcess
runProcess
)
throws
IOException
{
int
byteRead
;
URL
url
=
new
URL
(
serverFileName
);
URLConnection
conn
=
url
.
openConnection
();
InputStream
inStream
=
conn
.
getInputStream
();
try
{
ProcessData
data
=
new
ProcessData
(
serverFileName
,
conn
.
getContentLengthLong
());
FileOutputStream
outputStream
=
new
FileOutputStream
(
localFileName
);
try
{
byte
[]
buffer
=
new
byte
[
1204
];
while
((
byteRead
=
inStream
.
read
(
buffer
))
!=
-
1
)
{
data
.
processAdd
(
runProcess
,
byteRead
);
outputStream
.
write
(
buffer
,
0
,
byteRead
);
}
}
finally
{
outputStream
.
close
();
}
}
finally
{
inStream
.
close
();
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/ZipHelper.java
0 → 100644
View file @
f89af689
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ProcessData.java
0 → 100644
View file @
f89af689
package
com
.
yanzuoguang
.
util
.
thread
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.log.Log
;
/**
* 进度数据
*/
public
class
ProcessData
{
/**
* 目标
*/
private
String
target
;
/**
* 位置
*/
private
long
pos
;
/**
* 长度
*/
private
long
total
;
public
ProcessData
()
{
}
public
ProcessData
(
String
target
)
{
this
.
target
=
target
;
}
public
ProcessData
(
String
target
,
long
total
)
{
this
.
target
=
target
;
this
.
total
=
total
;
}
public
String
getTarget
()
{
return
target
;
}
public
void
setTarget
(
String
target
)
{
this
.
target
=
target
;
}
public
long
getPos
()
{
return
pos
;
}
public
void
setPos
(
long
pos
)
{
this
.
pos
=
pos
;
}
public
long
getTotal
()
{
return
total
;
}
public
void
setTotal
(
long
total
)
{
this
.
total
=
total
;
}
/**
* 进度调用
*
* @param runProcess
* @param pos
*/
public
void
processCall
(
RunProcess
runProcess
,
long
pos
)
{
this
.
pos
=
pos
;
if
(
runProcess
==
null
)
{
return
;
}
try
{
runProcess
.
execute
(
this
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
HttpHelper
.
class
,
ex
);
}
}
/**
* 进度调用
*
* @param runProcess 运行进度
* @param add 需要添加的量
*/
public
void
processAdd
(
RunProcess
runProcess
,
long
add
)
{
this
.
pos
+=
add
;
this
.
processCall
(
runProcess
,
this
.
pos
);
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunProcess.java
0 → 100644
View file @
f89af689
package
com
.
yanzuoguang
.
util
.
thread
;
/**
* 运行进度处理
*/
public
interface
RunProcess
{
/**
* 进度信息
*
* @param data
*/
void
execute
(
ProcessData
data
);
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
View file @
f89af689
package
com
.
yanzuoguang
.
cloud
.
helper
;
package
com
.
yanzuoguang
.
cloud
.
helper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.io.*
;
import
java.net.URL
;
import
java.net.URLConnection
;
/**
/**
* HTTP文件
* HTTP文件
*/
*/
public
class
HttpFileHelper
{
public
class
HttpFileHelper
extends
HttpHelper
{
/**
* 下载文件
*
* @param serverFileName 下载的服务器文件路径
* @param localFileName 保存的文件路径
* @throws IOException
*/
public
static
void
downToLocal
(
String
serverFileName
,
String
localFileName
)
throws
IOException
{
int
byteRead
;
URL
url
=
new
URL
(
serverFileName
);
URLConnection
conn
=
url
.
openConnection
();
InputStream
inStream
=
conn
.
getInputStream
();
try
{
FileOutputStream
outputStream
=
new
FileOutputStream
(
localFileName
);
try
{
byte
[]
buffer
=
new
byte
[
1204
];
while
((
byteRead
=
inStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
byteRead
);
}
}
finally
{
outputStream
.
close
();
}
}
finally
{
inStream
.
close
();
}
}
/**
/**
* 下载文件
* 下载文件
...
...
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