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
f6562d2b
Commit
f6562d2b
authored
Nov 12, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
参数处理
parent
7b6b23da
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+0
-2
YzgFileService.java
.../main/java/com/yanzuoguang/cloud/file/YzgFileService.java
+12
-0
HttpFileHelper.java
...ain/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
+5
-0
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+25
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
f6562d2b
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.HttpCodeException
;
import
com.yanzuoguang.util.thread.ProcessData
;
import
com.yanzuoguang.util.thread.RunProcess
;
import
javax.xml.ws.http.HTTPException
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileService.java
View file @
f6562d2b
...
...
@@ -2,6 +2,9 @@ package com.yanzuoguang.cloud.file;
import
com.yanzuoguang.cloud.file.vo.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* 文件上传路径
*
...
...
@@ -24,6 +27,15 @@ public interface YzgFileService {
*/
void
removeTempFolder
(
String
tempFolder
);
/**
* 下载文件
*
* @param fromUrl 服务其文件路径
* @param response 输出流
* @throws IOException
*/
void
down
(
String
fromUrl
,
HttpServletResponse
response
)
throws
IOException
;
/**
* 移动文件或文件夹
*
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
View file @
f6562d2b
package
com
.
yanzuoguang
.
cloud
.
helper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -25,6 +26,10 @@ public class HttpFileHelper extends HttpHelper {
public
static
void
localToDown
(
String
serverFilePath
,
String
saveFileName
,
HttpServletResponse
response
)
throws
IOException
{
//获取文件的长度
File
file
=
new
File
(
serverFilePath
);
if
(
StringHelper
.
isEmpty
(
saveFileName
))
{
File
parentFile
=
file
.
getParentFile
();
saveFileName
=
StringHelper
.
trimLeft
(
file
.
getAbsolutePath
().
substring
(
parentFile
.
getAbsolutePath
().
length
()),
"/"
);
}
//设置文件输出类型
response
.
setContentType
(
"application/octet-stream"
);
...
...
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
f6562d2b
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.cloud.file.vo.*
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.util.MediaHelper
;
import
com.yanzuoguang.util.MediaParameter
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
javax.servlet.http.HttpServletResponse
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -116,6 +119,28 @@ public class YzgFileServiceImpl implements YzgFileService {
}
}
/**
* 下载文件
*
* @param fromUrl
* @param response
*/
@Override
public
void
down
(
String
fromUrl
,
HttpServletResponse
response
)
throws
IOException
{
checkFolder
(
fromUrl
);
String
fromFullUrl
=
fileConfig
.
getServerFullPath
(
fromUrl
);
// 父文件夹不存在子文件时则删除
File
file
=
new
File
(
fromFullUrl
);
if
(
file
.
exists
())
{
throw
new
CodeException
(
"文件不存在"
);
}
if
(
file
.
isDirectory
())
{
throw
new
CodeException
(
"文件是目录"
);
}
HttpFileHelper
.
localToDown
(
fromFullUrl
,
StringHelper
.
EMPTY
,
response
);
}
/**
* 移动文件或文件夹
*
...
...
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