3
3
*
4
4
* DO NOT EDIT DIRECTLY
5
5
*/
6
- package com .baeldung .apache .avro .model ;
6
+ package com .baeldung .apache .avro .generated ;
7
7
8
+ import org .apache .avro .generic .GenericArray ;
8
9
import org .apache .avro .specific .SpecificData ;
10
+ import org .apache .avro .util .Utf8 ;
9
11
import org .apache .avro .message .BinaryMessageEncoder ;
10
12
import org .apache .avro .message .BinaryMessageDecoder ;
11
13
import org .apache .avro .message .SchemaStore ;
12
14
13
- @ SuppressWarnings ("all" )
14
15
@ org .apache .avro .specific .AvroGenerated
15
16
public class ClientIdentifier extends org .apache .avro .specific .SpecificRecordBase implements org .apache .avro .specific .SpecificRecord {
16
- private static final long serialVersionUID = 8754570983127295424L ;
17
- public static final org .apache .avro .Schema SCHEMA$ = new org .apache .avro .Schema .Parser ().parse ("{\" type\" :\" record\" ,\" name\" :\" ClientIdentifier\" ,\" namespace\" :\" com.baeldung.avro.model\" ,\" fields\" :[{\" name\" :\" hostName\" ,\" type\" :\" string\" },{\" name\" :\" ipAddress\" ,\" type\" :\" string\" }]}" );
17
+ private static final long serialVersionUID = -1549393766288162557L ;
18
+
19
+
20
+ public static final org .apache .avro .Schema SCHEMA$ = new org .apache .avro .Schema .Parser ().parse ("{\" type\" :\" record\" ,\" name\" :\" ClientIdentifier\" ,\" namespace\" :\" com.baeldung.apache.avro.generated\" ,\" fields\" :[{\" name\" :\" hostName\" ,\" type\" :{\" type\" :\" string\" ,\" avro.java.string\" :\" String\" }},{\" name\" :\" ipAddress\" ,\" type\" :{\" type\" :\" string\" ,\" avro.java.string\" :\" String\" }}]}" );
18
21
public static org .apache .avro .Schema getClassSchema () { return SCHEMA$ ; }
19
22
20
- private static SpecificData MODEL$ = new SpecificData ();
23
+ private static final SpecificData MODEL$ = new SpecificData ();
21
24
22
25
private static final BinaryMessageEncoder <ClientIdentifier > ENCODER =
23
- new BinaryMessageEncoder <ClientIdentifier >(MODEL$ , SCHEMA$ );
26
+ new BinaryMessageEncoder <>(MODEL$ , SCHEMA$ );
24
27
25
28
private static final BinaryMessageDecoder <ClientIdentifier > DECODER =
26
- new BinaryMessageDecoder <ClientIdentifier >(MODEL$ , SCHEMA$ );
29
+ new BinaryMessageDecoder <>(MODEL$ , SCHEMA$ );
30
+
31
+ /**
32
+ * Return the BinaryMessageEncoder instance used by this class.
33
+ * @return the message encoder used by this class
34
+ */
35
+ public static BinaryMessageEncoder <ClientIdentifier > getEncoder () {
36
+ return ENCODER ;
37
+ }
27
38
28
39
/**
29
40
* Return the BinaryMessageDecoder instance used by this class.
41
+ * @return the message decoder used by this class
30
42
*/
31
43
public static BinaryMessageDecoder <ClientIdentifier > getDecoder () {
32
44
return DECODER ;
@@ -35,24 +47,34 @@ public static BinaryMessageDecoder<ClientIdentifier> getDecoder() {
35
47
/**
36
48
* Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
37
49
* @param resolver a {@link SchemaStore} used to find schemas by fingerprint
50
+ * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
38
51
*/
39
52
public static BinaryMessageDecoder <ClientIdentifier > createDecoder (SchemaStore resolver ) {
40
- return new BinaryMessageDecoder <ClientIdentifier >(MODEL$ , SCHEMA$ , resolver );
53
+ return new BinaryMessageDecoder <>(MODEL$ , SCHEMA$ , resolver );
41
54
}
42
55
43
- /** Serializes this ClientIdentifier to a ByteBuffer. */
56
+ /**
57
+ * Serializes this ClientIdentifier to a ByteBuffer.
58
+ * @return a buffer holding the serialized data for this instance
59
+ * @throws java.io.IOException if this instance could not be serialized
60
+ */
44
61
public java .nio .ByteBuffer toByteBuffer () throws java .io .IOException {
45
62
return ENCODER .encode (this );
46
63
}
47
64
48
- /** Deserializes a ClientIdentifier from a ByteBuffer. */
65
+ /**
66
+ * Deserializes a ClientIdentifier from a ByteBuffer.
67
+ * @param b a byte buffer holding serialized data for an instance of this class
68
+ * @return a ClientIdentifier instance decoded from the given buffer
69
+ * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
70
+ */
49
71
public static ClientIdentifier fromByteBuffer (
50
72
java .nio .ByteBuffer b ) throws java .io .IOException {
51
73
return DECODER .decode (b );
52
74
}
53
75
54
- @ Deprecated public java .lang .CharSequence hostName ;
55
- @ Deprecated public java .lang .CharSequence ipAddress ;
76
+ private java .lang .String hostName ;
77
+ private java .lang .String ipAddress ;
56
78
57
79
/**
58
80
* Default constructor. Note that this does not initialize fields
@@ -66,125 +88,143 @@ public ClientIdentifier() {}
66
88
* @param hostName The new value for hostName
67
89
* @param ipAddress The new value for ipAddress
68
90
*/
69
- public ClientIdentifier (java .lang .CharSequence hostName , java .lang .CharSequence ipAddress ) {
91
+ public ClientIdentifier (java .lang .String hostName , java .lang .String ipAddress ) {
70
92
this .hostName = hostName ;
71
93
this .ipAddress = ipAddress ;
72
94
}
73
95
96
+ @ Override
97
+ public org .apache .avro .specific .SpecificData getSpecificData () { return MODEL$ ; }
98
+
99
+ @ Override
74
100
public org .apache .avro .Schema getSchema () { return SCHEMA$ ; }
101
+
75
102
// Used by DatumWriter. Applications should not call.
103
+ @ Override
76
104
public java .lang .Object get (int field$ ) {
77
105
switch (field$ ) {
78
106
case 0 : return hostName ;
79
107
case 1 : return ipAddress ;
80
- default : throw new org . apache . avro . AvroRuntimeException ( "Bad index" );
108
+ default : throw new IndexOutOfBoundsException ( "Invalid index: " + field$ );
81
109
}
82
110
}
83
111
84
112
// Used by DatumReader. Applications should not call.
113
+ @ Override
85
114
@ SuppressWarnings (value ="unchecked" )
86
115
public void put (int field$ , java .lang .Object value$ ) {
87
116
switch (field$ ) {
88
- case 0 : hostName = ( java . lang . CharSequence ) value$ ; break ;
89
- case 1 : ipAddress = ( java . lang . CharSequence ) value$ ; break ;
90
- default : throw new org . apache . avro . AvroRuntimeException ( "Bad index" );
117
+ case 0 : hostName = value$ != null ? value$ . toString () : null ; break ;
118
+ case 1 : ipAddress = value$ != null ? value$ . toString () : null ; break ;
119
+ default : throw new IndexOutOfBoundsException ( "Invalid index: " + field$ );
91
120
}
92
121
}
93
122
94
123
/**
95
124
* Gets the value of the 'hostName' field.
96
125
* @return The value of the 'hostName' field.
97
126
*/
98
- public java .lang .CharSequence getHostName () {
127
+ public java .lang .String getHostName () {
99
128
return hostName ;
100
129
}
101
130
131
+
102
132
/**
103
133
* Sets the value of the 'hostName' field.
104
134
* @param value the value to set.
105
135
*/
106
- public void setHostName (java .lang .CharSequence value ) {
136
+ public void setHostName (java .lang .String value ) {
107
137
this .hostName = value ;
108
138
}
109
139
110
140
/**
111
141
* Gets the value of the 'ipAddress' field.
112
142
* @return The value of the 'ipAddress' field.
113
143
*/
114
- public java .lang .CharSequence getIpAddress () {
144
+ public java .lang .String getIpAddress () {
115
145
return ipAddress ;
116
146
}
117
147
148
+
118
149
/**
119
150
* Sets the value of the 'ipAddress' field.
120
151
* @param value the value to set.
121
152
*/
122
- public void setIpAddress (java .lang .CharSequence value ) {
153
+ public void setIpAddress (java .lang .String value ) {
123
154
this .ipAddress = value ;
124
155
}
125
156
126
157
/**
127
158
* Creates a new ClientIdentifier RecordBuilder.
128
159
* @return A new ClientIdentifier RecordBuilder
129
160
*/
130
- public static ClientIdentifier .Builder newBuilder () {
131
- return new ClientIdentifier .Builder ();
161
+ public static com . baeldung . apache . avro . generated . ClientIdentifier .Builder newBuilder () {
162
+ return new com . baeldung . apache . avro . generated . ClientIdentifier .Builder ();
132
163
}
133
164
134
165
/**
135
166
* Creates a new ClientIdentifier RecordBuilder by copying an existing Builder.
136
167
* @param other The existing builder to copy.
137
168
* @return A new ClientIdentifier RecordBuilder
138
169
*/
139
- public static ClientIdentifier .Builder newBuilder (ClientIdentifier .Builder other ) {
140
- return new ClientIdentifier .Builder (other );
170
+ public static com .baeldung .apache .avro .generated .ClientIdentifier .Builder newBuilder (com .baeldung .apache .avro .generated .ClientIdentifier .Builder other ) {
171
+ if (other == null ) {
172
+ return new com .baeldung .apache .avro .generated .ClientIdentifier .Builder ();
173
+ } else {
174
+ return new com .baeldung .apache .avro .generated .ClientIdentifier .Builder (other );
175
+ }
141
176
}
142
177
143
178
/**
144
179
* Creates a new ClientIdentifier RecordBuilder by copying an existing ClientIdentifier instance.
145
180
* @param other The existing instance to copy.
146
181
* @return A new ClientIdentifier RecordBuilder
147
182
*/
148
- public static ClientIdentifier .Builder newBuilder (ClientIdentifier other ) {
149
- return new ClientIdentifier .Builder (other );
183
+ public static com .baeldung .apache .avro .generated .ClientIdentifier .Builder newBuilder (com .baeldung .apache .avro .generated .ClientIdentifier other ) {
184
+ if (other == null ) {
185
+ return new com .baeldung .apache .avro .generated .ClientIdentifier .Builder ();
186
+ } else {
187
+ return new com .baeldung .apache .avro .generated .ClientIdentifier .Builder (other );
188
+ }
150
189
}
151
190
152
191
/**
153
192
* RecordBuilder for ClientIdentifier instances.
154
193
*/
194
+ @ org .apache .avro .specific .AvroGenerated
155
195
public static class Builder extends org .apache .avro .specific .SpecificRecordBuilderBase <ClientIdentifier >
156
196
implements org .apache .avro .data .RecordBuilder <ClientIdentifier > {
157
197
158
- private java .lang .CharSequence hostName ;
159
- private java .lang .CharSequence ipAddress ;
198
+ private java .lang .String hostName ;
199
+ private java .lang .String ipAddress ;
160
200
161
201
/** Creates a new Builder */
162
202
private Builder () {
163
- super (SCHEMA$ );
203
+ super (SCHEMA$ , MODEL$ );
164
204
}
165
205
166
206
/**
167
207
* Creates a Builder by copying an existing Builder.
168
208
* @param other The existing Builder to copy.
169
209
*/
170
- private Builder (ClientIdentifier .Builder other ) {
210
+ private Builder (com . baeldung . apache . avro . generated . ClientIdentifier .Builder other ) {
171
211
super (other );
172
212
if (isValidValue (fields ()[0 ], other .hostName )) {
173
213
this .hostName = data ().deepCopy (fields ()[0 ].schema (), other .hostName );
174
- fieldSetFlags ()[0 ] = true ;
214
+ fieldSetFlags ()[0 ] = other . fieldSetFlags ()[ 0 ] ;
175
215
}
176
216
if (isValidValue (fields ()[1 ], other .ipAddress )) {
177
217
this .ipAddress = data ().deepCopy (fields ()[1 ].schema (), other .ipAddress );
178
- fieldSetFlags ()[1 ] = true ;
218
+ fieldSetFlags ()[1 ] = other . fieldSetFlags ()[ 1 ] ;
179
219
}
180
220
}
181
221
182
222
/**
183
223
* Creates a Builder by copying an existing ClientIdentifier instance
184
224
* @param other The existing instance to copy.
185
225
*/
186
- private Builder (ClientIdentifier other ) {
187
- super (SCHEMA$ );
226
+ private Builder (com . baeldung . apache . avro . generated . ClientIdentifier other ) {
227
+ super (SCHEMA$ , MODEL $ );
188
228
if (isValidValue (fields ()[0 ], other .hostName )) {
189
229
this .hostName = data ().deepCopy (fields ()[0 ].schema (), other .hostName );
190
230
fieldSetFlags ()[0 ] = true ;
@@ -199,16 +239,17 @@ private Builder(ClientIdentifier other) {
199
239
* Gets the value of the 'hostName' field.
200
240
* @return The value.
201
241
*/
202
- public java .lang .CharSequence getHostName () {
242
+ public java .lang .String getHostName () {
203
243
return hostName ;
204
244
}
205
245
246
+
206
247
/**
207
248
* Sets the value of the 'hostName' field.
208
249
* @param value The value of 'hostName'.
209
250
* @return This builder.
210
251
*/
211
- public ClientIdentifier .Builder setHostName (java .lang .CharSequence value ) {
252
+ public com . baeldung . apache . avro . generated . ClientIdentifier .Builder setHostName (java .lang .String value ) {
212
253
validate (fields ()[0 ], value );
213
254
this .hostName = value ;
214
255
fieldSetFlags ()[0 ] = true ;
@@ -228,7 +269,7 @@ public boolean hasHostName() {
228
269
* Clears the value of the 'hostName' field.
229
270
* @return This builder.
230
271
*/
231
- public ClientIdentifier .Builder clearHostName () {
272
+ public com . baeldung . apache . avro . generated . ClientIdentifier .Builder clearHostName () {
232
273
hostName = null ;
233
274
fieldSetFlags ()[0 ] = false ;
234
275
return this ;
@@ -238,16 +279,17 @@ public ClientIdentifier.Builder clearHostName() {
238
279
* Gets the value of the 'ipAddress' field.
239
280
* @return The value.
240
281
*/
241
- public java .lang .CharSequence getIpAddress () {
282
+ public java .lang .String getIpAddress () {
242
283
return ipAddress ;
243
284
}
244
285
286
+
245
287
/**
246
288
* Sets the value of the 'ipAddress' field.
247
289
* @param value The value of 'ipAddress'.
248
290
* @return This builder.
249
291
*/
250
- public ClientIdentifier .Builder setIpAddress (java .lang .CharSequence value ) {
292
+ public com . baeldung . apache . avro . generated . ClientIdentifier .Builder setIpAddress (java .lang .String value ) {
251
293
validate (fields ()[1 ], value );
252
294
this .ipAddress = value ;
253
295
fieldSetFlags ()[1 ] = true ;
@@ -267,7 +309,7 @@ public boolean hasIpAddress() {
267
309
* Clears the value of the 'ipAddress' field.
268
310
* @return This builder.
269
311
*/
270
- public ClientIdentifier .Builder clearIpAddress () {
312
+ public com . baeldung . apache . avro . generated . ClientIdentifier .Builder clearIpAddress () {
271
313
ipAddress = null ;
272
314
fieldSetFlags ()[1 ] = false ;
273
315
return this ;
@@ -278,9 +320,11 @@ public ClientIdentifier.Builder clearIpAddress() {
278
320
public ClientIdentifier build () {
279
321
try {
280
322
ClientIdentifier record = new ClientIdentifier ();
281
- record .hostName = fieldSetFlags ()[0 ] ? this .hostName : (java .lang .CharSequence ) defaultValue (fields ()[0 ]);
282
- record .ipAddress = fieldSetFlags ()[1 ] ? this .ipAddress : (java .lang .CharSequence ) defaultValue (fields ()[1 ]);
323
+ record .hostName = fieldSetFlags ()[0 ] ? this .hostName : (java .lang .String ) defaultValue (fields ()[0 ]);
324
+ record .ipAddress = fieldSetFlags ()[1 ] ? this .ipAddress : (java .lang .String ) defaultValue (fields ()[1 ]);
283
325
return record ;
326
+ } catch (org .apache .avro .AvroMissingFieldException e ) {
327
+ throw e ;
284
328
} catch (java .lang .Exception e ) {
285
329
throw new org .apache .avro .AvroRuntimeException (e );
286
330
}
@@ -305,4 +349,51 @@ public ClientIdentifier build() {
305
349
READER$ .read (this , SpecificData .getDecoder (in ));
306
350
}
307
351
352
+ @ Override protected boolean hasCustomCoders () { return true ; }
353
+
354
+ @ Override public void customEncode (org .apache .avro .io .Encoder out )
355
+ throws java .io .IOException
356
+ {
357
+ out .writeString (this .hostName );
358
+
359
+ out .writeString (this .ipAddress );
360
+
361
+ }
362
+
363
+ @ Override public void customDecode (org .apache .avro .io .ResolvingDecoder in )
364
+ throws java .io .IOException
365
+ {
366
+ org .apache .avro .Schema .Field [] fieldOrder = in .readFieldOrderIfDiff ();
367
+ if (fieldOrder == null ) {
368
+ this .hostName = in .readString ();
369
+
370
+ this .ipAddress = in .readString ();
371
+
372
+ } else {
373
+ for (int i = 0 ; i < 2 ; i ++) {
374
+ switch (fieldOrder [i ].pos ()) {
375
+ case 0 :
376
+ this .hostName = in .readString ();
377
+ break ;
378
+
379
+ case 1 :
380
+ this .ipAddress = in .readString ();
381
+ break ;
382
+
383
+ default :
384
+ throw new java .io .IOException ("Corrupt ResolvingDecoder." );
385
+ }
386
+ }
387
+ }
388
+ }
308
389
}
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
0 commit comments