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