Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
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
曲欣亮
common
Commits
2c952ff3
Commit
2c952ff3
authored
Aug 01, 2018
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file转换 和 设置contentType
parent
4e86aaf4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
FileUtil.java
src/main/java/com/egolm/common/FileUtil.java
+27
-0
HttpUtil.java
src/main/java/com/egolm/common/HttpUtil.java
+2
-3
No files found.
src/main/java/com/egolm/common/FileUtil.java
View file @
2c952ff3
...
@@ -13,6 +13,7 @@ import java.io.IOException;
...
@@ -13,6 +13,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.OutputStreamWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.Writer
;
import
java.io.Writer
;
...
@@ -546,4 +547,30 @@ public class FileUtil {
...
@@ -546,4 +547,30 @@ public class FileUtil {
return
!
new
File
(
jspname
).
exists
();
return
!
new
File
(
jspname
).
exists
();
}
}
/**
*
* @Title: inputStreamToFile
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param ins
* @param: @param file
* @return: void
* @throws
*/
public
static
void
inputStreamToFile
(
InputStream
ins
,
File
file
)
{
try
{
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
ins
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
os
.
close
();
ins
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
\ No newline at end of file
src/main/java/com/egolm/common/HttpUtil.java
View file @
2c952ff3
...
@@ -219,7 +219,7 @@ public class HttpUtil {
...
@@ -219,7 +219,7 @@ public class HttpUtil {
}
}
public
static
String
post
(
String
requestUrl
,
Map
<
String
,
Object
>
parameters
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
File
>
attachments
)
{
public
static
String
post
(
String
requestUrl
,
Map
<
String
,
Object
>
parameters
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
File
>
attachments
,
String
contentType
)
{
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
try
{
try
{
Data
data
=
new
Data
();
Data
data
=
new
Data
();
...
@@ -233,7 +233,6 @@ public class HttpUtil {
...
@@ -233,7 +233,6 @@ public class HttpUtil {
ParamBuffer
.
append
(
parameters
.
get
(
key
)
+
"\r\n"
);
ParamBuffer
.
append
(
parameters
.
get
(
key
)
+
"\r\n"
);
}
}
}
}
//ParamBuffer.append("--" + BOUNDARY + "\r\nContent-Disposition: form-data; name=\"----------------------------------\"\r\n\r\n-------------------------\r\n");
String
ParamBufferString
=
ParamBuffer
.
toString
();
String
ParamBufferString
=
ParamBuffer
.
toString
();
data
.
add
(
ParamBufferString
.
getBytes
());
data
.
add
(
ParamBufferString
.
getBytes
());
if
(
attachments
!=
null
)
{
if
(
attachments
!=
null
)
{
...
@@ -242,7 +241,7 @@ public class HttpUtil {
...
@@ -242,7 +241,7 @@ public class HttpUtil {
File
file
=
attachments
.
get
(
name
);
File
file
=
attachments
.
get
(
name
);
FileBuffer
.
append
(
"--"
+
BOUNDARY
+
"\r\n"
);
FileBuffer
.
append
(
"--"
+
BOUNDARY
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Disposition: form-data; name=\""
+
name
+
"\"; filename=\""
+
file
.
getName
()
+
"\""
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Disposition: form-data; name=\""
+
name
+
"\"; filename=\""
+
file
.
getName
()
+
"\""
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Type:
application/octet-stream
"
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Type:
"
+
contentType
+
"
"
+
"\r\n"
);
FileBuffer
.
append
(
"\r\n"
);
FileBuffer
.
append
(
"\r\n"
);
String
FileBufferString
=
FileBuffer
.
toString
();
String
FileBufferString
=
FileBuffer
.
toString
();
data
.
add
(
FileBufferString
.
getBytes
());
data
.
add
(
FileBufferString
.
getBytes
());
...
...
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