/*
 * Copyright 2013 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package ru.finam.slf4jgwt.logging.console;

import java.io.FilterOutputStream;
import java.io.PrintStream;

/**
 * A {@link java.io.PrintStream} implementation that implements only a subset of methods that is enough to
 * be used with {@link Throwable#printStackTrace(java.io.PrintStream)}.
 * <p>
 * Note that all implemented methods marked as final except two methods that are safe to be
 * overridden by the subclasses: {@link #append(String)} {@link #newLine()}.
 */
public class StackTracePrintStream extends PrintStream {

  private final StringBuilder builder;

  public StackTracePrintStream(StringBuilder builder) {
    super(new FilterOutputStream(null));
    this.builder = builder;
  }

  /**
   * Appends some text to the output.
   */
  protected void append(String text) {
    builder.append(text);
  }

  /**
   * Appends a newline to the output.
   */
  protected void newLine() {
    builder.append("\n");
  }

  @Override
  public final void print(Object obj) {
    append(String.valueOf(obj));
  }

  @Override
  public final void println(Object obj) {
    append(String.valueOf(obj));
    newLine();
  }

  @Override
  public final void print(String str) {
    append(str);
  }

  @Override
  public final void println() {
    newLine();
  }

  @Override
  public final void println(String str) {
    append(str);
    newLine();
  }
}
@@ -643,22 +643,16 @@
 java.io.
-Filter
 OutputSt
@@ -875,193 +875,10 @@
 .%0A *
- %3Cp%3E%0A * Note that all implemented methods marked as final except two methods that are safe to be%0A * overridden by the subclasses: %7B@link #append(String)%7D %7B@link #newLine()%7D.%0A */%0Apublic 
+/%0A
 clas
@@ -1034,18 +1034,9 @@
 per(
-new Filter
+(
 Outp
@@ -1047,15 +1047,15 @@
 ream
-(
+) 
 null)
-)
 ;%0A  
@@ -1089,238 +1089,8 @@
  %7D%0A%0A
-  /**%0A   * Appends some text to the output.%0A   */%0A  protected void append(String text) %7B%0A    builder.append(text);%0A  %7D%0A%0A  /**%0A   * Appends a newline to the output.%0A   */%0A  protected void newLine() %7B%0A    builder.append(%22%5Cn%22);%0A  %7D%0A%0A
   @O
@@ -1145,35 +1145,27 @@
     
-append(String.valueOf
+builder.append
 (obj)
-)
 ;%0A  
@@ -1229,48 +1229,31 @@
     
-append(String.valueOf
+print
 (obj)
-)
 ;%0A    
-newLine
+println
 ();%0A
@@ -1305,32 +1305,40 @@
 ring str) %7B%0A    
+builder.
 append(str);%0A  %7D
@@ -1383,32 +1383,43 @@
 tln() %7B%0A    
-newLine(
+builder.append(%22%5Cn%22
 );%0A  %7D%0A%0A  @O
@@ -1472,22 +1472,21 @@
 ) %7B%0A    
-append
+print
 (str);%0A 
@@ -1492,15 +1492,15 @@
     
-newLine
+println
 ();%0A

refactor StackTracePrintStream