Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
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
邬友楠
test
Commits
d4c55cc3
Commit
d4c55cc3
authored
Aug 21, 2019
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CommonController - 添加文件输出拦截器
parent
3b97cf3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
22 deletions
+10
-22
CommonController.java
...rc/main/java/com/huigou/uasp/client/CommonController.java
+10
-22
No files found.
huigou-uasp/src/main/java/com/huigou/uasp/client/CommonController.java
View file @
d4c55cc3
package
com
.
huigou
.
uasp
.
client
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.RandomAccessFile
;
import
java.io.*
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
...
...
@@ -22,6 +17,7 @@ import org.activiti.engine.ActivitiException;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.apache.commons.io.IOUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -452,31 +448,23 @@ public class CommonController extends ControllerBase {
*/
protected
String
outputFile
(
File
file
,
String
type
)
throws
Exception
{
HttpServletResponse
res
=
this
.
getResponse
();
ServletOutputStream
out
=
null
;
res
.
setContentType
(
ContentTypeHelper
.
getContentType
(
type
));
res
.
setCharacterEncoding
(
"utf-8"
);
res
.
setHeader
(
"Content-Disposition"
,
"inline;fileName="
+
System
.
currentTimeMillis
()
+
"."
+
type
+
""
);
BufferedInputStream
b
is
=
null
;
BufferedOutputStream
bos
=
null
;
InputStream
is
=
null
;
ServletOutputStream
out
=
null
;
try
{
is
=
outputFileInterceptor
!=
null
?
outputFileInterceptor
.
intercept
(
new
FileInputStream
(
file
),
type
,
this
)
:
new
FileInputStream
(
file
);
out
=
res
.
getOutputStream
();
bis
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
if
(
outputFileInterceptor
!=
null
)
{
bis
=
new
BufferedInputStream
(
outputFileInterceptor
.
intercept
(
bis
,
type
,
this
));
}
bos
=
new
BufferedOutputStream
(
out
);
byte
[]
buff
=
new
byte
[
2048
];
int
bytesRead
;
while
(-
1
!=
(
bytesRead
=
bis
.
read
(
buff
,
0
,
buff
.
length
)))
{
bos
.
write
(
buff
,
0
,
bytesRead
);
}
IOUtils
.
copy
(
is
,
out
);
res
.
flushBuffer
();
}
catch
(
final
Exception
e
)
{
throw
new
ApplicationException
(
e
);
}
finally
{
if
(
bis
!=
null
)
bis
.
close
();
if
(
bos
!=
null
)
bos
.
close
();
if
(
out
!=
null
)
out
.
close
();
IOUtils
.
closeQuietly
(
is
);
IOUtils
.
closeQuietly
(
out
);
}
return
null
;
}
...
...
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