1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.core.util; 18 19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX; 20 21 import android.util.Log; 22 23 import androidx.annotation.RestrictTo; 24 25 import java.io.Writer; 26 27 /** 28 * @deprecated Copied to use sites. Do not use. 29 */ 30 @RestrictTo(LIBRARY_GROUP_PREFIX) 31 @Deprecated 32 public class LogWriter extends Writer { 33 private final String mTag; 34 private StringBuilder mBuilder = new StringBuilder(128); 35 36 /** 37 * Create a new Writer that sends to the log with the given priority 38 * and tag. 39 * 40 * @param tag A string tag to associate with each printed log statement. 41 */ LogWriter(String tag)42 public LogWriter(String tag) { 43 mTag = tag; 44 } 45 close()46 @Override public void close() { 47 flushBuilder(); 48 } 49 flush()50 @Override public void flush() { 51 flushBuilder(); 52 } 53 write(char[] buf, int offset, int count)54 @Override public void write(char[] buf, int offset, int count) { 55 for(int i = 0; i < count; i++) { 56 char c = buf[offset + i]; 57 if ( c == '\n') { 58 flushBuilder(); 59 } 60 else { 61 mBuilder.append(c); 62 } 63 } 64 } 65 flushBuilder()66 private void flushBuilder() { 67 if (mBuilder.length() > 0) { 68 Log.d(mTag, mBuilder.toString()); 69 mBuilder.delete(0, mBuilder.length()); 70 } 71 } 72 } 73