2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.env.util;
24 import java.io.OutputStream;
25 import java.io.PrintWriter;
26 import java.io.Writer;
31 * Catch \n and indent according to current indent levels of JavaGen
33 public class IndentPrintWriter extends PrintWriter {
34 public static int INDENT = 2;
35 private boolean addIndent;
39 public IndentPrintWriter(Writer out) {
45 public IndentPrintWriter(OutputStream out) {
52 public void write(String str) {
53 int len = str.length();
54 for(int i=0;i<len;++i) {
55 write((int)str.charAt(i));
59 public void println() {
62 public void write(String str, int off, int len) {
63 len = Math.min(str.length(),off+len);
64 for(int i=off;i<len;++i) {
65 write((int)str.charAt(i));
68 public void write(int b) {
72 } else if (addIndent) {
82 public void write(char[] buf, int off, int len) {
83 for (int i = 0; i < len; ++i)
87 public void setIndent(int size) {
99 public void toCol(int idx) {
100 while(idx>col++)super.write((int)' ');
103 public int getIndent() {
107 public void toIndent() {
108 int end = indent * INDENT;
109 for (int i = 0; i < end; ++i) {
110 super.write((int) ' ');