Move yang-common(-netty)
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / JsonWriterFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.codec.gson;
9
10 import com.google.common.annotations.Beta;
11 import com.google.gson.stream.JsonWriter;
12 import java.io.Writer;
13
14 /**
15  * Factory Method class for JsonWriter creation.
16  */
17 @Beta
18 public final class JsonWriterFactory {
19     private JsonWriterFactory() {
20         // Hidden on purpose
21     }
22
23     /**
24      * Create a new JsonWriter, which writes to the specified output writer.
25      *
26      * @param writer Output writer
27      * @return A JsonWriter instance
28      */
29     public static JsonWriter createJsonWriter(final Writer writer) {
30         return new JsonWriter(writer);
31     }
32
33     /**
34      * Create a new JsonWriter, which writes to the specified output writer.
35      *
36      * @param writer Output writer
37      * @param indentSize size of the indent
38      * @return A JsonWriter instance
39      */
40     public static JsonWriter createJsonWriter(final Writer writer, final int indentSize) {
41         JsonWriter jsonWriter = new JsonWriter(writer);
42         final String indent = " ".repeat(indentSize);
43         jsonWriter.setIndent(indent);
44         return jsonWriter;
45     }
46 }