• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wuwen5 / hessian / 17023139374

17 Aug 2025 09:39AM UTC coverage: 44.094% (-0.08%) from 44.169%
17023139374

push

github

wuwen5
refactor: code clean,fix sonar check

1203 of 2989 branches covered (40.25%)

Branch coverage included in aggregate %.

2903 of 6323 relevant lines covered (45.91%)

1.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.35
hessian2-codec/src/main/java/io/github/wuwen5/hessian/io/AbstractHessianDecoder.java
1
/*
2
 * Copyright (c) 2001-2004 Caucho Technology, Inc.  All rights reserved.
3
 *
4
 * The Apache Software License, Version 1.1
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 *
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in
15
 *    the documentation and/or other materials provided with the
16
 *    distribution.
17
 *
18
 * 3. The end-user documentation included with the redistribution, if
19
 *    any, must include the following acknowlegement:
20
 *       "This product includes software developed by the
21
 *        Caucho Technology (http://www.caucho.com/)."
22
 *    Alternately, this acknowlegement may appear in the software itself,
23
 *    if and wherever such third-party acknowlegements normally appear.
24
 *
25
 * 4. The names "Burlap", "Resin", and "Caucho" must not be used to
26
 *    endorse or promote products derived from this software without prior
27
 *    written permission. For written permission, please contact
28
 *    info@caucho.com.
29
 *
30
 * 5. Products derived from this software may not be called "Resin"
31
 *    nor may "Resin" appear in their names without prior written
32
 *    permission of Caucho Technology.
33
 *
34
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
 * DISCLAIMED.  IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
 *
46
 * @author Scott Ferguson
47
 */
48

49
package io.github.wuwen5.hessian.io;
50

51
import java.io.Closeable;
52
import java.io.IOException;
53
import java.io.InputStream;
54
import java.io.OutputStream;
55
import java.io.Reader;
56

57
/**
58
 * Abstract base class for Hessian requests.  Hessian users should only
59
 * need to use the methods in this class.
60
 */
