2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "DumpWriter.h"
19 #include <android-base/stringprintf.h>
20 #include <utils/String8.h>
22 using android::base::StringAppendV;
23 using android::String16;
24 using android::Vector;
28 const char kIndentString[] = " ";
29 const size_t kIndentStringLen = strlen(kIndentString);
34 DumpWriter::DumpWriter(int fd) : mIndentLevel(0), mFd(fd) {}
36 void DumpWriter::incIndent() {
37 if (mIndentLevel < 255) {
42 void DumpWriter::decIndent() {
43 if (mIndentLevel > 0) {
48 void DumpWriter::println(const std::string& line) {
50 for (int i = 0; i < mIndentLevel; i++) {
51 write(mFd, kIndentString, kIndentStringLen);
53 write(mFd, line.c_str(), line.size());
58 void DumpWriter::println(const char* fmt, ...) {
62 StringAppendV(&line, fmt, ap);