1
1
/*
2
2
* JACOB - CBOR implementation in Java.
3
- *
3
+ *
4
4
* (C) Copyright - 2013 - J.W. Janssen <[email protected] >
5
5
*/
6
6
package org .xipki .apppackage .cbor ;
@@ -18,7 +18,7 @@ public class CborDecoder {
18
18
19
19
/**
20
20
* Creates a new {@link CborDecoder} instance.
21
- *
21
+ *
22
22
* @param is the actual input stream to read the CBOR-encoded data from, cannot be <code>null</code>.
23
23
*/
24
24
public CborDecoder (InputStream is ) {
@@ -34,7 +34,7 @@ private static void fail(String msg, Object... args) throws IOException {
34
34
35
35
/**
36
36
* Peeks in the input stream for the upcoming type.
37
- *
37
+ *
38
38
* @return the upcoming type in the stream, or <code>null</code> in case of an end-of-stream.
39
39
* @throws IOException in case of I/O problems reading the CBOR-type from the underlying input stream.
40
40
*/
@@ -50,7 +50,7 @@ public CborType peekType() throws IOException {
50
50
51
51
/**
52
52
* Prolog to reading an array value in CBOR format.
53
- *
53
+ *
54
54
* @return the number of elements in the array to read, or -1 in case of infinite-length arrays.
55
55
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
56
56
*/
@@ -60,7 +60,7 @@ public long readArrayLength() throws IOException {
60
60
61
61
/**
62
62
* Reads a boolean value in CBOR format.
63
- *
63
+ *
64
64
* @return the read boolean.
65
65
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
66
66
*/
@@ -75,7 +75,8 @@ public boolean readBoolean() throws IOException {
75
75
/**
76
76
* Reads a byte string value in CBOR format.
77
77
*
78
- * @return the read byte string, never <code>null</code>. In case the encoded string has a length of 0, an empty string is returned.
78
+ * @return the read byte string, never <code>null</code>. In case the encoded string has a length of 0, an
79
+ * empty string is returned.
79
80
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
80
81
*/
81
82
public byte [] readByteString () throws IOException {
@@ -91,7 +92,7 @@ public byte[] readByteString() throws IOException {
91
92
92
93
/**
93
94
* Reads a signed or unsigned integer value in CBOR format.
94
- *
95
+ *
95
96
* @return the read integer value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
96
97
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
97
98
*/
@@ -106,7 +107,7 @@ public long readInt() throws IOException {
106
107
107
108
/**
108
109
* Reads a <code>null</code>-value in CBOR format.
109
- *
110
+ *
110
111
* @return always <code>null</code>.
111
112
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
112
113
*/
@@ -117,8 +118,9 @@ public Object readNull() throws IOException {
117
118
118
119
/**
119
120
* Reads an UTF-8 encoded string value in CBOR format.
120
- *
121
- * @return the read UTF-8 encoded string, never <code>null</code>. In case the encoded string has a length of 0, an empty string is returned.
121
+ *
122
+ * @return the read UTF-8 encoded string, never <code>null</code>. In case the encoded string has a length of
123
+ * 0, an empty string is returned.
122
124
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
123
125
*/
124
126
public String readTextString () throws IOException {
@@ -133,24 +135,27 @@ public String readTextString() throws IOException {
133
135
}
134
136
135
137
/**
136
- * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
137
- *
138
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given
139
+ * expectation.
140
+ *
138
141
* @param ib the expected major type, cannot be <code>null</code> (unchecked).
139
142
* @return either -1 if the major type was an signed integer, or 0 otherwise.
140
143
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
141
144
*/
142
145
protected long expectIntegerType (int ib ) throws IOException {
143
146
int majorType = ((ib & 0xFF ) >>> 5 );
144
147
if ((majorType != CborConstants .TYPE_UNSIGNED_INTEGER ) && (majorType != CborConstants .TYPE_NEGATIVE_INTEGER )) {
145
- fail ("Unexpected type: %s, expected type %s or %s!" , CborType .getName (majorType ), CborType .getName (CborConstants .TYPE_UNSIGNED_INTEGER ),
148
+ fail ("Unexpected type: %s, expected type %s or %s!" , CborType .getName (majorType ),
149
+ CborType .getName (CborConstants .TYPE_UNSIGNED_INTEGER ),
146
150
CborType .getName (CborConstants .TYPE_NEGATIVE_INTEGER ));
147
151
}
148
152
return -majorType ;
149
153
}
150
154
151
155
/**
152
- * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
153
- *
156
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given
157
+ * expectation.
158
+ *
154
159
* @param majorType the expected major type, cannot be <code>null</code> (unchecked).
155
160
* @return the read subtype, or payload, of the read major type.
156
161
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
@@ -164,8 +169,9 @@ protected int readMajorType(int majorType) throws IOException {
164
169
}
165
170
166
171
/**
167
- * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.
168
- *
172
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given
173
+ * expectations.
174
+ *
169
175
* @param majorType the expected major type, cannot be <code>null</code> (unchecked);
170
176
* @param subtype the expected subtype.
171
177
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
@@ -178,8 +184,9 @@ protected void readMajorTypeExact(int majorType, int subtype) throws IOException
178
184
}
179
185
180
186
/**
181
- * Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.
182
- *
187
+ * Reads the next major type from the underlying input stream, verifies whether it matches the given
188
+ * expectation, and decodes the payload into a size.
189
+ *
183
190
* @param majorType the expected major type, cannot be <code>null</code> (unchecked).
184
191
* @return the number of succeeding bytes, >= 0, or -1 if an infinite-length type is read.
185
192
* @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
@@ -190,7 +197,7 @@ protected long readMajorTypeWithSize(int majorType) throws IOException {
190
197
191
198
/**
192
199
* Reads an unsigned integer with a given length-indicator.
193
- *
200
+ *
194
201
* @param length the length indicator to use;
195
202
* @param breakAllowed whether break is allowed.
196
203
* @return the read unsigned integer, as long value.
@@ -219,7 +226,7 @@ protected long readUInt(int length, boolean breakAllowed) throws IOException {
219
226
220
227
/**
221
228
* Reads an unsigned 16-bit integer value
222
- *
229
+ *
223
230
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
224
231
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
225
232
*/
@@ -230,7 +237,7 @@ protected int readUInt16() throws IOException {
230
237
231
238
/**
232
239
* Reads an unsigned 32-bit integer value
233
- *
240
+ *
234
241
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
235
242
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
236
243
*/
@@ -241,7 +248,7 @@ protected long readUInt32() throws IOException {
241
248
242
249
/**
243
250
* Reads an unsigned 64-bit integer value
244
- *
251
+ *
245
252
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
246
253
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
247
254
*/
@@ -253,7 +260,7 @@ protected long readUInt64() throws IOException {
253
260
254
261
/**
255
262
* Reads an unsigned 8-bit integer value
256
- *
263
+ *
257
264
* @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
258
265
* @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
259
266
*/
0 commit comments