/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * 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 com.google.api.server.spi.response;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;

import java.io.IOException;

/**
 * A {@link com.fasterxml.jackson.core.PrettyPrinter} that mimics legacy formatting.
 */
public class EndpointsPrettyPrinter extends DefaultPrettyPrinter {
  public EndpointsPrettyPrinter() {
    SingleSpaceIndenter indenter = new SingleSpaceIndenter();
    indentArraysWith(indenter);
    indentObjectsWith(indenter);
  }

  @Override
  public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
    jg.writeRaw(": ");
  }

  @Override
  public EndpointsPrettyPrinter createInstance() {
    return this;
  }

  private static class SingleSpaceIndenter implements Indenter {
    @Override
    public void writeIndentation(JsonGenerator jg, int level) throws IOException {
      jg.writeRaw('\n');
      for (int i = 0; i < level; i++) {
        jg.writeRaw(' ');
      }
    }

    @Override
    public boolean isInline() {
      return false;
    }
  }
}

@@ -994,22 +994,89 @@
 ) %7B%0A    
-Single
+this(1);%0A  %7D%0A%0A  public EndpointsPrettyPrinter(int spacesPerIndent) %7B%0A    
 SpaceInd
@@ -1096,22 +1096,16 @@
 r = new 
-Single
 SpaceInd
@@ -1110,16 +1110,31 @@
 ndenter(
+spacesPerIndent
 );%0A    i
@@ -1435,14 +1435,8 @@
 ss S
-ingleS
 pace
@@ -1465,16 +1465,286 @@
 denter %7B
+%0A    private final String indent;%0A%0A    SpaceIndenter(int spacesPerIndent) %7B%0A      StringBuilder builder = new StringBuilder(spacesPerIndent);%0A      for (int i = 0; i %3C spacesPerIndent; i++) %7B%0A        builder.append(' ');%0A      %7D%0A      indent = builder.toString();%0A    %7D%0A
 %0A    @Ov
@@ -1918,19 +1918,22 @@
 riteRaw(
-' '
+indent
 );%0A     

add indent level option to EndpointsPrettyPrinter