Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
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
jenkins
slm-fileview
Commits
fb09a8c0
Commit
fb09a8c0
authored
Dec 10, 2020
by
13540823418
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容本地绝对路径文件读取,采用file标准协议读取文件
parent
4c708f3c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
35 deletions
+1
-35
DownloadUtils.java
...rter-web/src/main/java/cn/keking/utils/DownloadUtils.java
+1
-35
No files found.
jodconverter-web/src/main/java/cn/keking/utils/DownloadUtils.java
View file @
fb09a8c0
...
...
@@ -33,7 +33,6 @@ public class DownloadUtils {
private
static
final
String
URL_PARAM_FTP_USERNAME
=
"ftp.username"
;
private
static
final
String
URL_PARAM_FTP_PASSWORD
=
"ftp.password"
;
private
static
final
String
URL_PARAM_FTP_CONTROL_ENCODING
=
"ftp.control.encoding"
;
private
static
final
String
[]
URL_PARAM_LOCALURL_START
={
"c:"
,
"d:"
,
"e:"
,
"f:"
,
"g:"
,
"/"
};
/**
* @param fileAttribute fileAttribute
...
...
@@ -56,13 +55,8 @@ public class DownloadUtils {
dirFile
.
mkdirs
();
}
try
{
if
(
isLocalUrl
(
urlStr
)){
byte
[]
bytes
=
getBytesFromLocalUrl
(
urlStr
);
OutputStream
os
=
new
FileOutputStream
(
new
File
(
realPath
));
saveBytesToOutStream
(
bytes
,
os
);
}
else
{
URL
url
=
new
URL
(
urlStr
);
if
(
url
.
getProtocol
()
!=
null
&&
url
.
getProtocol
().
toLowerCase
().
startsWith
(
"http"
))
{
if
(
url
.
getProtocol
()
!=
null
&&
(
url
.
getProtocol
().
toLowerCase
().
startsWith
(
"file"
)||
url
.
getProtocol
().
toLowerCase
().
startsWith
(
"http"
)
))
{
byte
[]
bytes
=
getBytesFromUrl
(
urlStr
);
OutputStream
os
=
new
FileOutputStream
(
new
File
(
realPath
));
saveBytesToOutStream
(
bytes
,
os
);
...
...
@@ -76,7 +70,6 @@ public class DownloadUtils {
response
.
setContent
(
null
);
response
.
setMsg
(
"url不能识别url"
+
urlStr
);
}
}
response
.
setContent
(
realPath
);
response
.
setMsg
(
fileName
);
if
(
FileType
.
simText
.
equals
(
fileAttribute
.
getType
())){
...
...
@@ -111,21 +104,6 @@ public class DownloadUtils {
}
}
public
byte
[]
getBytesFromLocalUrl
(
String
urlStr
)
throws
IOException
{
File
file
=
new
File
(
urlStr
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
(
1024
);
byte
[]
b
=
new
byte
[
1024
];
int
n
;
while
((
n
=
fis
.
read
(
b
))
!=
-
1
)
{
bos
.
write
(
b
,
0
,
n
);
}
fis
.
close
();
byte
[]
data
=
bos
.
toByteArray
();
bos
.
close
();
return
data
;
}
public
void
saveBytesToOutStream
(
byte
[]
b
,
OutputStream
os
)
throws
IOException
{
os
.
write
(
b
);
os
.
close
();
...
...
@@ -195,16 +173,4 @@ public class DownloadUtils {
}
}
}
/**
* @param url url
* @return 是否是本地文件的绝对路径
*/
private
boolean
isLocalUrl
(
String
url
){
for
(
String
str:
URL_PARAM_LOCALURL_START
){
if
(
url
.
toLowerCase
().
startsWith
(
str
))
return
true
;
}
return
false
;
}
}
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