3b3bf8d01344c8b9b47f568ce9a6e3f91cad0de8
[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.common.base.Strings;
12 import com.google.gson.stream.JsonWriter;
13 import java.io.Writer;
14
15 /**
16  * Factory Method class for JsonWriter creation
17  */
18 @Beta
19 public final class JsonWriterFactory {
20
21     private JsonWriterFactory() {
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(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(Writer writer, int indentSize) {
41         JsonWriter jsonWriter = new JsonWriter(writer);
42         final String indent = Strings.repeat(" ", indentSize);
43         jsonWriter.setIndent(indent);
44         return jsonWriter;
45     }
46
47 }