mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-28 08:43:44 +00:00
修改代码规范
This commit is contained in:
+1
-1
@@ -169,7 +169,7 @@ public class ExceptionController extends AbstractErrorController {
|
||||
errorResult.setMessage(body.get("path").toString());
|
||||
} else { //非404处理
|
||||
Object object = request.getAttribute("javax.servlet.error.exception");
|
||||
if (object != null && object instanceof Exception) { //上下文中能拿到异常的情况
|
||||
if (object instanceof Exception) { //上下文中能拿到异常的情况
|
||||
Exception exception = (Exception) object;
|
||||
//ZuulException异常特殊处理,去除ZuulException的包裹 (不用instanceof的原因是不想因为这里的判断而引入zuul的依赖在core包中)
|
||||
if (exception.getClass().getName().equals("com.netflix.zuul.exception.ZuulException")) { //NOSONAR
|
||||
|
||||
@@ -82,11 +82,7 @@ public class ZipUtil {
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
private void decompressZip(File file, String saveFileDir) throws IOException {
|
||||
InputStream is = null;
|
||||
ZipArchiveInputStream zais = null;
|
||||
try { //NOSONAR
|
||||
is = new FileInputStream(file);
|
||||
zais = new ZipArchiveInputStream(is, this.encoding);
|
||||
try (InputStream is = new FileInputStream(file); ZipArchiveInputStream zais = new ZipArchiveInputStream(is, this.encoding)) { //NOSONAR
|
||||
ArchiveEntry archiveEntry;
|
||||
|
||||
// 把zip包中的每个文件读取出来
|
||||
@@ -108,13 +104,6 @@ public class ZipUtil {
|
||||
this.decompressZip(saveFileDir, archiveEntry, zais);
|
||||
|
||||
}
|
||||
} finally {
|
||||
if (zais != null) {
|
||||
zais.close();
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,20 +121,14 @@ public class ZipUtil {
|
||||
throws IOException {
|
||||
String entryFilePath = saveFileDir + archiveEntry.getName();
|
||||
byte[] content = new byte[BYTE_SIZE];
|
||||
OutputStream os = null;
|
||||
try { //NOSONAR
|
||||
File entryFile = new File(entryFilePath);
|
||||
try (OutputStream os = new FileOutputStream(entryFile)) { //NOSONAR
|
||||
// 把解压出来的文件写到指定路径
|
||||
File entryFile = new File(entryFilePath);
|
||||
os = new FileOutputStream(entryFile);
|
||||
int r;
|
||||
while ((r = zais.read(content)) > 0) {
|
||||
os.write(content, 0, r);
|
||||
}
|
||||
os.flush();
|
||||
} finally {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +143,8 @@ public class ZipUtil {
|
||||
*/
|
||||
public void compressFiles2Zip(File[] files, String zipFilePath) throws IOException {
|
||||
if (files != null && files.length > 0) {
|
||||
ZipArchiveOutputStream zaos = null;
|
||||
try { //NOSONAR
|
||||
File zipFile = new File(zipFilePath);
|
||||
zaos = new ZipArchiveOutputStream(zipFile);
|
||||
File zipFile = new File(zipFilePath);
|
||||
try (ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(zipFile)) { //NOSONAR
|
||||
|
||||
// 将每个文件用ZipArchiveEntry封装
|
||||
// 再用ZipArchiveOutputStream写到压缩文件中
|
||||
@@ -171,10 +152,6 @@ public class ZipUtil {
|
||||
this.compressFiles2Zip(file, zaos);
|
||||
}
|
||||
zaos.finish();
|
||||
} finally {
|
||||
if (zaos != null) {
|
||||
zaos.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -195,19 +172,13 @@ public class ZipUtil {
|
||||
if (file != null) {
|
||||
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, file.getName());
|
||||
zaos.putArchiveEntry(zipArchiveEntry);
|
||||
InputStream is = null;
|
||||
try { //NOSONAR
|
||||
is = new BufferedInputStream(new FileInputStream(file), ioBuffered);
|
||||
try (InputStream is = new BufferedInputStream(new FileInputStream(file), ioBuffered)) { //NOSONAR
|
||||
byte[] buffer = new byte[BYTE_SIZE];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
zaos.write(buffer, 0, len);
|
||||
}
|
||||
zaos.closeArchiveEntry();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,24 +107,13 @@ public class FileController implements IFileController {
|
||||
//输出文件
|
||||
final int buffInt = 1024;
|
||||
byte[] buff = new byte[buffInt];
|
||||
OutputStream os = null;
|
||||
BufferedInputStream bis = null;
|
||||
try { //NOSONAR
|
||||
os = response.getOutputStream();
|
||||
bis = new BufferedInputStream(fsr.getInputStream());
|
||||
try (OutputStream os = response.getOutputStream(); BufferedInputStream bis = new BufferedInputStream(fsr.getInputStream())) { //NOSONAR
|
||||
int i = bis.read(buff);
|
||||
while (i != -1) {
|
||||
os.write(buff, 0, buff.length);
|
||||
os.flush();
|
||||
i = bis.read(buff);
|
||||
}
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,20 +58,14 @@ public class QrcodeController implements IQrcodeController {
|
||||
//常量
|
||||
final String contentType = "image/png";
|
||||
//输出流
|
||||
OutputStream os = null;
|
||||
try {
|
||||
BufferedImage bufferedImage = this.qrcodeService.parseBufferedImage(qrCodeRequest);
|
||||
response.setContentType(contentType);
|
||||
response.setCharacterEncoding(applicationConfig.getEncoding());
|
||||
try (OutputStream os = response.getOutputStream()) {
|
||||
//设置response
|
||||
response.setCharacterEncoding(applicationConfig.getEncoding());
|
||||
response.setContentType(contentType);
|
||||
//生成二维码
|
||||
BufferedImage bufferedImage = this.qrcodeService.parseBufferedImage(qrCodeRequest);
|
||||
//输出
|
||||
os = response.getOutputStream();
|
||||
ImageIO.write(bufferedImage, QrCodeOptions.DEF_PIC_TYPE, os);
|
||||
} finally {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ public class ListenerService {
|
||||
String exceptionDetail = null;
|
||||
// 获得result
|
||||
Object o = context.getResult();
|
||||
if (null != o && o instanceof Map) {
|
||||
if (o instanceof Map) {
|
||||
Map<String, Object> result = (Map<String, Object>) o;
|
||||
status = result.get("status").toString();
|
||||
JobExecutionException jobException = (JobExecutionException) result.get("jobException");
|
||||
|
||||
+3
-9
@@ -78,18 +78,12 @@ public class WeixinMpConsont {
|
||||
*/
|
||||
public static Element formatInputMessage(String inputMsg) throws ParserConfigurationException, SAXException, IOException {
|
||||
//解析消息
|
||||
StringReader sr = null;
|
||||
try { //NOSONAR
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
sr = new StringReader(inputMsg);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
try (StringReader sr = new StringReader(inputMsg)) { //NOSONAR
|
||||
InputSource is = new InputSource(sr);
|
||||
Document document = db.parse(is);
|
||||
return document.getDocumentElement();
|
||||
} finally {
|
||||
if (sr != null) {
|
||||
sr.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user