Reduce use of Status
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / AbstractPatchStatusBodyWriter.java
1 /*
2  * Copyright (c) 2021 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.nb.rfc8040.jersey.providers;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Type;
16 import javax.ws.rs.core.MediaType;
17 import javax.ws.rs.core.MultivaluedMap;
18 import javax.ws.rs.ext.MessageBodyWriter;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.restconf.server.api.PatchStatusContext;
21
22 abstract class AbstractPatchStatusBodyWriter implements MessageBodyWriter<PatchStatusContext> {
23     @Override
24     public final boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
25             final MediaType mediaType) {
26         return type.equals(PatchStatusContext.class);
27     }
28
29     @Override
30     public final void writeTo(final PatchStatusContext body, final Class<?> type, final Type genericType,
31             final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
32             final OutputStream entityStream) throws IOException {
33         writeTo(requireNonNull(body), requireNonNull(entityStream));
34     }
35
36     abstract void writeTo(@NonNull PatchStatusContext body, @NonNull OutputStream out) throws IOException;
37 }