• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 package com.android.internal.widget.remotecompose.core.operations.utilities;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 /** Utility serializer maintaining an indent buffer */
22 public class StringSerializer {
23     @NonNull StringBuffer mBuffer = new StringBuffer();
24 
25     @NonNull
26     String mIndentBuffer = "                                                                      ";
27 
28     /**
29      * Append some content to the current buffer
30      *
31      * @param indent the indentation level to use
32      * @param content content to append
33      */
append(int indent, @Nullable String content)34     public void append(int indent, @Nullable String content) {
35         String indentation = mIndentBuffer.substring(0, indent);
36         mBuffer.append(indentation);
37         mBuffer.append(indentation);
38         mBuffer.append(content);
39         mBuffer.append("\n");
40     }
41 
42     /** Reset the buffer */
reset()43     public void reset() {
44         mBuffer = new StringBuffer();
45     }
46 
47     /**
48      * Return a string representation of the buffer
49      *
50      * @return string representation
51      */
52     @NonNull
53     @Override
toString()54     public String toString() {
55         return mBuffer.toString();
56     }
57 }
58