| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.util; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.os.Build; |
| 21 |
|
| 22 |
import java.io.Writer; |
| 23 |
|
| 24 |
|
| 25 |
public class LogWriter extends Writer { |
| 26 |
private final int mPriority; |
| 27 |
private final String mTag; |
| 28 |
private final int mBuffer; |
| 29 |
private StringBuilder mBuilder = new StringBuilder(128); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 44 |
public LogWriter(int priority, String tag) { |
| 45 |
mPriority = priority; |
| 46 |
mTag = tag; |
| 47 |
mBuffer = Log.LOG_ID_MAIN; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public LogWriter(int priority, String tag, int buffer) { |
| 55 |
mPriority = priority; |
| 56 |
mTag = tag; |
| 57 |
mBuffer = buffer; |
| 58 |
} |
| 59 |
|
| 60 |
@Override public void close() { |
| 61 |
flushBuilder(); |
| 62 |
} |
| 63 |
|
| 64 |
@Override public void flush() { |
| 65 |
flushBuilder(); |
| 66 |
} |
| 67 |
|
| 68 |
@Override public void write(char[] buf, int offset, int count) { |
| 69 |
for(int i = 0; i < count; i++) { |
| 70 |
char c = buf[offset + i]; |
| 71 |
if ( c == '\n') { |
| 72 |
flushBuilder(); |
| 73 |
} |
| 74 |
else { |
| 75 |
mBuilder.append(c); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
private void flushBuilder() { |
| 81 |
if (mBuilder.length() > 0) { |
| 82 |
Log.println_native(mBuffer, mPriority, mTag, mBuilder.toString()); |
| 83 |
mBuilder.delete(0, mBuilder.length()); |
| 84 |
} |
| 85 |
} |
| 86 |
} |