|
|
@@ -1,6 +1,5 @@
|
|
|
package com.railway.common.utils.http;
|
|
|
|
|
|
-import com.google.common.primitives.Bytes;
|
|
|
import com.railway.common.constant.Constants;
|
|
|
import com.railway.common.utils.StringUtils;
|
|
|
import java.io.BufferedReader;
|
|
|
@@ -254,11 +253,11 @@ public class HttpUtils {
|
|
|
* 将输入流中的数据写入字节数组
|
|
|
*/
|
|
|
public static byte[] inputStream2ByteArray(InputStream in) {
|
|
|
- List<Byte> byteList = new ArrayList<>();
|
|
|
- byte[] bytes = new byte[102400];
|
|
|
+ List<byte[]> byteList = new ArrayList<>();
|
|
|
+ byte[] bytes = new byte[40960];
|
|
|
try {
|
|
|
while (in.read(bytes) != -1) {
|
|
|
- byteList.addAll(Bytes.asList(bytes));
|
|
|
+ byteList.add(bytes);
|
|
|
}
|
|
|
}catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -269,7 +268,21 @@ public class HttpUtils {
|
|
|
e2.getStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- return Bytes.toArray(byteList);
|
|
|
+ return concatAll(byteList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] concatAll(List<byte []> rest) {
|
|
|
+ int totalLength = 0;
|
|
|
+ for (byte[] array : rest) {
|
|
|
+ totalLength += array.length;
|
|
|
+ }
|
|
|
+ byte[] result = new byte[totalLength];
|
|
|
+ int offset = 0;
|
|
|
+ for (byte[] array : rest) {
|
|
|
+ System.arraycopy(array, 0, result, offset, array.length);
|
|
|
+ offset += array.length;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private static class TrustAnyTrustManager implements X509TrustManager {
|