Loading... java代码 MyLog.java ```java package com.android.akamai; import android.util.Log; import androidx.annotation.NonNull; import java.nio.charset.StandardCharsets; public class MyLog { public static String TAG = "TAG"; public static void i(String content){ // Log.i(TAG,content); largeLog(content); } private static final int MAX_LOG_BYTES = 4000; public static void largeLog(@NonNull String content) { int size = content.getBytes(StandardCharsets.UTF_8).length; if (size > MAX_LOG_BYTES) { String text = trim(content, MAX_LOG_BYTES); Log.println(Log.INFO, TAG, text); largeLog(content.substring(text.length())); } else { Log.println(Log.INFO, TAG, content); } } public static String trim(String text, int size) { byte[] inputBytes = text.getBytes(StandardCharsets.UTF_8); byte[] outputBytes = new byte[size]; System.arraycopy(inputBytes, 0, outputBytes, 0, size); String result = new String(outputBytes, StandardCharsets.UTF_8); // check if last character is truncated int lastIndex = result.length() - 1; if (lastIndex > 0 && result.charAt(lastIndex) != text.charAt(lastIndex)) { // last character is truncated so remove the last character return result.substring(0, lastIndex); } return result; } } ``` 最后修改:2024 年 08 月 28 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