diff --git a/HelloAnnotation/db.sqlite3 b/HelloAnnotation/db.sqlite3
deleted file mode 100644
index 518cec9..0000000
Binary files a/HelloAnnotation/db.sqlite3 and /dev/null differ
diff --git a/HelloAnnotation/hello_annotation.postman_collection.json b/HelloAnnotation/postman/hello_annotation.postman_collection.json
similarity index 100%
rename from HelloAnnotation/hello_annotation.postman_collection.json
rename to HelloAnnotation/postman/hello_annotation.postman_collection.json
diff --git a/HelloAudio/pom.xml b/HelloAudio/pom.xml
index 4e804a1..d0e3504 100644
--- a/HelloAudio/pom.xml
+++ b/HelloAudio/pom.xml
@@ -21,33 +21,11 @@
-
- org.apache.commons
- commons-collections4
- 4.4
-
org.apache.commons
commons-lang3
3.7
-
- com.alibaba
- fastjson
- 1.2.60
-
-
-
-
- org.apache.httpcomponents
- httpclient
- 4.5.2
-
-
- org.apache.httpcomponents
- httpmime
- 4.5
-
junit
@@ -55,16 +33,6 @@
4.11
test
-
- org.slf4j
- slf4j-api
- 1.7.7
-
-
- org.slf4j
- slf4j-log4j12
- 1.7.7
-
diff --git a/HelloAudio/rec.wav b/HelloAudio/rec.wav
deleted file mode 100644
index 57b2871..0000000
Binary files a/HelloAudio/rec.wav and /dev/null differ
diff --git a/HelloAudio/src/main/java/com/hello/App.java b/HelloAudio/src/main/java/com/hello/App.java
index 4ecff3e..aa3818d 100644
--- a/HelloAudio/src/main/java/com/hello/App.java
+++ b/HelloAudio/src/main/java/com/hello/App.java
@@ -1,6 +1,5 @@
package com.hello;
-import com.hello.audio.ChatUtil;
import com.hello.audio.RecordHelper;
import com.hello.audio.TimeListener;
@@ -11,7 +10,7 @@
public class App {
public static void main(String[] args) {
// create frame
- final JFrame frame = new JFrame("Walle");
+ final JFrame frame = new JFrame("Audio");
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
@@ -24,7 +23,7 @@ public static void main(String[] args) {
// Create buttons
final long msDuration = 5000;
- final String title = "AI语音聊天";
+ final String title = "Record";
final JButton recordBtn = new JButton(title);
recordBtn.addActionListener(new ActionListener() {
@Override
@@ -41,7 +40,7 @@ public void timeUpdated(long seconds) {
@Override
public void stopped(long seconds) {
recordBtn.setText(title);
- ChatUtil.chat();
+ recordHelper.play();
}
}, msDuration);
}
diff --git a/HelloAudio/src/main/java/com/hello/audio/ChatUtil.java b/HelloAudio/src/main/java/com/hello/audio/ChatUtil.java
deleted file mode 100644
index 7c2e4e7..0000000
--- a/HelloAudio/src/main/java/com/hello/audio/ChatUtil.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.hello.audio;
-
-import com.hello.http.HttpUtil;
-import com.hello.http.RespData;
-import com.hello.util.B64Util;
-
-import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
-
-public class ChatUtil {
- public static void chat() {
- RecordHelper recordHelper = RecordHelper.getInst();
- final ByteArrayOutputStream data = recordHelper.save(new ByteArrayOutputStream());
-
- RespData resp = new RespData();
- byte[] ret = HttpUtil.sendHttpPost(
- "http://localhost:8011/speech/walle",
- null, new HashMap() {{
- put("size", data.size());
- put("format", "wav");
- put("audio", B64Util.encode(data.toByteArray()));
- }}, resp
- );
- System.out.printf("%s, %s, %s, %d, %d\n",
- resp.getContentType(), resp.getFileName(), resp.getFileExt(),
- resp.getContentLength(), ret == null ? 0 : ret.length
- );
-
- if (ret != null && ret.length > 0) {
- Player.asyncPlay(ret);
- } else {
- // 播放自己的声音吧
- recordHelper.play();
- }
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/http/HttpUtil.java b/HelloAudio/src/main/java/com/hello/http/HttpUtil.java
deleted file mode 100644
index c336d08..0000000
--- a/HelloAudio/src/main/java/com/hello/http/HttpUtil.java
+++ /dev/null
@@ -1,247 +0,0 @@
-package com.hello.http;
-
-import com.hello.util.JsonUtil;
-import com.hello.util.LogUtil;
-import com.hello.util.StrUtil;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.conn.socket.ConnectionSocketFactory;
-import org.apache.http.conn.socket.PlainConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLContextBuilder;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.message.BasicNameValuePair;
-
-import java.io.File;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-public class HttpUtil {
- private static final String CHARSET_UTF_8 = "utf-8";
- private static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded;charset=utf-8";
- private static final String CONTENT_TYPE_JSON = "application/json;charset=utf-8";
-
- private static final int MAX_TOTAL = 100;
- private static final int MAX_PER_ROUTE = 20;
-
- private static final int SOCKET_TIMEOUT = 10000;
- private static final int CONNECT_TIMEOUT = 10000;
- private static final int REQUEST_TIMEOUT = 10000;
-
- private static PoolingHttpClientConnectionManager connectionPool;
- private static RequestConfig requestConfig;
-
- static {
- try {
- SSLContextBuilder builder = new SSLContextBuilder();
- builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
- SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
- Registry socketFactoryRegistry = RegistryBuilder.create()
- .register("http", PlainConnectionSocketFactory.getSocketFactory())
- .register("https", sslsf)
- .build();
-
- connectionPool = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
- connectionPool.setMaxTotal(MAX_TOTAL);
- connectionPool.setDefaultMaxPerRoute(MAX_PER_ROUTE);
- } catch (KeyStoreException e) {
- e.printStackTrace();
- } catch (KeyManagementException e) {
- e.printStackTrace();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
-
- requestConfig = RequestConfig.custom()
- .setSocketTimeout(SOCKET_TIMEOUT)
- .setConnectTimeout(CONNECT_TIMEOUT)
- .setConnectionRequestTimeout(REQUEST_TIMEOUT)
- .build();
- }
-
- private static CloseableHttpClient getHttpClient() {
- return HttpClients.custom()
- .setConnectionManager(connectionPool)
- .setDefaultRequestConfig(requestConfig)
- .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
- .build();
- }
-
- private static T sendHttpRequest(HttpRequestBase httpRequest, ResponseHandler handler) {
- try {
- return getHttpClient().execute(httpRequest, handler);
- } catch (ClientProtocolException e) {
- LogUtil.error("Error when sendHttpRequest", e.getMessage());
- } catch (IOException e) {
- LogUtil.error("Error when sendHttpRequest", e.getMessage());
- }
- return null;
- }
-
- public static T sendHttpGet(String httpUrl, ResponseHandler handler) {
- HttpGet httpGet = new HttpGet(httpUrl);
- return sendHttpRequest(httpGet, handler);
- }
-
- public static String sendHttpGet(String httpUrl) {
- return sendHttpGet(httpUrl, new RespStr());
- }
-
- public static T sendHttpGet(String httpUrl, Map headers, ResponseHandler handler) {
- HttpGet httpGet = new HttpGet(httpUrl);
- fillHeaders(httpGet, headers);
- return sendHttpRequest(httpGet, handler);
- }
-
- public static String sendHttpGet(String httpUrl, Map headers) {
- HttpGet httpGet = new HttpGet(httpUrl);
- fillHeaders(httpGet, headers);
- return sendHttpRequest(httpGet, new RespStr());
- }
-
- public static T sendHttpGet(String httpUrl, Map headers, Map params, ResponseHandler handler) {
- if (!MapUtils.isEmpty(params)) {
- List paramList = new ArrayList();
- for (Map.Entry param : params.entrySet()) {
- Object value = param.getValue();
- if (value != null) {
- paramList.add(String.format("%s=%s", param.getKey(), UrlUtil.encode(String.valueOf(value))));
- }
- }
-
- String paramStr = StrUtil.join(paramList, "&");
- httpUrl = String.format("%s%s%s", httpUrl, httpUrl.indexOf("?") > 0 ? "&" : "?", paramStr);
- }
- return sendHttpGet(httpUrl, headers, handler);
- }
-
- public static String sendHttpGet(String httpUrl, Map headers, Map params) {
- return sendHttpGet(httpUrl, headers, params, new RespStr());
- }
-
- public static T sendHttpPost(String httpUrl, Map headers, Map params, ResponseHandler handler) {
- HttpPost httpPost = new HttpPost(httpUrl);
- fillHeaders(httpPost, headers);
-
- if (!MapUtils.isEmpty(params)) {
- String jsonStr = JsonUtil.toStr(params);
- StringEntity stringEntity = new StringEntity(jsonStr, "UTF-8");
- stringEntity.setContentType(CONTENT_TYPE_JSON);
- httpPost.setEntity(stringEntity);
- }
- return sendHttpRequest(httpPost, handler);
- }
-
- public static String sendHttpPost(String httpUrl, Map headers, Map params) {
- return sendHttpPost(httpUrl, headers, params, new RespStr());
- }
-
- public static T sendHttpPost(String httpUrl, Map headers, Map params, File file, ResponseHandler handler) {
- File[] files = new File[]{file};
- return sendHttpPost(httpUrl, headers, params, Arrays.asList(files), handler);
- }
-
- public static T sendHttpPost(String httpUrl, Map headers, Map params, Collection files, ResponseHandler handler) {
- HttpPost httpPost = new HttpPost(httpUrl);
- fillHeaders(httpPost, headers);
-
- MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create();
- if (!MapUtils.isEmpty(params)) {
- for (String key : params.keySet()) {
- Object value = params.get(key);
- if (value != null) {
- meBuilder.addPart(key, new StringBody(String.valueOf(value), ContentType.TEXT_PLAIN));
- }
- }
- }
-
- if (!CollectionUtils.isEmpty(files)) {
- for (File file : files) {
- meBuilder.addBinaryBody("file", file);
- }
- }
-
- HttpEntity reqEntity = meBuilder.build();
- httpPost.setEntity(reqEntity);
- return sendHttpRequest(httpPost, handler);
- }
-
- public static T sendHttpForm(String httpUrl, Map headers, Map params, ResponseHandler handler) {
- HttpPost httpPost = new HttpPost(httpUrl);
- fillHeaders(httpPost, headers);
-
- if (!MapUtils.isEmpty(params)) {
- List pairs = new ArrayList(params.size());
- for (Map.Entry param : params.entrySet()) {
- Object value = param.getValue();
- if (value != null) {
- pairs.add(new BasicNameValuePair(param.getKey(), String.valueOf(value)));
- }
- }
-
- try {
- httpPost.setEntity(new UrlEncodedFormEntity(pairs));
- } catch (Exception e) {
- LogUtil.error("Error when sendHttpSubmit", e.getMessage());
- }
- }
- return sendHttpRequest(httpPost, handler);
- }
-
- public static T sendHttpPut(String httpUrl, Map headers, Map params, ResponseHandler handler) {
- HttpPut httpPut = new HttpPut(httpUrl);
- fillHeaders(httpPut, headers);
-
- if (!MapUtils.isEmpty(params)) {
- String jsonStr = JsonUtil.toStr(params);
- StringEntity stringEntity = new StringEntity(jsonStr, "UTF-8");
- stringEntity.setContentType(CONTENT_TYPE_JSON);
- httpPut.setEntity(stringEntity);
- }
- return sendHttpRequest(httpPut, handler);
- }
-
- public static T sendHttpDelete(String httpUrl, Map headers, ResponseHandler handler) {
- HttpDelete httpDelete = new HttpDelete(httpUrl);
- fillHeaders(httpDelete, headers);
- return sendHttpRequest(httpDelete, handler);
- }
-
- private static void fillHeaders(HttpRequestBase request, Map headers) {
- if (request == null || MapUtils.isEmpty(headers)) {
- return;
- }
-
- for (Map.Entry header : headers.entrySet()) {
- request.addHeader(header.getKey(), header.getValue());
- }
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/http/RespData.java b/HelloAudio/src/main/java/com/hello/http/RespData.java
deleted file mode 100644
index 69d4eb3..0000000
--- a/HelloAudio/src/main/java/com/hello/http/RespData.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package com.hello.http;
-
-import com.hello.util.LogUtil;
-import com.hello.util.StrUtil;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.util.EntityUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-public class RespData implements ResponseHandler {
- private byte[] bytes;
- private String fileName;
- private String fileExt;
- private String contentType;
- private String contentLength;
-
- public byte[] getBytes() {
- return bytes;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public String getFileExt() {
- return fileExt;
- }
-
- public String getContentType() {
- return contentType;
- }
-
- public int getContentLength() {
- return StrUtil.isEmpty(contentLength) ? 0 : Integer.valueOf(contentLength);
- }
-
- public String saveFile(String filePath) {
- if (StrUtil.isEmpty(filePath)) {
- filePath = fileName;
- }
- if (StrUtil.isEmpty(filePath) || bytes == null || bytes.length <= 0) {
- return null;
- }
-
- // Check path
- File file = new File(filePath);
- String fileName = file.getName();
- filePath = file.getParent();
-
- file = new File(filePath == null ? "tmp" : filePath);
- if (!file.exists() && !file.mkdirs()) {
- return null;
- }
-
- // Write to disc
- Path path = Paths.get(file.getPath(), fileName);
- try {
- Files.write(path, bytes);
- } catch (IOException e) {
- LogUtil.error("Fail to save file: %s, %s\n", path.toString(), e.getMessage());
- return null;
- }
- return path.toString();
- }
-
- private String getHeader(HttpResponse response, String header) {
- return response.containsHeader(header) ? response.getFirstHeader(header).getValue() : null;
- }
-
- @Override
- public byte[] handleResponse(HttpResponse response) throws IOException {
- // 判断响应状态
- if (response.getStatusLine().getStatusCode() >= 300) {
- throw new IOException("HTTP Request is not success, Response code is " + response.getStatusLine().getStatusCode());
- }
-
- // 读取文件名称,Header: Content-Disposition: attachment;fileName=abc.txt
- String disposition = getHeader(response, "Content-Disposition");
- if (!StrUtil.isEmpty(disposition) && disposition.contains("=")) {
- fileName = disposition.split("=")[1];
- }
-
- // 读取ContentType: audio/mp3
- contentType = getHeader(response, "Content-Type");
- if (!StrUtil.isEmpty(contentType) && contentType.contains("/")) {
- fileExt = contentType.split("/")[1];
- }
-
- contentLength = getHeader(response, "Content-Length");
-
- // 读取返回内容
- HttpEntity entity = response.getEntity();
- if (entity == null) {
- throw new ClientProtocolException("Response contains no content");
- }
-
- bytes = EntityUtils.toByteArray(entity);
- return bytes;
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/http/RespJsonObj.java b/HelloAudio/src/main/java/com/hello/http/RespJsonObj.java
deleted file mode 100644
index 44fc5ff..0000000
--- a/HelloAudio/src/main/java/com/hello/http/RespJsonObj.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.hello.http;
-
-import com.alibaba.fastjson.JSONObject;
-import com.hello.util.JsonUtil;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.entity.ContentType;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-public class RespJsonObj implements ResponseHandler {
- @Override
- public JSONObject handleResponse(HttpResponse resp) throws IOException {
- HttpEntity entity = resp.getEntity();
- if (entity == null) {
- throw new ClientProtocolException("Response contains no content");
- }
-
- // read content
- ContentType contentType = ContentType.getOrDefault(entity);
- Charset charset = contentType.getCharset();
- String jsonStr = EntityUtils.toString(entity, charset == null ? Charset.forName("utf-8") : charset);
-
- // parse JSON object
- return JsonUtil.parseObj(jsonStr);
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/http/RespStr.java b/HelloAudio/src/main/java/com/hello/http/RespStr.java
deleted file mode 100644
index ccaf5ee..0000000
--- a/HelloAudio/src/main/java/com/hello/http/RespStr.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.hello.http;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.entity.ContentType;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-public class RespStr implements ResponseHandler {
- @Override
- public String handleResponse(HttpResponse httpResponse) throws IOException {
- HttpEntity entity = httpResponse.getEntity();
- if (entity == null) {
- throw new ClientProtocolException("Response contains no content");
- }
-
- // 读取返回内容
- ContentType contentType = ContentType.getOrDefault(entity);
- Charset charset = contentType.getCharset();
- return EntityUtils.toString(entity, charset == null ? Charset.forName("utf-8") : charset);
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/http/UrlUtil.java b/HelloAudio/src/main/java/com/hello/http/UrlUtil.java
deleted file mode 100644
index 7899028..0000000
--- a/HelloAudio/src/main/java/com/hello/http/UrlUtil.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.hello.http;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-
-public class UrlUtil {
- public static String encode(String str) {
- if (str == null) {
- return null;
- }
-
- try {
- return URLEncoder.encode(str, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static String decode(String str) {
- if (str == null) {
- return null;
- }
-
- try {
- return URLDecoder.decode(str, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return null;
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/util/B64Util.java b/HelloAudio/src/main/java/com/hello/util/B64Util.java
deleted file mode 100644
index 4d9e7b9..0000000
--- a/HelloAudio/src/main/java/com/hello/util/B64Util.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.hello.util;
-
-import org.apache.commons.codec.binary.Base64;
-
-import java.io.UnsupportedEncodingException;
-
-public class B64Util {
- public static String encode(String str) {
- if (str == null) {
- return null;
- }
-
- try {
- return encode(str.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static String encode(byte[] bytes) {
- return bytes == null ? null : Base64.encodeBase64String(bytes);
- }
-
- public static String decode(String str) {
- if (str == null) {
- return null;
- }
-
- byte[] bytes = decodeForBytes(str);
- try {
- return new String(bytes, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static byte[] decodeForBytes(String str) {
- return str == null ? null : Base64.decodeBase64(str);
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/util/JsonUtil.java b/HelloAudio/src/main/java/com/hello/util/JsonUtil.java
deleted file mode 100644
index fcd90ca..0000000
--- a/HelloAudio/src/main/java/com/hello/util/JsonUtil.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.hello.util;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-
-import java.util.List;
-
-public class JsonUtil {
- public static String toStr(Object javaObj) {
- return javaObj == null ? null : JSONObject.toJSONString(javaObj);
- }
-
- public static JSONObject parseObj(String jsonStr) {
- if (StrUtil.isEmpty(jsonStr)) {
- return null;
- }
-
- try {
- return JSONObject.parseObject(jsonStr);
- } catch (Exception e) {
- String msg = e.getMessage();
- if (msg != null && msg.length() > 100) {
- msg = msg.substring(0, 100);
- }
- LogUtil.warn("Exception when parseJson", msg);
- }
- return null;
- }
-
- public static T parseObj(String jsonStr, Class clazz) {
- if (StrUtil.isEmpty(jsonStr)) {
- return null;
- }
-
- try {
- return JSONObject.parseObject(jsonStr, clazz);
- } catch (Exception e) {
- String msg = e.getMessage();
- if (msg != null && msg.length() > 100) {
- msg = msg.substring(0, 100);
- }
- LogUtil.warn("Exception when parseObj", msg);
- }
- return null;
- }
-
- public static JSONArray parseArr(String jsonStr) {
- if (StrUtil.isEmpty(jsonStr)) {
- return null;
- }
-
- try {
- return JSONObject.parseArray(jsonStr);
- } catch (Exception e) {
- String msg = e.getMessage();
- if (msg != null && msg.length() > 100) {
- msg = msg.substring(0, 100);
- }
- LogUtil.warn("Exception when parseJson", msg);
- }
- return null;
- }
-
- public static List parseArr(String jsonStr, Class clazz) {
- if (StrUtil.isEmpty(jsonStr)) {
- return null;
- }
-
- try {
- return JSONObject.parseArray(jsonStr, clazz);
- } catch (Exception e) {
- String msg = e.getMessage();
- if (msg != null && msg.length() > 100) {
- msg = msg.substring(0, 100);
- }
- LogUtil.warn("Exception when parseObj", msg);
- }
- return null;
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/util/LogUtil.java b/HelloAudio/src/main/java/com/hello/util/LogUtil.java
deleted file mode 100644
index 1875c33..0000000
--- a/HelloAudio/src/main/java/com/hello/util/LogUtil.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.hello.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LogUtil {
- private static final Logger log = LoggerFactory.getLogger(LogUtil.class);
-
- public static void debug(Object... msg) {
- debug(log, msg);
- }
-
- public static void debug(Logger log, Object... msg) {
- log.debug(StrUtil.joinObj(msg, ", "));
- }
-
- public static void info(Object... msg) {
- info(log, msg);
- }
-
- public static void info(Logger log, Object... msg) {
- log.info(StrUtil.joinObj(msg, ", "));
- }
-
- public static void warn(Object... msg) {
- warn(log, msg);
- }
-
- public static void warn(Logger log, Object... msg) {
- log.warn(StrUtil.joinObj(msg, ", "));
- }
-
- public static void error(Object... msg) {
- error(log, msg);
- }
-
- public static void error(Logger log, Object... msg) {
- log.error(StrUtil.joinObj(msg, ", "));
- }
-}
diff --git a/HelloAudio/src/main/java/com/hello/util/StrUtil.java b/HelloAudio/src/main/java/com/hello/util/StrUtil.java
deleted file mode 100644
index 995bb48..0000000
--- a/HelloAudio/src/main/java/com/hello/util/StrUtil.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package com.hello.util;
-
-import org.apache.commons.collections4.CollectionUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class StrUtil {
- /**
- * String is null or empty
- */
- public static boolean isEmpty(String str) {
- return isEmpty(str, true);
- }
-
- public static boolean isEmpty(String str, boolean trim) {
- return str == null || str.isEmpty() || (trim && str.trim().isEmpty());
- }
-
- public static boolean chkLen(String str, int minLen, int maxLen) {
- return str != null
- && str.length() >= Math.max(minLen, 0)
- && str.length() <= Math.min(Math.max(maxLen, 0), 1024);
- }
-
- public static String mask(String str) {
- return mask(str, 1, 12);
- }
-
- public static String mask(String str, int minLen, int maxLen) {
- if (isEmpty(str)) {
- return "";
- }
-
- str = str.trim().replace(" ", "")
- .replace("-", "")
- .replace("_", "");
- if (str.length() <= minLen && minLen > 0) {
- return str;
- }
-
- // Remove the middle part if it's too long
- if (maxLen > 0) {
- if (maxLen % 2 != 0) {
- maxLen++;
- }
-
- if (str.length() > maxLen) {
- str = String.format("%s%s",
- str.substring(0, maxLen / 2),
- str.substring(str.length() - maxLen / 2, str.length())
- );
- }
- }
-
- // Divide 3 parts: str+mask+str
- final int len = str.length();
- final int maskLen = len > 3 ? len / 3 : 1;
- StringBuilder sb = new StringBuilder(maskLen);
- for (int i = 0; i < maskLen; i++) {
- sb.append("*");
- }
-
- int startLen = (len - maskLen) / 2;
- return String.format("%s%s%s",
- str.substring(0, startLen), sb.toString(), str.substring(startLen + maskLen, len)
- );
- }
-
- public static boolean matches(String str, String pattern) {
- if (isEmpty(str) || isEmpty(pattern)) {
- return false;
- }
- Pattern p = Pattern.compile(pattern);
- Matcher m = p.matcher(str);
- return m.matches();
- }
-
- public static String[] parse(String str, String pattern) {
- if (isEmpty(str) || isEmpty(pattern)) {
- return null;
- }
-
- List list = new ArrayList();
- Pattern p = Pattern.compile(pattern);
- Matcher m = p.matcher(str);
- while (m.find()) {
- list.add(m.group());
- }
- if (list.size() <= 0) {
- return null;
- }
-
- String[] arr = new String[list.size()];
- list.toArray(arr);
- return arr;
- }
-
- public static boolean contains(String str, String subStr) {
- return contains(str, subStr, ",");
- }
-
- public static boolean contains(String str, String subStr, String separator) {
- if (isEmpty(str) || isEmpty(subStr)) {
- return false;
- }
-
- if (subStr.equalsIgnoreCase(str)) {
- return true;
- }
-
- String[] strArray = split(str, separator);
- if (strArray == null) {
- return false;
- }
-
- for (String tmpStr : strArray) {
- if (tmpStr.trim().length() == 0 && subStr.trim().length() == 0) {
- return true;
- }
-
- if (tmpStr.trim().equalsIgnoreCase(subStr.trim())) {
- return true;
- }
- }
- return false;
- }
-
- public static String[] split(String str, String separator) {
- if (isEmpty(str) || isEmpty(separator)) {
- return null;
- }
- return str.split(separator);
- }
-
- public static String joinObj(Object[] objArr, String separator) {
- return objArr == null ? null : joinObj(Arrays.asList(objArr), separator);
- }
-
- public static String joinObj(Collection