]> git.basschouten.com Git - openhab-addons.git/blob
a4ebce2b7d1ef2924bf6287f052c1de68a4e65be
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mqtt.generic.tools;
14
15 import java.io.IOException;
16 import java.io.StringReader;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 import com.google.gson.stream.JsonReader;
22 import com.google.gson.stream.JsonToken;
23
24 /**
25  * JsonReader delegate.
26  *
27  * This class allows to overwrite parts of the {@link JsonReader} functionality
28  *
29  * @author Jochen Klein - Initial contribution
30  */
31 @NonNullByDefault
32 public class JsonReaderDelegate extends JsonReader {
33
34     /**
35      * Retrieve the 'original' {@link JsonReader} after removing all {@link JsonReaderDelegate}s
36      *
37      * @param in the current {@link JsonReader}
38      * @return the original {@link JsonReader} after removing all {@link JsonReaderDelegate}s
39      */
40     public static JsonReader getDelegate(final JsonReader in) {
41         JsonReader current = in;
42         while (current instanceof JsonReaderDelegate) {
43             current = ((JsonReaderDelegate) current).delegate;
44         }
45         return current;
46     }
47
48     private final JsonReader delegate;
49
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;
54     }
55
56     @Override
57     public void beginArray() throws IOException {
58         delegate.beginArray();
59     }
60
61     @Override
62     public void beginObject() throws IOException {
63         delegate.beginObject();
64     }
65
66     @Override
67     public void close() throws IOException {
68         delegate.close();
69     }
70
71     @Override
72     public void endArray() throws IOException {
73         delegate.endArray();
74     }
75
76     @Override
77     public void endObject() throws IOException {
78         delegate.endObject();
79     }
80
81     @Override
82     public boolean equals(@Nullable Object obj) {
83         return delegate.equals(obj);
84     }
85
86     @Override
87     public String getPath() {
88         return delegate.getPath();
89     }
90
91     @Override
92     public boolean hasNext() throws IOException {
93         return delegate.hasNext();
94     }
95
96     @Override
97     public int hashCode() {
98         return delegate.hashCode();
99     }
100
101     @Override
102     public boolean nextBoolean() throws IOException {
103         return delegate.nextBoolean();
104     }
105
106     @Override
107     public double nextDouble() throws IOException {
108         return delegate.nextDouble();
109     }
110
111     @Override
112     public int nextInt() throws IOException {
113         return delegate.nextInt();
114     }
115
116     @Override
117     public long nextLong() throws IOException {
118         return delegate.nextLong();
119     }
120
121     @Override
122     public String nextName() throws IOException {
123         return delegate.nextName();
124     }
125
126     @Override
127     public void nextNull() throws IOException {
128         delegate.nextNull();
129     }
130
131     @Override
132     public String nextString() throws IOException {
133         return delegate.nextString();
134     }
135
136     @Override
137     public JsonToken peek() throws IOException {
138         return delegate.peek();
139     }
140
141     @Override
142     public void skipValue() throws IOException {
143         delegate.skipValue();
144     }
145
146     @Override
147     public String toString() {
148         return delegate.toString();
149     }
150 }