Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
solo-1
Commits
4d4c1844
Unverified
Commit
4d4c1844
authored
Apr 05, 2018
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
使用 try-with-resources 关闭 IO 流
parent
0e29d32a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
74 deletions
+62
-74
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
+8
-11
src/main/java/org/b3log/solo/processor/FileUploadProcessor.java
...in/java/org/b3log/solo/processor/FileUploadProcessor.java
+9
-10
src/main/java/org/b3log/solo/processor/console/AdminConsole.java
...n/java/org/b3log/solo/processor/console/AdminConsole.java
+31
-38
src/main/java/org/b3log/solo/util/Markdowns.java
src/main/java/org/b3log/solo/util/Markdowns.java
+14
-15
No files found.
src/main/java/org/b3log/solo/processor/CaptchaProcessor.java
View file @
4d4c1844
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
*/
*/
package
org
.
b3log
.
solo
.
processor
;
package
org
.
b3log
.
solo
.
processor
;
import
org.apache.commons.io.IOUtils
;
import
org.b3log.latke.image.Image
;
import
org.b3log.latke.image.Image
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.logging.Logger
;
...
@@ -43,7 +42,7 @@ import java.util.Set;
...
@@ -43,7 +42,7 @@ import java.util.Set;
* Captcha processor.
* Captcha processor.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.
0, Feb 13
, 2018
* @version 2.0.0.
1, Apr 5
, 2018
* @since 0.3.1
* @since 0.3.1
*/
*/
@RequestProcessor
@RequestProcessor
...
@@ -108,15 +107,13 @@ public class CaptchaProcessor {
...
@@ -108,15 +107,13 @@ public class CaptchaProcessor {
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setDateHeader
(
"Expires"
,
0
);
response
.
setDateHeader
(
"Expires"
,
0
);
final
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
try
(
final
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
())
{
ImageIO
.
write
(
bufferedImage
,
"png"
,
baos
);
ImageIO
.
write
(
bufferedImage
,
"png"
,
baos
);
final
byte
[]
data
=
baos
.
toByteArray
();
final
byte
[]
data
=
baos
.
toByteArray
();
IOUtils
.
closeQuietly
(
baos
);
final
Image
captchaImg
=
new
Image
();
final
Image
captchaImg
=
new
Image
();
captchaImg
.
setData
(
data
);
captchaImg
.
setData
(
data
);
renderer
.
setImage
(
captchaImg
);
renderer
.
setImage
(
captchaImg
);
}
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
}
}
...
...
src/main/java/org/b3log/solo/processor/FileUploadProcessor.java
View file @
4d4c1844
...
@@ -53,7 +53,7 @@ import java.util.*;
...
@@ -53,7 +53,7 @@ import java.util.*;
* File upload processor.
* File upload processor.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.
1, Mar 1
5, 2018
* @version 1.0.0.
2, Apr
5, 2018
* @since 2.8.0
* @since 2.8.0
*/
*/
@RequestProcessor
@RequestProcessor
...
@@ -131,11 +131,10 @@ public class FileUploadProcessor {
...
@@ -131,11 +131,10 @@ public class FileUploadProcessor {
return
;
return
;
}
}
final
OutputStream
output
=
resp
.
getOutputStream
();
try
(
final
OutputStream
output
=
resp
.
getOutputStream
())
{
IOUtils
.
write
(
data
,
output
);
IOUtils
.
write
(
data
,
output
);
output
.
flush
();
output
.
flush
();
}
IOUtils
.
closeQuietly
(
output
);
}
}
/**
/**
...
@@ -215,10 +214,10 @@ public class FileUploadProcessor {
...
@@ -215,10 +214,10 @@ public class FileUploadProcessor {
uploadManager
.
put
(
file
.
getFileInputStream
(),
fileName
,
uploadToken
,
null
,
contentType
);
uploadManager
.
put
(
file
.
getFileInputStream
(),
fileName
,
uploadToken
,
null
,
contentType
);
succMap
.
put
(
originalName
,
qiniu
.
optString
(
Option
.
ID_C_QINIU_DOMAIN
)
+
"/"
+
fileName
);
succMap
.
put
(
originalName
,
qiniu
.
optString
(
Option
.
ID_C_QINIU_DOMAIN
)
+
"/"
+
fileName
);
}
else
{
}
else
{
final
OutputStream
output
=
new
FileOutputStream
(
Solos
.
UPLOAD_DIR_PATH
+
fileName
);
try
(
final
OutputStream
output
=
new
FileOutputStream
(
Solos
.
UPLOAD_DIR_PATH
+
fileName
);
IOUtils
.
copy
(
file
.
getFileInputStream
(),
output
);
final
InputStream
input
=
file
.
getFileInputStream
())
{
IOUtils
.
closeQuietly
(
file
.
getFileInputStream
()
);
IOUtils
.
copy
(
input
,
output
);
IOUtils
.
closeQuietly
(
output
);
}
succMap
.
put
(
originalName
,
Latkes
.
getServePath
()
+
"/upload/"
+
fileName
);
succMap
.
put
(
originalName
,
Latkes
.
getServePath
()
+
"/upload/"
+
fileName
);
}
}
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
...
...
src/main/java/org/b3log/solo/processor/console/AdminConsole.java
View file @
4d4c1844
...
@@ -72,7 +72,7 @@ import java.util.*;
...
@@ -72,7 +72,7 @@ import java.util.*;
* Admin console render processing.
* Admin console render processing.
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.7.0.
1, Nov 20, 2017
* @version 1.7.0.
2, Apr 5, 2018
* @since 0.4.1
* @since 0.4.1
*/
*/
@RequestProcessor
@RequestProcessor
...
@@ -399,16 +399,15 @@ public class AdminConsole {
...
@@ -399,16 +399,15 @@ public class AdminConsole {
try
{
try
{
final
byte
[]
data
=
sql
.
getBytes
(
"UTF-8"
);
final
byte
[]
data
=
sql
.
getBytes
(
"UTF-8"
);
try
(
final
OutputStream
output
=
new
FileOutputStream
(
localFile
))
{
final
OutputStream
output
=
new
FileOutputStream
(
localFile
);
IOUtils
.
write
(
data
,
output
);
IOUtils
.
write
(
data
,
output
);
IOUtils
.
closeQuietly
(
output
);
}
final
File
zipFile
=
ZipUtil
.
zip
(
localFile
);
final
File
zipFile
=
ZipUtil
.
zip
(
localFile
);
byte
[]
zipData
;
final
FileInputStream
inputStream
=
new
FileInputStream
(
zipFile
);
try
(
final
FileInputStream
inputStream
=
new
FileInputStream
(
zipFile
))
{
final
byte
[]
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
IOUtils
.
closeQuietly
(
inputStream
);
}
response
.
setContentType
(
"application/zip"
);
response
.
setContentType
(
"application/zip"
);
final
String
fileName
=
"solo-sql-"
+
date
+
".zip"
;
final
String
fileName
=
"solo-sql-"
+
date
+
".zip"
;
...
@@ -455,24 +454,19 @@ public class AdminConsole {
...
@@ -455,24 +454,19 @@ public class AdminConsole {
final
JSONObject
json
=
exportService
.
getJSONs
();
final
JSONObject
json
=
exportService
.
getJSONs
();
final
byte
[]
data
=
json
.
toString
(
4
).
getBytes
(
"UTF-8"
);
final
byte
[]
data
=
json
.
toString
(
4
).
getBytes
(
"UTF-8"
);
final
OutputStream
output
=
new
FileOutputStream
(
localFile
);
try
(
final
OutputStream
output
=
new
FileOutputStream
(
localFile
))
{
IOUtils
.
write
(
data
,
output
);
IOUtils
.
write
(
data
,
output
);
IOUtils
.
closeQuietly
(
output
);
}
final
File
zipFile
=
ZipUtil
.
zip
(
localFile
);
final
FileInputStream
inputStream
=
new
FileInputStream
(
zipFile
);
try
(
final
FileInputStream
inputStream
=
new
FileInputStream
(
ZipUtil
.
zip
(
localFile
));
final
ServletOutputStream
outputStream
=
response
.
getOutputStream
())
{
final
byte
[]
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
final
byte
[]
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
IOUtils
.
closeQuietly
(
inputStream
);
response
.
setContentType
(
"application/zip"
);
response
.
setContentType
(
"application/zip"
);
final
String
fileName
=
"solo-json-"
+
date
+
".zip"
;
final
String
fileName
=
"solo-json-"
+
date
+
".zip"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
final
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
outputStream
.
write
(
zipData
);
outputStream
.
write
(
zipData
);
outputStream
.
flush
();
outputStream
.
flush
();
outputStream
.
close
();
}
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Export failed"
,
e
);
LOGGER
.
log
(
Level
.
ERROR
,
"Export failed"
,
e
);
context
.
renderJSON
().
renderMsg
(
"Export failed, please check log"
);
context
.
renderJSON
().
renderMsg
(
"Export failed, please check log"
);
...
@@ -530,19 +524,18 @@ public class AdminConsole {
...
@@ -530,19 +524,18 @@ public class AdminConsole {
exportHexoMd
(
drafts
,
draftDir
.
getPath
());
exportHexoMd
(
drafts
,
draftDir
.
getPath
());
final
File
zipFile
=
ZipUtil
.
zip
(
localFile
);
final
File
zipFile
=
ZipUtil
.
zip
(
localFile
);
byte
[]
zipData
;
final
FileInputStream
inputStream
=
new
FileInputStream
(
zipFile
);
try
(
final
FileInputStream
inputStream
=
new
FileInputStream
(
zipFile
))
{
final
byte
[]
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
zipData
=
IOUtils
.
toByteArray
(
inputStream
);
IOUtils
.
closeQuietly
(
inputStream
);
response
.
setContentType
(
"application/zip"
);
response
.
setContentType
(
"application/zip"
);
final
String
fileName
=
"solo-hexo-"
+
date
+
".zip"
;
final
String
fileName
=
"solo-hexo-"
+
date
+
".zip"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
}
final
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
try
(
final
ServletOutputStream
outputStream
=
response
.
getOutputStream
())
{
outputStream
.
write
(
zipData
);
outputStream
.
write
(
zipData
);
outputStream
.
flush
();
outputStream
.
flush
();
outputStream
.
close
();
}
}
catch
(
final
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Export failed"
,
e
);
LOGGER
.
log
(
Level
.
ERROR
,
"Export failed"
,
e
);
context
.
renderJSON
().
renderMsg
(
"Export failed, please check log"
);
context
.
renderJSON
().
renderMsg
(
"Export failed, please check log"
);
...
...
src/main/java/org/b3log/solo/util/Markdowns.java
View file @
4d4c1844
...
@@ -52,7 +52,7 @@ import java.util.concurrent.*;
...
@@ -52,7 +52,7 @@ import java.util.concurrent.*;
* </p>
* </p>
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.3.0.
7, Jan 13
, 2018
* @version 2.3.0.
8, Apr 5
, 2018
* @since 0.4.5
* @since 0.4.5
*/
*/
public
final
class
Markdowns
{
public
final
class
Markdowns
{
...
@@ -114,13 +114,14 @@ public final class Markdowns {
...
@@ -114,13 +114,14 @@ public final class Markdowns {
final
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
final
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setDoOutput
(
true
);
final
OutputStream
outputStream
=
conn
.
getOutputStream
();
try
(
final
OutputStream
outputStream
=
conn
.
getOutputStream
())
{
IOUtils
.
write
(
"Solo 大法好"
,
outputStream
,
"UTF-8"
);
IOUtils
.
write
(
"Solo 大法好"
,
outputStream
,
"UTF-8"
);
IOUtils
.
closeQuietly
(
outputStream
);
}
final
InputStream
inputStream
=
conn
.
getInputStream
();
String
html
;
final
String
html
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
try
(
final
InputStream
inputStream
=
conn
.
getInputStream
())
{
IOUtils
.
closeQuietly
(
inputStream
);
html
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
}
conn
.
disconnect
();
conn
.
disconnect
();
...
@@ -232,17 +233,15 @@ public final class Markdowns {
...
@@ -232,17 +233,15 @@ public final class Markdowns {
final
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
final
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setDoOutput
(
true
);
final
OutputStream
outputStream
=
conn
.
getOutputStream
();
String
ret
;
try
(
final
OutputStream
outputStream
=
conn
.
getOutputStream
();
final
InputStream
inputStream
=
conn
.
getInputStream
())
{
IOUtils
.
write
(
markdownText
,
outputStream
,
"UTF-8"
);
IOUtils
.
write
(
markdownText
,
outputStream
,
"UTF-8"
);
IOUtils
.
closeQuietly
(
outputStream
);
ret
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
}
final
InputStream
inputStream
=
conn
.
getInputStream
();
final
String
html
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
IOUtils
.
closeQuietly
(
inputStream
);
//conn.disconnect();
//conn.disconnect();
return
html
;
return
ret
;
}
}
/**
/**
...
...
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