list, String part, boolean isTrim
return list;
}
+ /**
+ * 一个对象不为空且不存在于该集合中时,加入到该集合中
+ *
+ * null, null = false
+ * [], null = false
+ * null, "123" = false
+ * ["123"], "123" = false
+ * [], "123" => true
+ * ["456"], "123" = true
+ * [Animal{"name": "jack"}], Dog{"name": "jack"} = true
+ *
+ *
+ * @param collection 被加入的集合
+ * @param object 要添加到集合的对象
+ * @param 集合元素类型
+ * @param 要添加的元素类型【为集合元素类型的类型或子类型】
+ * @return 是否添加成功
+ * @author Cloud-Style
+ */
+ public static boolean addIfAbsent(Collection collection, S object) {
+ if (object == null || collection == null || collection.contains(object)) {
+ return false;
+ }
+
+ return collection.add(object);
+ }
+
/**
* 将另一个列表中的元素加入到列表中,如果列表中已经存在此元素则忽略之
*
diff --git a/bus-core/src/main/java/org/aoju/bus/core/toolkit/RandomKit.java b/bus-core/src/main/java/org/aoju/bus/core/toolkit/RandomKit.java
index db82d6f6c7..57a01a7aa4 100755
--- a/bus-core/src/main/java/org/aoju/bus/core/toolkit/RandomKit.java
+++ b/bus-core/src/main/java/org/aoju/bus/core/toolkit/RandomKit.java
@@ -390,6 +390,30 @@ public static String randomString(int length) {
return randomString(Normal.LOWER_NUMBER, length);
}
+ /**
+ * 获得一个随机的字符串
+ *
+ * @param text 随机字符选取的样本
+ * @param length 字符串的长度
+ * @return 随机字符串
+ */
+ public static String randomString(String text, int length) {
+ if (StringKit.isEmpty(text)) {
+ return Normal.EMPTY;
+ }
+ if (length < 1) {
+ length = 1;
+ }
+
+ final StringBuilder sb = new StringBuilder(length);
+ int baseLength = text.length();
+ for (int i = 0; i < length; i++) {
+ int number = randomInt(baseLength);
+ sb.append(text.charAt(number));
+ }
+ return sb.toString();
+ }
+
/**
* 获得一个随机的字符串(只包含数字和大写字符)
*
@@ -438,30 +462,6 @@ public static String randomNumbers(int length) {
return randomString(Normal.NUMBER, length);
}
- /**
- * 获得一个随机的字符串
- *
- * @param text 随机字符选取的样本
- * @param length 字符串的长度
- * @return 随机字符串
- */
- public static String randomString(String text, int length) {
- if (StringKit.isEmpty(text)) {
- return Normal.EMPTY;
- }
- final StringBuilder sb = new StringBuilder(length);
-
- if (length < 1) {
- length = 1;
- }
- int baseLength = text.length();
- for (int i = 0; i < length; i++) {
- int number = randomInt(baseLength);
- sb.append(text.charAt(number));
- }
- return sb.toString();
- }
-
/**
* 随机数字,数字为0~9单个数字
*
diff --git a/bus-core/src/main/java/org/aoju/bus/core/toolkit/ReflectKit.java b/bus-core/src/main/java/org/aoju/bus/core/toolkit/ReflectKit.java
index 35a70fb9c4..4d3c7c6194 100755
--- a/bus-core/src/main/java/org/aoju/bus/core/toolkit/ReflectKit.java
+++ b/bus-core/src/main/java/org/aoju/bus/core/toolkit/ReflectKit.java
@@ -575,10 +575,12 @@ public static Object[] getFieldsValue(Object object) {
/**
* 设置字段值
+ * 若值类型与字段类型不一致,则会尝试通过 {@link Convert} 进行转换
+ * 若字段类型是原始类型而传入的值是 null,则会将字段设置为对应原始类型的默认值(见 {@link ClassKit#getDefaultValue(Class)})
*
* @param object 对象,static字段则此处传Class
* @param fieldName 字段名
- * @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
+ * @param value 值,当值类型与字段类型不匹配时,会尝试转换
* @throws InstrumentException 包装IllegalAccessException异常
*/
public static void setFieldValue(Object object, String fieldName, Object value) throws InstrumentException {
@@ -592,10 +594,12 @@ public static void setFieldValue(Object object, String fieldName, Object value)
/**
* 设置字段值
+ * 若值类型与字段类型不一致,则会尝试通过 {@link Convert} 进行转换
+ * 若字段类型是原始类型而传入的值是 null,则会将字段设置为对应原始类型的默认值(见 {@link ClassKit#getDefaultValue(Class)})
*
* @param object 对象,如果是static字段,此参数为null
* @param field 字段
- * @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
+ * @param value 值,当值类型与字段类型不匹配时,会尝试转换
* @throws InstrumentException UtilException 包装IllegalAccessException异常
*/
public static void setFieldValue(Object object, Field field, Object value) throws InstrumentException {
diff --git a/bus-core/src/main/java/org/aoju/bus/core/toolkit/UriKit.java b/bus-core/src/main/java/org/aoju/bus/core/toolkit/UriKit.java
index 00bf980706..be781a2ff2 100755
--- a/bus-core/src/main/java/org/aoju/bus/core/toolkit/UriKit.java
+++ b/bus-core/src/main/java/org/aoju/bus/core/toolkit/UriKit.java
@@ -1759,12 +1759,7 @@ public URL toURL(URLStreamHandler handler) {
*/
public URI toURI() {
try {
- return new URI(
- getSchemeWithDefault(),
- getAuthority(),
- getPathString(),
- getQueryString(),
- getFragmentEncoded());
+ return toURL().toURI();
} catch (URISyntaxException e) {
return null;
}
diff --git a/bus-cron/pom.xml b/bus-cron/pom.xml
index f64e8cbdb1..0fab433a96 100755
--- a/bus-cron/pom.xml
+++ b/bus-cron/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-cron
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -66,7 +66,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-crypto/pom.xml b/bus-crypto/pom.xml
index 559ea1a720..4c32e5d199 100755
--- a/bus-crypto/pom.xml
+++ b/bus-crypto/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-crypto
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -79,7 +79,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-crypto/src/main/java/org/aoju/bus/crypto/Builder.java b/bus-crypto/src/main/java/org/aoju/bus/crypto/Builder.java
index 0aab679ff8..a1e26fccf8 100644
--- a/bus-crypto/src/main/java/org/aoju/bus/crypto/Builder.java
+++ b/bus-crypto/src/main/java/org/aoju/bus/crypto/Builder.java
@@ -575,7 +575,7 @@ public static String sha256Hex(File file) {
* @return {@link HMac}
*/
public static HMac hmac(Algorithm algorithm, String key) {
- return new HMac(algorithm, StringKit.bytes(key));
+ return new HMac(algorithm, StringKit.isNotEmpty(key) ? StringKit.bytes(key) : null);
}
/**
@@ -586,6 +586,9 @@ public static HMac hmac(Algorithm algorithm, String key) {
* @return {@link HMac}
*/
public static HMac hmac(Algorithm algorithm, byte[] key) {
+ if (ArrayKit.isEmpty(key)) {
+ key = generateKey(algorithm.getValue()).getEncoded();
+ }
return new HMac(algorithm, key);
}
@@ -597,6 +600,9 @@ public static HMac hmac(Algorithm algorithm, byte[] key) {
* @return {@link HMac}
*/
public static HMac hmac(Algorithm algorithm, SecretKey key) {
+ if (ObjectKit.isNull(key)) {
+ key = generateKey(algorithm.getValue());
+ }
return new HMac(algorithm, key);
}
@@ -610,7 +616,7 @@ public static HMac hmac(Algorithm algorithm, SecretKey key) {
* @return {@link HMac}
*/
public static HMac hmacMd5(String key) {
- return hmacMd5(StringKit.bytes(key));
+ return hmacMd5(StringKit.isNotEmpty(key) ? StringKit.bytes(key) : null);
}
/**
@@ -623,6 +629,9 @@ public static HMac hmacMd5(String key) {
* @return {@link HMac}
*/
public static HMac hmacMd5(byte[] key) {
+ if (ArrayKit.isEmpty(key)) {
+ key = generateKey(Algorithm.HMACMD5.getValue()).getEncoded();
+ }
return new HMac(Algorithm.HMACMD5, key);
}
@@ -648,7 +657,7 @@ public static HMac hmacMd5() {
* @return {@link HMac}
*/
public static HMac hmacSha1(String key) {
- return hmacSha1(StringKit.bytes(key));
+ return hmacSha1(StringKit.isNotEmpty(key) ? StringKit.bytes(key) : null);
}
/**
@@ -661,6 +670,9 @@ public static HMac hmacSha1(String key) {
* @return {@link HMac}
*/
public static HMac hmacSha1(byte[] key) {
+ if (ArrayKit.isEmpty(key)) {
+ key = generateKey(Algorithm.HMACMD5.getValue()).getEncoded();
+ }
return new HMac(Algorithm.HMACSHA1, key);
}
@@ -686,7 +698,7 @@ public static HMac hmacSha1() {
* @return {@link HMac}
*/
public static HMac hmacSha256(String key) {
- return hmacSha256(StringKit.bytes(key));
+ return hmacSha256(StringKit.isNotEmpty(key) ? StringKit.bytes(key) : null);
}
/**
@@ -699,6 +711,9 @@ public static HMac hmacSha256(String key) {
* @return {@link HMac}
*/
public static HMac hmacSha256(byte[] key) {
+ if (ArrayKit.isEmpty(key)) {
+ key = generateKey(Algorithm.HMACMD5.getValue()).getEncoded();
+ }
return new HMac(Algorithm.HMACSHA256, key);
}
diff --git a/bus-extra/pom.xml b/bus-extra/pom.xml
index d4d04d43e0..c1b0957743 100644
--- a/bus-extra/pom.xml
+++ b/bus-extra/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-extra
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -44,22 +44,22 @@
17
1.18.24
1.2.83
- 2.9.0
+ 2.9.1
2.13.3
1.1.8
2.5.1
2.0.3.RELEASE
1.0.0
0.3.1
- 0.1.54
- 0.33.0
+ 0.1.55
+ 0.34.0
3.5.0
3.8.0
5.1.1
1.21
1.0.6
- 1.3.0
- 1.1.7.6
+ 1.8.0
+ 1.1.8.4
4.0.4
@@ -178,10 +178,9 @@
true
- net.jpountz.lz4
- lz4
+ org.lz4
+ lz4-java
${lz4.version}
- true
org.xerial.snappy
@@ -211,7 +210,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-gitlab/README.md b/bus-gitlab/README.md
index 6e6c8b3ee2..37a7c9798a 100755
--- a/bus-gitlab/README.md
+++ b/bus-gitlab/README.md
@@ -70,7 +70,7 @@ dependencies {
org.aoju
bus-gitlab
- 6.5.5
+ 6.5.6
```
diff --git a/bus-gitlab/pom.xml b/bus-gitlab/pom.xml
index e0f044374f..d375a4ad68 100755
--- a/bus-gitlab/pom.xml
+++ b/bus-gitlab/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-gitlab
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -44,7 +44,7 @@
17
2.12.4
2.36
- 5.0.0
+ 4.0.4
@@ -105,7 +105,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/HookManager.java b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/HookManager.java
index 157ea82000..2a35ccf1e8 100644
--- a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/HookManager.java
+++ b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/HookManager.java
@@ -25,7 +25,7 @@
********************************************************************************/
package org.aoju.bus.gitlab;
-import jakarta.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequest;
/**
* This interface provides a base class handler for processing GitLab Web Hook and System Hook callouts.
diff --git a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/SystemHookManager.java b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/SystemHookManager.java
index c74295d973..6370d27643 100644
--- a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/SystemHookManager.java
+++ b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/SystemHookManager.java
@@ -27,12 +27,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import jakarta.servlet.http.HttpServletRequest;
import org.aoju.bus.gitlab.GitLabApiException;
import org.aoju.bus.gitlab.HookManager;
import org.aoju.bus.gitlab.support.HttpRequest;
import org.aoju.bus.gitlab.support.JacksonJson;
+import javax.servlet.http.HttpServletRequest;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
diff --git a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/web/WebHookManager.java b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/web/WebHookManager.java
index 50bfa6bffb..caa6c40215 100644
--- a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/web/WebHookManager.java
+++ b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/hooks/web/WebHookManager.java
@@ -25,12 +25,12 @@
********************************************************************************/
package org.aoju.bus.gitlab.hooks.web;
-import jakarta.servlet.http.HttpServletRequest;
import org.aoju.bus.gitlab.GitLabApiException;
import org.aoju.bus.gitlab.HookManager;
import org.aoju.bus.gitlab.support.HttpRequest;
import org.aoju.bus.gitlab.support.JacksonJson;
+import javax.servlet.http.HttpServletRequest;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
diff --git a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/support/HttpRequest.java b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/support/HttpRequest.java
index 0de0a49091..246e646a7b 100644
--- a/bus-gitlab/src/main/java/org/aoju/bus/gitlab/support/HttpRequest.java
+++ b/bus-gitlab/src/main/java/org/aoju/bus/gitlab/support/HttpRequest.java
@@ -25,9 +25,8 @@
********************************************************************************/
package org.aoju.bus.gitlab.support;
-import jakarta.servlet.http.Cookie;
-import jakarta.servlet.http.HttpServletRequest;
-
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
diff --git a/bus-goalie/pom.xml b/bus-goalie/pom.xml
index 2229639970..6e785b5b92 100644
--- a/bus-goalie/pom.xml
+++ b/bus-goalie/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-goalie
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -42,7 +42,7 @@
UTF-8
UTF-8
17
- 2.7.0
+ 2.7.2
1.18.24
31.1-jre
@@ -109,7 +109,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-health/pom.xml b/bus-health/pom.xml
index 0629a34e9d..3972c86f53 100755
--- a/bus-health/pom.xml
+++ b/bus-health/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-health
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -42,7 +42,7 @@
UTF-8
UTF-8
17
- 5.12.0
+ 5.12.1
@@ -79,7 +79,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-http/README.md b/bus-http/README.md
index 05f5c63eaf..31f2cbd3a9 100644
--- a/bus-http/README.md
+++ b/bus-http/README.md
@@ -115,7 +115,7 @@ body 的内容类型,关于 MediaType 的更多信息可以查看 RFC 2045,R
RequestBody requestBody = new RequestBody() {
@Override
- public MediaType contentType() {
+ public MediaType mediaType() {
return MediaType.valueOf("text/x-markdown; charsets=utf-8");
}
diff --git a/bus-http/pom.xml b/bus-http/pom.xml
index aaa399cf5b..15f34056c0 100755
--- a/bus-http/pom.xml
+++ b/bus-http/pom.xml
@@ -6,7 +6,7 @@
org.aoju
bus-http
- 6.5.5
+ 6.5.6
jar
${project.artifactId}
@@ -93,7 +93,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
diff --git a/bus-http/src/main/java/org/aoju/bus/http/Httpv.java b/bus-http/src/main/java/org/aoju/bus/http/Httpv.java
index 513714a140..bc14585d2a 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/Httpv.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/Httpv.java
@@ -442,7 +442,7 @@ private static void addCopyInterceptor(Httpd.Builder builder) {
// 若是下载文件,则必须指定在 IO 线程操作
return response;
}
- ResponseBody newBody = ResponseBody.create(body.contentType(), body.bytes());
+ ResponseBody newBody = ResponseBody.create(body.mediaType(), body.bytes());
return response.newBuilder().body(newBody).build();
});
}
diff --git a/bus-http/src/main/java/org/aoju/bus/http/Response.java b/bus-http/src/main/java/org/aoju/bus/http/Response.java
index 86aae2404b..fd28359072 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/Response.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/Response.java
@@ -176,7 +176,7 @@ public ResponseBody peekBody(long byteCount) throws IOException {
Buffer buffer = new Buffer();
peeked.request(byteCount);
buffer.write(peeked, Math.min(byteCount, peeked.getBuffer().size()));
- return ResponseBody.create(body.contentType(), buffer.size(), buffer);
+ return ResponseBody.create(body.mediaType(), buffer.size(), buffer);
}
/**
diff --git a/bus-http/src/main/java/org/aoju/bus/http/accord/Exchange.java b/bus-http/src/main/java/org/aoju/bus/http/accord/Exchange.java
index 3d82a4a4ac..84307c9d0d 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/accord/Exchange.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/accord/Exchange.java
@@ -95,10 +95,10 @@ public void writeRequestHeaders(Request request) throws IOException {
public Sink createRequestBody(Request request, boolean duplex) throws IOException {
this.duplex = duplex;
- long contentLength = request.body().contentLength();
+ long length = request.body().length();
eventListener.requestBodyStart(call);
- Sink rawRequestBody = httpCodec.createRequestBody(request, contentLength);
- return new RequestBodySink(rawRequestBody, contentLength);
+ Sink rawRequestBody = httpCodec.createRequestBody(request, length);
+ return new RequestBodySink(rawRequestBody, length);
}
public void flushRequest() throws IOException {
@@ -146,11 +146,11 @@ public void responseHeadersEnd(Response response) {
public ResponseBody openResponseBody(Response response) throws IOException {
try {
eventListener.responseBodyStart(call);
- String contentType = response.header("Content-Type");
- long contentLength = httpCodec.reportedContentLength(response);
+ String mediaType = response.header("Content-Type");
+ long length = httpCodec.reportedContentLength(response);
Source rawSource = httpCodec.openResponseBodySource(response);
- ResponseBodySource source = new ResponseBodySource(rawSource, contentLength);
- return new RealResponseBody(contentType, contentLength, IoKit.buffer(source));
+ ResponseBodySource source = new ResponseBodySource(rawSource, length);
+ return new RealResponseBody(mediaType, length, IoKit.buffer(source));
} catch (IOException e) {
eventListener.responseFailed(call, e);
trackFailure(e);
diff --git a/bus-http/src/main/java/org/aoju/bus/http/bodys/FormBody.java b/bus-http/src/main/java/org/aoju/bus/http/bodys/FormBody.java
index df4e3c7434..5b0f2b6667 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/bodys/FormBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/bodys/FormBody.java
@@ -72,12 +72,12 @@ public String value(int index) {
}
@Override
- public MediaType contentType() {
+ public MediaType mediaType() {
return MediaType.APPLICATION_FORM_URLENCODED_TYPE;
}
@Override
- public long contentLength() {
+ public long length() {
return writeOrCountBytes(null, true);
}
diff --git a/bus-http/src/main/java/org/aoju/bus/http/bodys/MultipartBody.java b/bus-http/src/main/java/org/aoju/bus/http/bodys/MultipartBody.java
index 2d68ca4cf2..49e4b2b080 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/bodys/MultipartBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/bodys/MultipartBody.java
@@ -53,14 +53,14 @@ public class MultipartBody extends RequestBody {
private final ByteString boundary;
private final MediaType originalType;
- private final MediaType contentType;
+ private final MediaType mediaType;
private final List parts;
private long contentLength = -1L;
- MultipartBody(ByteString boundary, MediaType type, List parts) {
+ MultipartBody(ByteString boundary, MediaType mediaType, List parts) {
this.boundary = boundary;
- this.originalType = type;
- this.contentType = MediaType.valueOf(type + "; boundary=" + boundary.utf8());
+ this.originalType = mediaType;
+ this.mediaType = MediaType.valueOf(mediaType.toString() + "; boundary=" + boundary.utf8());
this.parts = org.aoju.bus.http.Builder.immutableList(parts);
}
@@ -122,12 +122,12 @@ public Part part(int index) {
* A combination of {@link #type()} and {@link #boundary()}.
*/
@Override
- public MediaType contentType() {
- return contentType;
+ public MediaType mediaType() {
+ return mediaType;
}
@Override
- public long contentLength() throws IOException {
+ public long length() throws IOException {
long result = contentLength;
if (result != -1L) return result;
return contentLength = writeOrCountBytes(null, true);
@@ -174,14 +174,14 @@ private long writeOrCountBytes(BufferSink sink, boolean countBytes) throws IOExc
}
}
- MediaType contentType = body.contentType();
- if (null != contentType) {
+ MediaType mediaType = body.mediaType();
+ if (null != mediaType) {
sink.writeUtf8(Header.CONTENT_TYPE + ": ")
- .writeUtf8(contentType.toString())
+ .writeUtf8(mediaType.toString())
.write(CRLF);
}
- long contentLength = body.contentLength();
+ long contentLength = body.length();
if (contentLength != -1) {
sink.writeUtf8("Content-Length: ")
.writeDecimalLong(contentLength)
diff --git a/bus-http/src/main/java/org/aoju/bus/http/bodys/RealResponseBody.java b/bus-http/src/main/java/org/aoju/bus/http/bodys/RealResponseBody.java
index a41af8cbf4..fed3fb368c 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/bodys/RealResponseBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/bodys/RealResponseBody.java
@@ -40,25 +40,25 @@ public class RealResponseBody extends ResponseBody {
* 使用字符串避免在需要时才解析内容类型
* 这也避免了由格式不正确的内容类型引起的问题
*/
- private final String contentTypeString;
- private final long contentLength;
+ private final String mediaType;
+ private final long length;
private final BufferSource source;
public RealResponseBody(
- String contentTypeString, long contentLength, BufferSource source) {
- this.contentTypeString = contentTypeString;
- this.contentLength = contentLength;
+ String mediaType, long length, BufferSource source) {
+ this.mediaType = mediaType;
+ this.length = length;
this.source = source;
}
@Override
- public MediaType contentType() {
- return null != contentTypeString ? MediaType.valueOf(contentTypeString) : null;
+ public MediaType mediaType() {
+ return null != mediaType ? MediaType.valueOf(mediaType) : null;
}
@Override
- public long contentLength() {
- return contentLength;
+ public long length() {
+ return length;
}
@Override
diff --git a/bus-http/src/main/java/org/aoju/bus/http/bodys/RequestBody.java b/bus-http/src/main/java/org/aoju/bus/http/bodys/RequestBody.java
index 1dd2b56c01..af68e65234 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/bodys/RequestBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/bodys/RequestBody.java
@@ -46,43 +46,40 @@ public abstract class RequestBody {
/**
* 返回传输{@code content}的新请求体。
- * 如果{@code contentType}是非空且缺少字符集,则使用UTF-8
+ * 如果{@code mediaType}是非空且缺少字符集,则使用UTF-8
*
- * @param contentType 请求类型
- * @param content 内容
+ * @param mediaType 请求类型
+ * @param content 内容
* @return 传输请求体
*/
- public static RequestBody create(MediaType contentType, String content) {
+ public static RequestBody create(MediaType mediaType, String content) {
java.nio.charset.Charset charset = Charset.UTF_8;
- if (null != contentType) {
- charset = contentType.charset();
- if (null == charset) {
- charset = Charset.UTF_8;
- contentType = MediaType.valueOf(contentType + "; charset=utf-8");
- }
+ if (null != mediaType) {
+ charset = null != mediaType.charset() ? mediaType.charset() : Charset.UTF_8;
}
+
byte[] bytes = content.getBytes(charset);
- return create(contentType, bytes);
+ return create(mediaType, bytes);
}
/**
* 返回发送{@code content}的新请求体
*
- * @param contentType 请求类型
- * @param content 内容
+ * @param mediaType 请求类型
+ * @param content 内容
* @return 传输请求体
*/
public static RequestBody create(
- final MediaType contentType,
+ final MediaType mediaType,
final ByteString content) {
return new RequestBody() {
@Override
- public MediaType contentType() {
- return contentType;
+ public MediaType mediaType() {
+ return mediaType;
}
@Override
- public long contentLength() {
+ public long length() {
return content.size();
}
@@ -96,24 +93,24 @@ public void writeTo(BufferSink sink) throws IOException {
/**
* 发送{@code content}的新请求体
*
- * @param contentType 请求类型
- * @param content 内容
+ * @param mediaType 媒体类型
+ * @param content 内容
* @return 传输请求体
*/
- public static RequestBody create(final MediaType contentType, final byte[] content) {
- return create(contentType, content, 0, content.length);
+ public static RequestBody create(final MediaType mediaType, final byte[] content) {
+ return create(mediaType, content, 0, content.length);
}
/**
* 发送{@code content}的新请求体
*
- * @param contentType 请求类型
- * @param content 内容
- * @param offset 偏移量
- * @param byteCount 当前大小
+ * @param mediaType 媒体类型
+ * @param content 内容
+ * @param offset 偏移量
+ * @param byteCount 当前大小
* @return 传输请求体
*/
- public static RequestBody create(final MediaType contentType, final byte[] content,
+ public static RequestBody create(final MediaType mediaType, final byte[] content,
final int offset, final int byteCount) {
if (null == content) {
throw new NullPointerException("content == null");
@@ -121,12 +118,12 @@ public static RequestBody create(final MediaType contentType, final byte[] conte
Builder.checkOffsetAndCount(content.length, offset, byteCount);
return new RequestBody() {
@Override
- public MediaType contentType() {
- return contentType;
+ public MediaType mediaType() {
+ return mediaType;
}
@Override
- public long contentLength() {
+ public long length() {
return byteCount;
}
@@ -140,23 +137,23 @@ public void writeTo(BufferSink sink) throws IOException {
/**
* 新的请求体,该请求体传输{@code file}的内容
*
- * @param contentType 请求类型
- * @param file 文件
+ * @param mediaType 请求类型
+ * @param file 文件
* @return 传输请求体
*/
- public static RequestBody create(final MediaType contentType, final File file) {
+ public static RequestBody create(final MediaType mediaType, final File file) {
if (null == file) {
throw new NullPointerException("file == null");
}
return new RequestBody() {
@Override
- public MediaType contentType() {
- return contentType;
+ public MediaType mediaType() {
+ return mediaType;
}
@Override
- public long contentLength() {
+ public long length() {
return file.length();
}
@@ -172,7 +169,7 @@ public void writeTo(BufferSink sink) throws IOException {
/**
* @return 返回此主体的媒体类型
*/
- public abstract MediaType contentType();
+ public abstract MediaType mediaType();
/**
* 返回调用{@link #writeTo}时写入{@code sink}的字节数,如果该计数未知,则返回-1
@@ -180,7 +177,7 @@ public void writeTo(BufferSink sink) throws IOException {
* @return 计数信息
* @throws IOException 异常
*/
- public long contentLength() throws IOException {
+ public long length() throws IOException {
return -1;
}
@@ -242,4 +239,5 @@ public boolean isDuplex() {
public boolean isOneShot() {
return false;
}
-}
+
+}
\ No newline at end of file
diff --git a/bus-http/src/main/java/org/aoju/bus/http/bodys/ResponseBody.java b/bus-http/src/main/java/org/aoju/bus/http/bodys/ResponseBody.java
index 1292159099..c108be9158 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/bodys/ResponseBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/bodys/ResponseBody.java
@@ -70,59 +70,55 @@ public abstract class ResponseBody implements Closeable {
private Reader reader;
/**
- * 返回一个传输{@code content}的新响应体。如果{@code contentType}是非空且缺少字符集,则使用UTF-8
+ * 返回一个传输{@code content}的新响应体。如果{@code mediaType}是非空且缺少字符集,则使用UTF-8
*
- * @param contentType 媒体类型
- * @param content 内容
+ * @param mediaType 媒体类型
+ * @param content 内容
* @return 新响应体
*/
- public static ResponseBody create(MediaType contentType, String content) {
+ public static ResponseBody create(MediaType mediaType, String content) {
java.nio.charset.Charset charset = Charset.UTF_8;
- if (null != contentType) {
- charset = contentType.charset();
- if (null == charset) {
- charset = Charset.UTF_8;
- contentType = MediaType.valueOf(contentType + "; charset=utf-8");
- }
+ if (null != mediaType) {
+ charset = null != mediaType.charset() ? mediaType.charset() : Charset.UTF_8;
}
Buffer buffer = new Buffer().writeString(content, charset);
- return create(contentType, buffer.size(), buffer);
+ return create(mediaType, buffer.size(), buffer);
}
/**
* 新的响应体,它传输{@code content}
*
- * @param contentType 媒体类型
- * @param content 内容
+ * @param mediaType 媒体类型
+ * @param content 内容
* @return 新响应体
*/
- public static ResponseBody create(final MediaType contentType, byte[] content) {
+ public static ResponseBody create(final MediaType mediaType, byte[] content) {
Buffer buffer = new Buffer().write(content);
- return create(contentType, content.length, buffer);
+ return create(mediaType, content.length, buffer);
}
/**
* 新的响应体,它传输{@code content}
*
- * @param contentType 媒体类型
- * @param content 内容
+ * @param mediaType 媒体类型
+ * @param content 内容
* @return 新响应体
*/
- public static ResponseBody create(MediaType contentType, ByteString content) {
+ public static ResponseBody create(MediaType mediaType, ByteString content) {
Buffer buffer = new Buffer().write(content);
- return create(contentType, content.size(), buffer);
+ return create(mediaType, content.size(), buffer);
}
/**
* 新的响应体,它传输{@code content}
*
- * @param contentType 媒体类型
- * @param contentLength 内容大小
- * @param content 内容
+ * @param mediaType 媒体类型
+ * @param length 内容大小
+ * @param content 内容
* @return 新响应体
*/
- public static ResponseBody create(final MediaType contentType,
- final long contentLength,
+ public static ResponseBody create(final MediaType mediaType,
+ final long length,
final BufferSource content) {
if (null == content) {
throw new NullPointerException("source == null");
@@ -130,13 +126,13 @@ public static ResponseBody create(final MediaType contentType,
return new ResponseBody() {
@Override
- public MediaType contentType() {
- return contentType;
+ public MediaType mediaType() {
+ return mediaType;
}
@Override
- public long contentLength() {
- return contentLength;
+ public long length() {
+ return length;
}
@Override
@@ -146,13 +142,13 @@ public BufferSource source() {
};
}
- public abstract MediaType contentType();
+ public abstract MediaType mediaType();
/**
* Returns the number of bytes in that will returned by {@link #bytes}, or {@link #byteStream}, or
* -1 if unknown.
*/
- public abstract long contentLength();
+ public abstract long length();
public final InputStream byteStream() {
return source().inputStream();
@@ -168,7 +164,7 @@ public final InputStream byteStream() {
* possibility for your response.
*/
public final byte[] bytes() throws IOException {
- long contentLength = contentLength();
+ long contentLength = length();
if (contentLength > Integer.MAX_VALUE) {
throw new IOException("Cannot buffer entire body for content length: " + contentLength);
}
@@ -226,8 +222,8 @@ public final String string() throws IOException {
}
private java.nio.charset.Charset charset() {
- MediaType contentType = contentType();
- return null != contentType ? contentType.charset(Charset.UTF_8) : Charset.UTF_8;
+ MediaType mediaType = mediaType();
+ return null != mediaType ? mediaType.charset(Charset.UTF_8) : Charset.UTF_8;
}
@Override
diff --git a/bus-http/src/main/java/org/aoju/bus/http/cache/Cache.java b/bus-http/src/main/java/org/aoju/bus/http/cache/Cache.java
index 31b0a392bd..d121b08ca7 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/cache/Cache.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/cache/Cache.java
@@ -594,20 +594,20 @@ public boolean matches(Request request, Response response) {
}
public Response response(DiskLruCache.Snapshot snapshot) {
- String contentType = responseHeaders.get(Header.CONTENT_TYPE);
- String contentLength = responseHeaders.get(Header.CONTENT_LENGTH);
- Request cacheRequest = new Request.Builder()
+ String mediaType = responseHeaders.get(Header.CONTENT_TYPE);
+ String length = responseHeaders.get(Header.CONTENT_LENGTH);
+ Request request = new Request.Builder()
.url(url)
.method(requestMethod, null)
.headers(varyHeaders)
.build();
return new Response.Builder()
- .request(cacheRequest)
+ .request(request)
.protocol(protocol)
.code(code)
.message(message)
.headers(responseHeaders)
- .body(new CacheResponseBody(snapshot, contentType, contentLength))
+ .body(new CacheResponseBody(snapshot, mediaType, length))
.handshake(handshake)
.sentRequestAtMillis(sentRequestMillis)
.receivedResponseAtMillis(receivedResponseMillis)
@@ -618,14 +618,14 @@ public Response response(DiskLruCache.Snapshot snapshot) {
private static class CacheResponseBody extends ResponseBody {
final DiskLruCache.Snapshot snapshot;
private final BufferSource bodySource;
- private final String contentType;
- private final String contentLength;
+ private final String mediaType;
+ private final String length;
CacheResponseBody(final DiskLruCache.Snapshot snapshot,
- String contentType, String contentLength) {
+ String mediaType, String length) {
this.snapshot = snapshot;
- this.contentType = contentType;
- this.contentLength = contentLength;
+ this.mediaType = mediaType;
+ this.length = length;
Source source = snapshot.getSource(ENTRY_BODY);
bodySource = IoKit.buffer(new AssignSource(source) {
@@ -638,14 +638,14 @@ public void close() throws IOException {
}
@Override
- public MediaType contentType() {
- return null != contentType ? MediaType.valueOf(contentType) : null;
+ public MediaType mediaType() {
+ return null != mediaType ? MediaType.valueOf(mediaType) : null;
}
@Override
- public long contentLength() {
+ public long length() {
try {
- return null != contentLength ? Long.parseLong(contentLength) : -1;
+ return null != length ? Long.parseLong(length) : -1;
} catch (NumberFormatException e) {
return -1;
}
diff --git a/bus-http/src/main/java/org/aoju/bus/http/cache/CacheInterceptor.java b/bus-http/src/main/java/org/aoju/bus/http/cache/CacheInterceptor.java
index b9d8e7cd64..f1b6378556 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/cache/CacheInterceptor.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/cache/CacheInterceptor.java
@@ -292,10 +292,10 @@ public void close() throws IOException {
}
};
- String contentType = response.header(Header.CONTENT_TYPE);
- long contentLength = response.body().contentLength();
+ String mediaType = response.header(Header.CONTENT_TYPE);
+ long contentLength = response.body().length();
return response.newBuilder()
- .body(new RealResponseBody(contentType, contentLength, IoKit.buffer(cacheWritingSource)))
+ .body(new RealResponseBody(mediaType, contentLength, IoKit.buffer(cacheWritingSource)))
.build();
}
diff --git a/bus-http/src/main/java/org/aoju/bus/http/metric/http/BridgeInterceptor.java b/bus-http/src/main/java/org/aoju/bus/http/metric/http/BridgeInterceptor.java
index 608c89ccc2..090d3ed28a 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/metric/http/BridgeInterceptor.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/metric/http/BridgeInterceptor.java
@@ -57,19 +57,19 @@ public BridgeInterceptor(CookieJar cookieJar) {
@Override
public Response intercept(Chain chain) throws IOException {
- Request userRequest = chain.request();
- Request.Builder requestBuilder = userRequest.newBuilder();
+ Request request = chain.request();
+ Request.Builder requestBuilder = request.newBuilder();
- RequestBody body = userRequest.body();
+ RequestBody body = request.body();
if (null != body) {
- MediaType contentType = body.contentType();
- if (null != contentType) {
- requestBuilder.header(Header.CONTENT_TYPE, contentType.toString());
+ MediaType mediaType = body.mediaType();
+ if (null != mediaType) {
+ requestBuilder.header(Header.CONTENT_TYPE, mediaType.toString());
}
- long contentLength = body.contentLength();
- if (contentLength != -1) {
- requestBuilder.header(Header.CONTENT_LENGTH, Long.toString(contentLength));
+ long length = body.length();
+ if (length != -1) {
+ requestBuilder.header(Header.CONTENT_LENGTH, Long.toString(length));
requestBuilder.removeHeader(Header.TRANSFER_ENCODING);
} else {
requestBuilder.header(Header.TRANSFER_ENCODING, "chunked");
@@ -77,38 +77,38 @@ public Response intercept(Chain chain) throws IOException {
}
}
- if (null == userRequest.header(Header.HOST)) {
- requestBuilder.header(Header.HOST, Builder.hostHeader(userRequest.url(), false));
+ if (null == request.header(Header.HOST)) {
+ requestBuilder.header(Header.HOST, Builder.hostHeader(request.url(), false));
}
- if (null == userRequest.header(Header.CONNECTION)) {
+ if (null == request.header(Header.CONNECTION)) {
requestBuilder.header(Header.CONNECTION, Header.KEEP_ALIVE);
}
// If we add an "Accept-Encoding: gzip" header field we're responsible for also decompressing
// the transfer stream.
boolean transparentGzip = false;
- if (null == userRequest.header(Header.ACCEPT_ENCODING)
- && null == userRequest.header("Range")) {
+ if (null == request.header(Header.ACCEPT_ENCODING)
+ && null == request.header("Range")) {
transparentGzip = true;
requestBuilder.header(Header.ACCEPT_ENCODING, "gzip");
}
- List cookies = cookieJar.loadForRequest(userRequest.url());
+ List cookies = cookieJar.loadForRequest(request.url());
if (!cookies.isEmpty()) {
requestBuilder.header(Header.COOKIE, cookieHeader(cookies));
}
- if (null == userRequest.header(Header.USER_AGENT)) {
+ if (null == request.header(Header.USER_AGENT)) {
requestBuilder.header(Header.USER_AGENT, "Httpd/" + Version.all());
}
Response networkResponse = chain.proceed(requestBuilder.build());
- Headers.receiveHeaders(cookieJar, userRequest.url(), networkResponse.headers());
+ Headers.receiveHeaders(cookieJar, request.url(), networkResponse.headers());
Response.Builder responseBuilder = networkResponse.newBuilder()
- .request(userRequest);
+ .request(request);
if (transparentGzip
&& "gzip".equalsIgnoreCase(networkResponse.header(Header.CONTENT_ENCODING))
@@ -119,8 +119,8 @@ public Response intercept(Chain chain) throws IOException {
.removeAll(Header.CONTENT_LENGTH)
.build();
responseBuilder.headers(strippedHeaders);
- String contentType = networkResponse.header(Header.CONTENT_TYPE);
- responseBuilder.body(new RealResponseBody(contentType, -1L, IoKit.buffer(responseBody)));
+ String mediaType = networkResponse.header(Header.CONTENT_TYPE);
+ responseBuilder.body(new RealResponseBody(mediaType, -1L, IoKit.buffer(responseBody)));
}
return responseBuilder.build();
diff --git a/bus-http/src/main/java/org/aoju/bus/http/metric/http/CallServerInterceptor.java b/bus-http/src/main/java/org/aoju/bus/http/metric/http/CallServerInterceptor.java
index e4693997d1..89b87b71f3 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/metric/http/CallServerInterceptor.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/metric/http/CallServerInterceptor.java
@@ -150,9 +150,9 @@ public Response intercept(Chain chain) throws IOException {
exchange.noNewExchangesOnConnection();
}
- if ((code == 204 || code == 205) && response.body().contentLength() > 0) {
+ if ((code == 204 || code == 205) && response.body().length() > 0) {
throw new ProtocolException(
- "HTTP " + code + " had non-zero Content-Length: " + response.body().contentLength());
+ "HTTP " + code + " had non-zero Content-Length: " + response.body().length());
}
return response;
diff --git a/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/CoverHttp.java b/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/CoverHttp.java
index c5c2a0f1bc..4ad14164c3 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/CoverHttp.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/CoverHttp.java
@@ -570,7 +570,7 @@ protected Request prepareRequest(String method) {
private long contentLength(RequestBody reqBody) {
try {
- return reqBody.contentLength();
+ return reqBody.length();
} catch (IOException e) {
throw new InstrumentException("Cannot get the length of the request body", e);
}
@@ -741,8 +741,8 @@ protected CoverResult timeoutResult() {
public Charset charset(Response response) {
ResponseBody b = response.body();
- MediaType type = null != b ? b.contentType() : null;
- return null != type ? type.charset(charset) : charset;
+ MediaType mediaType = null != b ? b.mediaType() : null;
+ return null != mediaType ? mediaType.charset(charset) : charset;
}
static class FilePara {
diff --git a/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/ProgressBody.java b/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/ProgressBody.java
index a2517c2edd..75cded1ee3 100644
--- a/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/ProgressBody.java
+++ b/bus-http/src/main/java/org/aoju/bus/http/plugin/httpv/ProgressBody.java
@@ -61,13 +61,13 @@ public ProgressBody(RequestBody requestBody, Callback
-
- com.alibaba
- druid
- ${druid.version}
- true
-
com.zaxxer
- HikariCP-java6
+ HikariCP
${hikari.version}
true
- com.mchange
- c3p0
- ${c3p0.version}
- true
-
-
- org.apache.commons
- commons-dbcp2
- ${dbcp2.version}
+ com.alibaba
+ druid
+ ${druid.version}
true