*/
package org.opendaylight.restconf.api;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import java.io.IOException;
import org.opendaylight.yangtools.concepts.Immutable;
/**
- * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format.
+ * A body which is capable of being formatted to an {@link OutputStream} in either JSON or XML format using particular
+ * {@link FormatParameters}.
*/
@NonNullByDefault
public abstract class FormattableBody implements Immutable {
- private final FormatParameters format;
-
- protected FormattableBody(final FormatParameters format) {
- this.format = requireNonNull(format);
- }
-
/**
* Write the content of this body as a JSON document.
*
+ * @param format {@link FormatParameters}
* @param out output stream
* @throws IOException if an IO error occurs.
*/
- public final void formatToJSON(final OutputStream out) throws IOException {
- formatToJSON(requireNonNull(out), format);
- }
-
- protected abstract void formatToJSON(OutputStream out, FormatParameters format) throws IOException;
+ public abstract void formatToJSON(FormatParameters format, OutputStream out) throws IOException;
/**
* Write the content of this body as an XML document.
*
+ * @param format {@link FormatParameters}
* @param out output stream
* @throws IOException if an IO error occurs.
*/
- public final void formatToXML(final OutputStream out) throws IOException {
- formatToXML(requireNonNull(out), format);
- }
+ public abstract void formatToXML(FormatParameters format, OutputStream out) throws IOException;
- protected abstract void formatToXML(OutputStream out, FormatParameters format) throws IOException;
+ protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
@Override
public final String toString() {
return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
}
-
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return helper.add("prettyPrint", format.prettyPrint().value());
- }
}