61
public abstract class AbstractHessianDecoder implements Closeable {
3✔
62
    private HessianRemoteResolver resolver;
63
    private byte[] buffer;
64

65
    /**
66
     * Initialize the Hessian stream with the underlying input stream.
67
     */
68
    public void init(InputStream is) {}
×
69

70
    /**
71
     * Sets the resolver used to lookup remote objects.
72
     */
73
    public void setRemoteResolver(HessianRemoteResolver resolver) {
74
        this.resolver = resolver;
×
75
    }
×
76

77
    /**
78
     * Sets the resolver used to lookup remote objects.
79
     */
80
    public HessianRemoteResolver getRemoteResolver() {
81
        return resolver;
×
82
    }
83

84
    /**
85
     * Reads a boolean
86
     *
87
     * <pre>
88
     * T
89
     * F
90
     * </pre>
91
     * @throws IOException if an I/O error occurs
92
     * @return the boolean value
93
     */
94
    public abstract boolean readBoolean() throws IOException;
95

96
    /**
97
     * Reads a null
98
     *
99
     * <pre>
100
     * N
101
     * </pre>
102
     * @throws IOException if an I/O error occurs
103
     */
104
    public abstract void readNull() throws IOException;
105

106
    /**
107
     * Reads an integer
108
     *
109
     * <pre>
110
     * I b32 b24 b16 b8
111
     * </pre>
112
     * @throws IOException if an I/O error occurs
113
     * @return the integer value
114
     */
115
    public abstract int readInt() throws IOException;
116

117
    /**
118
     * Reads a long
119
     *
120
     * <pre>
121
     * L b64 b56 b48 b40 b32 b24 b16 b8
122
     * </pre>
123
     * @throws IOException if an I/O error occurs
124
     * @return the long value
125
     */
126
    public abstract long readLong() throws IOException;
127

128
    /**
129
     * Reads a double.
130
     *
131
     * <pre>
132
     * D b64 b56 b48 b40 b32 b24 b16 b8
133
     * </pre>
134
     * @throws IOException if an I/O error occurs
135
     * @return the double value
136
     */
137
    public abstract double readDouble() throws IOException;
138

139
    /**
140
     * Reads a date.
141
     *
142
     * <pre>
143
     * T b64 b56 b48 b40 b32 b24 b16 b8
144
     * </pre>
145
     * @throws IOException if an I/O error occurs
146
     * @return the date value in milliseconds since the epoch
147
     */
148
    public abstract long readUTCDate() throws IOException;
149

150
    /**
151
     * Reads a string encoded in UTF-8
152
     *
153
     * <pre>
154
     * s b16 b8 non-final string chunk
155
     * S b16 b8 final string chunk
156
     * </pre>
157
     * @throws IOException if an I/O error occurs
158
     * @return the string value
159
     */
160
    public abstract String readString() throws IOException;
161

162
    /**
163
     * Starts reading a string.  All the characters must be read before
164
     * calling the next method.  The actual characters will be read with
165
     * the reader's read() or read(char [], int, int).
166
     *
167
     * <pre>
168
     * s b16 b8 non-final string chunk
169
     * S b16 b8 final string chunk
170
     * </pre>
171
     * @throws IOException if an I/O error occurs
172
     * @return a Reader for reading the string
173
     */
174
    public abstract Reader getReader() throws IOException;
175

176
    /**
177
     * Starts reading a byte array using an input stream.  All the bytes
178
     * must be read before calling the following method.
179
     *
180
     * <pre>
181
     * b b16 b8 non-final binary chunk
182
     * B b16 b8 final binary chunk
183
     * </pre>
184
     * @throws IOException if an I/O error occurs
185
     * @return an InputStream for reading the bytes
186
     */
187
    public abstract InputStream readInputStream() throws IOException;
188

189
    /**
190
     * Reads data to an output stream.
191
     *
192
     * <pre>
193
     * b b16 b8 non-final binary chunk
194
     * B b16 b8 final binary chunk
195
     * </pre>
196
     */
197
    public boolean readToOutputStream(OutputStream os) throws IOException {
198

199
        try (InputStream is = readInputStream()) {
×
200

201
            if (is == null) {
×
202
                return false;
×
203
            }
204

205
            if (buffer == null) {
×
206
                buffer = new byte[256];
×
207
            }
208

209
            int len;
210

211
            while ((len = is.read(buffer, 0, buffer.length)) > 0) {
×
212
                os.write(buffer, 0, len);
×
213
            }
214

215
            return true;
×
216
        }
×
217
    }
218

219
    /**
220
     * Reads a byte array.
221
     *
222
     * <pre>
223
     * b b16 b8 non-final binary chunk
224
     * B b16 b8 final binary chunk
225
     * </pre>
226
     * @throws IOException if an I/O error occurs
227
     * @return the byte array
228
     */
229
    public abstract byte[] readBytes() throws IOException;
230

231
    /**
232
     * Reads an arbitrary object from the input stream.
233
     *
234
     * @throws IOException if an I/O error occurs
235
     * @param expectedClass the expected class if the protocol doesn't supply it.
236
     * @return the object read from the stream
237
     */
238
    public abstract Object readObject(Class<?> expectedClass) throws IOException;
239

240
    /**
241
     * Reads an arbitrary object from the input stream.
242
     * @throws IOException if an I/O error occurs
243
     * @return the object read from the stream
244
     */
245
    public abstract Object readObject() throws IOException;
246

247
    /**
248
     * Reads a remote object reference to the stream.  The type is the
249
     * type of the remote interface.
250
     *<pre>
251
     * <code>
252
     * 'r' 't' b16 b8 type url
253
     * </code>
254
     * </pre>
255
     * @throws IOException if an I/O error occurs
256
     * @return the remote object read from the stream
257
     */
258
    public abstract Object readRemote() throws IOException;
259

260
    /**
261
     * Reads a reference
262
     *
263
     * <pre>
264
     * R b32 b24 b16 b8
265
     * </pre>
266
     * @throws IOException if an I/O error occurs
267
     * @return the object reference read from the stream
268
     */
269
    public abstract Object readRef() throws IOException;
270

271
    /**
272
     * Adds an object reference.
273
     * @throws IOException if an I/O error occurs
274
     * @param obj the object to add as a reference
275
     * @return the reference index
276
     */
277
    public abstract int addRef(Object obj) throws IOException;
278

279
    /**
280
     * Sets an object reference.
281
     * @throws IOException if an I/O error occurs
282
     * @param i the reference index
283
     * @param obj the object to set as a reference
284
     */
285
    public abstract void setRef(int i, Object obj) throws IOException;
286

287
    /**
288
     * Resets the references for streaming.
289
     */
290
    public void resetReferences() {}
×
291

292
    /**
293
     * Reads the start of a list
294
     * @throws IOException if an I/O error occurs
295
     * @return the length of the list, or -1 if the list is unbounded
296
     */
297
    public abstract int readListStart() throws IOException;
298

299
    /**
300
     * Reads the length of a list.
301
     * @throws IOException if an I/O error occurs
302
     * @return the length of a list.
303
     */
304
    public abstract int readLength() throws IOException;
305

306
    /**
307
     * Reads the start of a map
308
     * @throws IOException if an I/O error occurs
309
     * @return the start of a map
310
     */
311
    public abstract int readMapStart() throws IOException;
312

313
    /**
314
     * Reads an object type.
315
     * @throws IOException if an I/O error occurs
316
     * @return an object type.
317
     */
318
    public abstract String readType() throws IOException;
319

320
    /**
321
     * Returns true if the data has ended.
322
     * @throws IOException if an I/O error occurs
323
     * @return true if the data has ended.
324
     */
325
    public abstract boolean isEnd() throws IOException;
326

327
    /**
328
     * Read the end byte
329
     * @throws IOException if an I/O error occurs
330
     */
331
    public abstract void readEnd() throws IOException;
332

333
    /**
334
     * Read the end byte
335
     * @throws IOException if an I/O error occurs
336
     */
337
    public abstract void readMapEnd() throws IOException;
338

339
    /**
340
     * Read the end byte
341
     * @throws IOException if an I/O error occurs
342
     */
343
    public abstract void readListEnd() throws IOException;
344
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc