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 */ 16package com.android.chimpchat.adb; 17 18import com.android.ddmlib.IShellOutputReceiver; 19 20import java.util.logging.Level; 21import java.util.logging.Logger; 22 23/** 24 * Shell Output Receiver that sends shell output to a Logger. 25 */ 26public class LoggingOutputReceiver implements IShellOutputReceiver { 27 private final Logger log; 28 private final Level level; 29 30 public LoggingOutputReceiver(Logger log, Level level) { 31 this.log = log; 32 this.level = level; 33 } 34 35 public void addOutput(byte[] data, int offset, int length) { 36 String message = new String(data, offset, length); 37 for (String line : message.split("\n")) { 38 log.log(level, line); 39 } 40 } 41 42 public void flush() { } 43 44 public boolean isCancelled() { 45 return false; 46 } 47} 48