Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YeeAmosFireAutoSysRoot
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
station
YeeAmosFireAutoSysRoot
Commits
c2e52969
Commit
c2e52969
authored
Apr 15, 2024
by
张森
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unreleased Resource: Streams(未出租的资源:流) 问题修复
parent
fd5cd3e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
76 deletions
+34
-76
FileController.java
.../yeejoin/amos/fas/business/controller/FileController.java
+6
-3
WeatherController.java
...ejoin/amos/fas/business/controller/WeatherController.java
+20
-47
FileHelper.java
...n/java/com/yeejoin/amos/fas/business/util/FileHelper.java
+8
-26
No files found.
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/controller/FileController.java
View file @
c2e52969
...
...
@@ -16,6 +16,7 @@ import org.springframework.context.annotation.Lazy;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
...
...
@@ -133,9 +134,11 @@ public class FileController extends BaseController {
@Permission
@RequestMapping
(
value
=
"/download/**"
,
method
=
RequestMethod
.
GET
)
public
void
download
(
HttpServletResponse
response
,
HttpServletRequest
request
)
throws
Exception
{
try
{
String
path
=
request
.
getServletPath
().
substring
(
15
);
IOUtils
.
copy
(
new
FileInputStream
(
fileUploadDir
+
path
),
response
.
getOutputStream
());
String
path
=
request
.
getServletPath
().
substring
(
15
);
try
(
FileInputStream
inputStream
=
new
FileInputStream
(
fileUploadDir
+
path
);
ServletOutputStream
outputStream
=
response
.
getOutputStream
();)
{
IOUtils
.
copy
(
inputStream
,
outputStream
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
ResponseUtils
.
renderText
(
response
,
"File not exists!"
);
...
...
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/controller/WeatherController.java
View file @
c2e52969
package
com
.
yeejoin
.
amos
.
fas
.
business
.
controller
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.zip.GZIPInputStream
;
...
...
@@ -31,64 +33,35 @@ public class WeatherController extends BaseController {
@Permission
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"天气查询"
,
notes
=
"天气查询"
)
@GetMapping
(
"/{address}"
)
public
CommonResponse
getWeather
(
@PathVariable
(
"address"
)
String
address
)
{
public
CommonResponse
getWeather
(
@PathVariable
(
"address"
)
String
address
)
throws
IOException
{
String
urlNameString
=
weatherUrl
+
address
;
URL
realUrl
=
new
URL
(
urlNameString
);
// 打开和URL之间的连接
URLConnection
connection
=
realUrl
.
openConnection
();
// 设置通用的请求属性
connection
.
setRequestProperty
(
"Accept"
,
"*/*"
);
connection
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip, deflate, br"
);
connection
.
setUseCaches
(
false
);
// 建立实际的连接
connection
.
connect
();
String
result
=
""
;
BufferedReader
in
=
null
;
BufferedReader
responseReader
=
null
;
InputStreamReader
res
=
null
;
try
{
String
urlNameString
=
weatherUrl
+
address
;
URL
realUrl
=
new
URL
(
urlNameString
);
// 打开和URL之间的连接
URLConnection
connection
=
realUrl
.
openConnection
();
// 设置通用的请求属性
connection
.
setRequestProperty
(
"Accept"
,
"*/*"
);
connection
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
// connection.setRequestProperty("Charset", "utf-8");
connection
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip, deflate, br"
);
connection
.
setUseCaches
(
false
);
// 建立实际的连接
connection
.
connect
();
try
(
GZIPInputStream
gZipS
=
new
GZIPInputStream
(
connection
.
getInputStream
());
InputStreamReader
res
=
new
InputStreamReader
(
gZipS
,
"UTF-8"
);
BufferedReader
responseReader
=
new
BufferedReader
(
res
);
)
{
StringBuffer
sb
=
new
StringBuffer
();
String
readLine
=
new
String
();
GZIPInputStream
gZipS
=
new
GZIPInputStream
(
connection
.
getInputStream
());
res
=
new
InputStreamReader
(
gZipS
,
"UTF-8"
);
responseReader
=
new
BufferedReader
(
res
);
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
sb
.
append
(
readLine
);
}
result
=
sb
.
toString
();
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送GET请求出现异常!"
+
e
);
return
CommonResponseUtil
.
failure
(
e
.
getMessage
());
}
// 使用finally块来关闭输入流
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
if
(
null
!=
responseReader
)
{
responseReader
.
close
();
}
if
(
null
!=
res
)
{
res
.
close
();
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
}
return
CommonResponseUtil
.
success
(
JSONObject
.
parse
(
result
));
}
...
...
YeeAmosFireAutoSysService/src/main/java/com/yeejoin/amos/fas/business/util/FileHelper.java
View file @
c2e52969
...
...
@@ -265,36 +265,18 @@ public class FileHelper {
* @param path 写入内容的文件路径
*/
public
static
void
writeFile
(
String
content
,
String
path
)
{
OutputStream
fos
=
null
;
BufferedWriter
bw
=
null
;
OutputStreamWriter
outputStreamWriter
=
null
;
try
{
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
try
(
OutputStream
fos
=
new
FileOutputStream
(
file
);
OutputStreamWriter
outputStreamWriter
=
new
OutputStreamWriter
(
fos
,
"UTF-8"
);
BufferedWriter
bw
=
new
BufferedWriter
(
outputStreamWriter
);
)
{
if
(!
file
.
getParentFile
().
exists
())
{
file
.
getParentFile
().
mkdirs
();
}
fos
=
new
FileOutputStream
(
file
);
outputStreamWriter
=
new
OutputStreamWriter
(
fos
,
"UTF-8"
);
bw
=
new
BufferedWriter
(
outputStreamWriter
);
bw
.
write
(
content
);
}
catch
(
FileNotFoundException
fnfe
)
{
fnfe
.
printStackTrace
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
finally
{
try
{
if
(
null
!=
bw
)
{
bw
.
close
();
}
if
(
null
!=
fos
)
{
fos
.
close
();
}
if
(
null
!=
outputStreamWriter
)
{
outputStreamWriter
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
...
...
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