用了okhttp官方的HttpLoggingInterceptor日志打印,发现上传大文件时会出现内存溢出问题。
写了个拦截器屏蔽了文件类型。能够打印method、url、header、参数和返回内容,以及请求耗时时间。
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;
public class LogInterceptor implements Interceptor {
public static String TAG = LogInterceptor.class.getSimpleName();
private static HashMap<String,String> headerIgnoreMap = new HashMap<>();
static {
headerIgnoreMap.put("Host", "");
headerIgnoreMap.put("Connection", "");
headerIgnoreMap.put("Accept-Encoding", "");
}
protected void log(String message) {
Log.d(TAG, message);
}
private boolean isPlainText(MediaType mediaType) {
if (null != mediaType)</