2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.generic.tools;
15 import java.io.IOException;
16 import java.io.StringReader;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
21 import com.google.gson.stream.JsonReader;
22 import com.google.gson.stream.JsonToken;
25 * JsonReader delegate.
27 * This class allows to overwrite parts of the {@link JsonReader} functionality
29 * @author Jochen Klein - Initial contribution
32 public class JsonReaderDelegate extends JsonReader {
35 * Retrieve the 'original' {@link JsonReader} after removing all {@link JsonReaderDelegate}s
37 * @param in the current {@link JsonReader}
38 * @return the original {@link JsonReader} after removing all {@link JsonReaderDelegate}s
40 public static JsonReader getDelegate(final JsonReader in) {
41 JsonReader current = in;
42 while (current instanceof JsonReaderDelegate) {
43 current = ((JsonReaderDelegate) current).delegate;
48 private final JsonReader delegate;
50 public JsonReaderDelegate(JsonReader delegate) {
51 /* super class demands a Reader. This will never be used as all requests are forwarded to the delegate */
52 super(new StringReader(""));
53 this.delegate = delegate;
57 public void beginArray() throws IOException {
58 delegate.beginArray();
62 public void beginObject() throws IOException {
63 delegate.beginObject();
67 public void close() throws IOException {
72 public void endArray() throws IOException {
77 public void endObject() throws IOException {
82 public boolean equals(@Nullable Object obj) {
83 return delegate.equals(obj);
87 public String getPath() {
88 return delegate.getPath();
92 public boolean hasNext() throws IOException {
93 return delegate.hasNext();
97 public int hashCode() {
98 return delegate.hashCode();
102 public boolean nextBoolean() throws IOException {
103 return delegate.nextBoolean();
107 public double nextDouble() throws IOException {
108 return delegate.nextDouble();
112 public int nextInt() throws IOException {
113 return delegate.nextInt();
117 public long nextLong() throws IOException {
118 return delegate.nextLong();
122 public String nextName() throws IOException {
123 return delegate.nextName();
127 public void nextNull() throws IOException {
132 public String nextString() throws IOException {
133 return delegate.nextString();
137 public JsonToken peek() throws IOException {
138 return delegate.peek();
142 public void skipValue() throws IOException {
143 delegate.skipValue();
147 public String toString() {
148 return delegate.toString();