48
48
import java .util .stream .Collectors ;
49
49
import java .util .stream .Stream ;
50
50
51
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3AvailableReleasesJSON ;
52
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3BinaryJSON ;
53
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3InstallerJSON ;
54
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3ListBinaryAssetViewJSON ;
55
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3PackageJSON ;
56
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3ReleaseJSON ;
57
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3ReleaseNamesJSON ;
58
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3ReleaseVersionJSON ;
59
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3ReleaseVersionsJSON ;
60
+ import static net .adoptopenjdk .v3 .vanilla .internal .AOV3AST .AOV3SourceJSON ;
61
+
51
62
public final class AOV3ResponseParser implements AOV3ResponseParserType
52
63
{
53
64
private static final Logger LOG =
@@ -75,7 +86,7 @@ public AOV3ResponseParser(
75
86
}
76
87
77
88
private static AOV3Binary toBinary (
78
- final AOV3AST . AOV3BinaryJSON binary )
89
+ final AOV3BinaryJSON binary )
79
90
{
80
91
final var architecture =
81
92
AOV3Architecture .of (
@@ -134,7 +145,7 @@ private static AOV3Binary toBinary(
134
145
}
135
146
136
147
private static AOV3Installer toInstaller (
137
- final AOV3AST . AOV3InstallerJSON installer )
148
+ final AOV3InstallerJSON installer )
138
149
{
139
150
final var checksum =
140
151
Optional .ofNullable (installer .checksum );
@@ -165,7 +176,7 @@ private static AOV3Installer toInstaller(
165
176
}
166
177
167
178
private static AOV3Package toPackage (
168
- final AOV3AST . AOV3PackageJSON package_ )
179
+ final AOV3PackageJSON package_ )
169
180
{
170
181
final var checksum =
171
182
Optional .ofNullable (package_ .checksum );
@@ -194,7 +205,7 @@ private static AOV3Package toPackage(
194
205
}
195
206
196
207
private static AOV3VersionData toVersionData (
197
- final AOV3AST . AOV3ReleaseVersionJSON versionData )
208
+ final AOV3ReleaseVersionJSON versionData )
198
209
{
199
210
return AOV3VersionData .builder ()
200
211
.setAdoptBuildNumber (versionData .adoptBuildNumber )
@@ -222,7 +233,7 @@ private static OffsetDateTime toOffsetDateTime(
222
233
}
223
234
224
235
private static AOV3Source toSource (
225
- final AOV3AST . AOV3SourceJSON source )
236
+ final AOV3SourceJSON source )
226
237
{
227
238
return AOV3Source .builder ()
228
239
.setLink (source .link )
@@ -232,7 +243,7 @@ private static AOV3Source toSource(
232
243
}
233
244
234
245
private AOV3Release toRelease (
235
- final AOV3AST . AOV3ReleaseJSON release )
246
+ final AOV3ReleaseJSON release )
236
247
{
237
248
final var builder = AOV3Release .builder ();
238
249
@@ -296,17 +307,18 @@ private AOV3Release toRelease(
296
307
public AOV3AvailableReleases parseAvailableReleases ()
297
308
throws AOV3ExceptionParseFailed
298
309
{
299
- try {
300
- final AOV3AST . AOV3AvailableReleasesJSON ast =
301
- this . objectMapper . readerFor ( AOV3AST . AOV3AvailableReleasesJSON . class )
302
- . readValue (this . stream );
310
+ final var factory = this . objectMapper . getFactory ();
311
+ try ( final var parser = factory . createParser ( this . stream )) {
312
+ final var ast =
313
+ this . objectMapper . readValue (parser , AOV3AvailableReleasesJSON . class );
303
314
304
315
return AOV3AvailableReleases .builder ()
305
316
.addAllAvailableLTSReleases (ast .availableLTSReleases )
306
317
.addAllAvailableReleases (ast .availableReleases )
307
318
.setMostRecentFeatureRelease (ast .mostRecentFeatureRelease )
308
319
.setMostRecentLTSRelease (ast .mostRecentLTS )
309
320
.build ();
321
+
310
322
} catch (final IOException e ) {
311
323
throw new AOV3ExceptionParseFailed (e );
312
324
}
@@ -316,11 +328,10 @@ public AOV3AvailableReleases parseAvailableReleases()
316
328
public List <String > parseReleaseNames ()
317
329
throws AOV3ExceptionParseFailed
318
330
{
319
- try {
320
- final AOV3AST .AOV3ReleaseNamesJSON ast =
321
- this .objectMapper .readerFor (AOV3AST .AOV3ReleaseNamesJSON .class )
322
- .readValue (this .stream );
323
-
331
+ final var factory = this .objectMapper .getFactory ();
332
+ try (final var parser = factory .createParser (this .stream )) {
333
+ final var ast =
334
+ this .objectMapper .readValue (parser , AOV3ReleaseNamesJSON .class );
324
335
return List .copyOf (ast .releases );
325
336
} catch (final IOException e ) {
326
337
throw new AOV3ExceptionParseFailed (e );
@@ -331,10 +342,10 @@ public List<String> parseReleaseNames()
331
342
public List <AOV3VersionData > parseReleaseVersions ()
332
343
throws AOV3ExceptionParseFailed
333
344
{
334
- try {
335
- final AOV3AST . AOV3ReleaseVersionsJSON ast =
336
- this . objectMapper . readerFor ( AOV3AST . AOV3ReleaseVersionsJSON . class )
337
- . readValue (this . stream );
345
+ final var factory = this . objectMapper . getFactory ();
346
+ try ( final var parser = factory . createParser ( this . stream )) {
347
+ final AOV3ReleaseVersionsJSON ast =
348
+ this . objectMapper . readValue (parser , AOV3ReleaseVersionsJSON . class );
338
349
339
350
return ast .versions .stream ()
340
351
.flatMap (this ::tryToVersionData )
@@ -345,7 +356,7 @@ public List<AOV3VersionData> parseReleaseVersions()
345
356
}
346
357
347
358
private Stream <? extends AOV3VersionData > tryToVersionData (
348
- final AOV3AST . AOV3ReleaseVersionJSON version )
359
+ final AOV3ReleaseVersionJSON version )
349
360
{
350
361
try {
351
362
return Stream .of (toVersionData (version ));
@@ -367,11 +378,15 @@ private Stream<? extends AOV3VersionData> tryToVersionData(
367
378
public List <AOV3Release > parseAssetsForRelease ()
368
379
throws AOV3ExceptionParseFailed
369
380
{
370
- try {
371
- final List <AOV3AST .AOV3ReleaseJSON > ast =
372
- this .objectMapper .readerFor (new TypeReference <List <AOV3AST .AOV3ReleaseJSON >>()
373
- {
374
- }).readValue (this .stream );
381
+ final var factory = this .objectMapper .getFactory ();
382
+ try (final var parser = factory .createParser (this .stream )) {
383
+ final TypeReference <List <AOV3ReleaseJSON >> typeReference =
384
+ new TypeReference <>()
385
+ {
386
+ };
387
+
388
+ final List <AOV3ReleaseJSON > ast =
389
+ this .objectMapper .readValue (parser , typeReference );
375
390
376
391
return ast .stream ()
377
392
.flatMap (this ::tryToRelease )
@@ -385,11 +400,15 @@ public List<AOV3Release> parseAssetsForRelease()
385
400
public List <AOV3ListBinaryAssetView > parseAssetsForLatest ()
386
401
throws AOV3ExceptionParseFailed
387
402
{
388
- try {
389
- final List <AOV3AST .AOV3ListBinaryAssetViewJSON > ast =
390
- this .objectMapper .readerFor (new TypeReference <List <AOV3AST .AOV3ListBinaryAssetViewJSON >>()
391
- {
392
- }).readValue (this .stream );
403
+ final var factory = this .objectMapper .getFactory ();
404
+ try (final var parser = factory .createParser (this .stream )) {
405
+ final TypeReference <List <AOV3ListBinaryAssetViewJSON >> typeReference =
406
+ new TypeReference <>()
407
+ {
408
+ };
409
+
410
+ final List <AOV3ListBinaryAssetViewJSON > ast =
411
+ this .objectMapper .readValue (parser , typeReference );
393
412
394
413
return ast .stream ()
395
414
.flatMap (this ::tryToListBinaryAssetView )
@@ -400,7 +419,7 @@ public List<AOV3ListBinaryAssetView> parseAssetsForLatest()
400
419
}
401
420
402
421
private Stream <? extends AOV3ListBinaryAssetView > tryToListBinaryAssetView (
403
- final AOV3AST . AOV3ListBinaryAssetViewJSON view )
422
+ final AOV3ListBinaryAssetViewJSON view )
404
423
{
405
424
try {
406
425
return Stream .of (toListBinaryAssetView (view ));
@@ -418,7 +437,7 @@ private Stream<? extends AOV3ListBinaryAssetView> tryToListBinaryAssetView(
418
437
}
419
438
420
439
private static AOV3ListBinaryAssetView toListBinaryAssetView (
421
- final AOV3AST . AOV3ListBinaryAssetViewJSON view )
440
+ final AOV3ListBinaryAssetViewJSON view )
422
441
{
423
442
final var builder = AOV3ListBinaryAssetView .builder ();
424
443
@@ -431,7 +450,7 @@ private static AOV3ListBinaryAssetView toListBinaryAssetView(
431
450
}
432
451
433
452
private Stream <? extends AOV3Release > tryToRelease (
434
- final AOV3AST . AOV3ReleaseJSON release )
453
+ final AOV3ReleaseJSON release )
435
454
{
436
455
try {
437
456
return Stream .of (this .toRelease (release ));
0 commit comments