00f5538da60de4db52e449b9f4dbb0c793099aa4
[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     private JsonWriterFactory() {
21         throw new UnsupportedOperationException();
22     }
23
24     /**
25      * Create a new JsonWriter, which writes to the specified output writer.
26      *
27      * @param writer Output writer
28      * @return A JsonWriter instance
29      */
30     public static JsonWriter createJsonWriter(final Writer writer) {
31         return new JsonWriter(writer);
32     }
33
34     /**
35      * Create a new JsonWriter, which writes to the specified output writer.
36      *
37      * @param writer Output writer
38      * @param indentSize size of the indent
39      * @return A JsonWriter instance
40      */
41     public static JsonWriter createJsonWriter(final Writer writer, final int indentSize) {
42         JsonWriter jsonWriter = new JsonWriter(writer);
43         final String indent = Strings.repeat(" ", indentSize);
44         jsonWriter.setIndent(indent);
45         return jsonWriter;
46     }
47 }