Eliminate FormatParameters
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / FormattableBody.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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.restconf.api;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.restconf.api.query.PrettyPrintParam;
16 import org.opendaylight.yangtools.concepts.Immutable;
17
18 /**
19  * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format using particular
20  * {@link PrettyPrintParam}.
21  */
22 @NonNullByDefault
23 public abstract class FormattableBody implements Immutable {
24     /**
25      * Write the content of this body as a JSON document.
26      *
27      * @param prettyPrint a {@link PrettyPrintParam}
28      * @param out output stream
29      * @throws IOException if an IO error occurs.
30      */
31     public abstract void formatToJSON(PrettyPrintParam prettyPrint, OutputStream out) throws IOException;
32
33     /**
34      * Write the content of this body as an XML document.
35      *
36      * @param prettyPrint a {@link PrettyPrintParam}
37      * @param out output stream
38      * @throws IOException if an IO error occurs.
39      */
40     public abstract void formatToXML(PrettyPrintParam prettyPrint, OutputStream out) throws IOException;
41
42     protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
43
44     @Override
45     public final String toString() {
46         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
47     }
48 }