package com.supwisdom.dlpay.framework.util;
+
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.beanutils.BeanUtils;
public class StringUtil {
/**
}*/
return true;
}
+
/**
* 手机号遮掩中间4位
- * */
- public static String phoneReplace(String phone){
+ */
+ public static String phoneReplace(String phone) {
return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}
/**
* 邮箱只显示@前面的首位和末位
- * */
- public static String emailReplace(String s){
- return s.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)", "$1****$3$4");
+ */
+ public static String emailReplace(String s) {
+ return s.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)", "$1****$3$4");
}
/**
* 名字显示姓
- * */
- public static String nameReplace(String s){
- return s.replaceAll("([\\d\\D]{1})(.*)", "$1**");
+ */
+ public static String nameReplace(String s) {
+ return s.replaceAll("([\\d\\D]{1})(.*)", "$1**");
}
- public static String urlAppend(String url ,String path){
- if(url.endsWith("/")){
- if(path.startsWith("/")){
- return url+path.substring(1);
+ public static String urlAppend(String url, String path) {
+ if (url.endsWith("/")) {
+ if (path.startsWith("/")) {
+ return url + path.substring(1);
}
- return url+path;
- }else{
- if(path.startsWith("/")){
- return url+path;
+ return url + path;
+ } else {
+ if (path.startsWith("/")) {
+ return url + path;
}
- return url+"/"+path;
+ return url + "/" + path;
}
}
for (int i = 0; i < fields.size(); i++) {
data.put(fields.get(i), columns.get(i));
}
- BeanUtils.populate(bean, data);
- return;
+ org.apache.commons.beanutils.BeanUtils.populate(bean, data);
}
}
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import javax.servlet.http.HttpServletResponse;
+import javax.validation.constraints.NotNull;
import javax.ws.rs.FormParam;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
}
@GetMapping("/download")
- public void downloadFile(@RequestParam("filename") String filename, HttpServletResponse response) throws IOException {
- try {
- String loaclfile = ynrccApiService.getChkfilePath(filename);
- parseFile(loaclfile, response.getOutputStream());
- } catch (Exception e) {
- e.printStackTrace();
- response.sendError(HttpStatus.SERVICE_UNAVAILABLE.value(), e.getMessage());
- }
+ public ResponseEntity<StreamingResponseBody> downloadFile(@RequestParam("filename") String filename,
+ HttpServletResponse response) throws Exception {
+ response.setContentType(MediaType.TEXT_PLAIN_VALUE);
+ String loaclfile = ynrccApiService.getChkfilePath(filename);
+// parseFile(loaclfile, response.getOutputStream());
+ StreamingResponseBody stream = new StreamingResponseBody() {
+ @Override
+ public void writeTo(OutputStream outputStream) throws IOException {
+ parseFile(loaclfile, outputStream);
+ }
+ };
+ return new ResponseEntity(stream, HttpStatus.OK);
}
-
}