blob: 5ffaadc89d56f9c59ccf2d5eb30741569d451ac5 [file] [log] [blame]
/**
* Copyright (c) 2013-2015 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
*/
package org.eclipse.json.provisonnal.com.eclipsesource.json;
import java.io.IOException;
import java.io.Writer;
class PrettyPrinter extends JsonWriter {
private final char[] indentChars = { ' ', ' ' };
private int indent;
PrettyPrinter( Writer writer ) {
super( writer );
}
@Override
protected void writeArrayOpen() throws IOException {
indent++;
writer.write( '[' );
writeNewLine();
}
@Override
protected void writeArrayClose() throws IOException {
indent--;
writeNewLine();
writer.write( ']' );
}
@Override
protected void writeArraySeparator() throws IOException {
writer.write( ',' );
writeNewLine();
}
@Override
protected void writeObjectOpen() throws IOException {
indent++;
writer.write( '{' );
writeNewLine();
}
@Override
protected void writeObjectClose() throws IOException {
indent--;
writeNewLine();
writer.write( '}' );
}
@Override
protected void writeMemberSeparator() throws IOException {
writer.write( ':' );
writer.write( ' ' );
}
@Override
protected void writeObjectSeparator() throws IOException {
writer.write( ',' );
writeNewLine();
}
private void writeNewLine() throws IOException {
writer.write( '\n' );
for( int i = 0; i < indent; i++ ) {
writer.write( indentChars );
}
}
}