Here you can find the source of indentCode(String code, int indentLevel)
public static String indentCode(String code, int indentLevel)
//package com.java2s; /*//from w ww . ja v a2 s .c o m * Copyright 2013 Red Hat, Inc. and/or its affiliates. * * Licensed under the Eclipse Public License version 1.0, available at * http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Adds indentLevel spaces to every line of code. */ public static String indentCode(String code, int indentLevel) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < indentLevel; i++) { sb.append(' '); } String indent = sb.toString(); sb = new StringBuilder(); String[] lines = code.split("\n"); for (String line : lines) { sb.append(indent); sb.append(line); sb.append('\n'); } return sb.toString(); } }