@@ -2256,55 +2256,6 @@ protected final void _reportInvalidUnsignedVInt(int firstCh, int lastCh) throws
2256
2256
currentToken (), firstCh );
2257
2257
}
2258
2258
2259
- private final byte [] _read7BitBinaryWithLength () throws IOException
2260
- {
2261
- int byteLen = _readUnsignedVInt ();
2262
- byte [] result = new byte [byteLen ];
2263
- int ptr = 0 ;
2264
- int lastOkPtr = byteLen - 7 ;
2265
-
2266
- // first, read all 7-by-8 byte chunks
2267
- while (ptr <= lastOkPtr ) {
2268
- if ((_inputEnd - _inputPtr ) < 8 ) {
2269
- _loadToHaveAtLeast (8 );
2270
- }
2271
- int i1 = (_inputBuffer [_inputPtr ++] << 25 )
2272
- + (_inputBuffer [_inputPtr ++] << 18 )
2273
- + (_inputBuffer [_inputPtr ++] << 11 )
2274
- + (_inputBuffer [_inputPtr ++] << 4 );
2275
- int x = _inputBuffer [_inputPtr ++];
2276
- i1 += x >> 3 ;
2277
- int i2 = ((x & 0x7 ) << 21 )
2278
- + (_inputBuffer [_inputPtr ++] << 14 )
2279
- + (_inputBuffer [_inputPtr ++] << 7 )
2280
- + _inputBuffer [_inputPtr ++];
2281
- // Ok: got our 7 bytes, just need to split, copy
2282
- result [ptr ++] = (byte )(i1 >> 24 );
2283
- result [ptr ++] = (byte )(i1 >> 16 );
2284
- result [ptr ++] = (byte )(i1 >> 8 );
2285
- result [ptr ++] = (byte )i1 ;
2286
- result [ptr ++] = (byte )(i2 >> 16 );
2287
- result [ptr ++] = (byte )(i2 >> 8 );
2288
- result [ptr ++] = (byte )i2 ;
2289
- }
2290
- // and then leftovers: n+1 bytes to decode n bytes
2291
- int toDecode = (result .length - ptr );
2292
- if (toDecode > 0 ) {
2293
- if ((_inputEnd - _inputPtr ) < (toDecode +1 )) {
2294
- _loadToHaveAtLeast (toDecode +1 );
2295
- }
2296
- int value = _inputBuffer [_inputPtr ++];
2297
- for (int i = 1 ; i < toDecode ; ++i ) {
2298
- value = (value << 7 ) + _inputBuffer [_inputPtr ++];
2299
- result [ptr ++] = (byte ) (value >> (7 - i ));
2300
- }
2301
- // last byte is different, has remaining 1 - 6 bits, right-aligned
2302
- value <<= toDecode ;
2303
- result [ptr ] = (byte ) (value + _inputBuffer [_inputPtr ++]);
2304
- }
2305
- return result ;
2306
- }
2307
-
2308
2259
/*
2309
2260
/**********************************************************
2310
2261
/* Internal methods, secondary String parsing
@@ -2484,16 +2435,23 @@ private final void _decodeLongUnicode() throws IOException
2484
2435
_textBuffer .setCurrentLength (outPtr );
2485
2436
}
2486
2437
2438
+ /*
2439
+ /**********************************************************************
2440
+ /* Internal methods, secondary Binary data parsing
2441
+ /**********************************************************************
2442
+ */
2443
+
2487
2444
private final byte [] _finishRawBinary () throws IOException
2488
2445
{
2489
2446
int byteLen = _readUnsignedVInt ();
2490
2447
2491
2448
// 20-Mar-2021, tatu [dataformats-binary#260]: avoid eager allocation
2492
2449
// for very large content
2493
2450
if (byteLen > LONGEST_NON_CHUNKED_BINARY ) {
2494
- return _finishLongContiguousBytes (byteLen );
2451
+ return _finishRawBinaryLong (byteLen );
2495
2452
}
2496
2453
2454
+ // But use simpler, no intermediate buffering, for more compact cases
2497
2455
final int expLen = byteLen ;
2498
2456
final byte [] b = new byte [byteLen ];
2499
2457
@@ -2520,7 +2478,7 @@ private final byte[] _finishRawBinary() throws IOException
2520
2478
}
2521
2479
2522
2480
// @since 2.12.3
2523
- protected byte [] _finishLongContiguousBytes (final int expLen ) throws IOException
2481
+ protected byte [] _finishRawBinaryLong (final int expLen ) throws IOException
2524
2482
{
2525
2483
int left = expLen ;
2526
2484
@@ -2545,6 +2503,58 @@ protected byte[] _finishLongContiguousBytes(final int expLen) throws IOException
2545
2503
}
2546
2504
}
2547
2505
2506
+ // Helper method for reading full contents of a 7-bit (7/8) encoded
2507
+ // binary data chunk: starting with leading leading VInt length indicator
2508
+ // followed by encoded data
2509
+ private final byte [] _read7BitBinaryWithLength () throws IOException
2510
+ {
2511
+ int byteLen = _readUnsignedVInt ();
2512
+ byte [] result = new byte [byteLen ];
2513
+ int ptr = 0 ;
2514
+ int lastOkPtr = byteLen - 7 ;
2515
+
2516
+ // first, read all 7-by-8 byte chunks
2517
+ while (ptr <= lastOkPtr ) {
2518
+ if ((_inputEnd - _inputPtr ) < 8 ) {
2519
+ _loadToHaveAtLeast (8 );
2520
+ }
2521
+ int i1 = (_inputBuffer [_inputPtr ++] << 25 )
2522
+ + (_inputBuffer [_inputPtr ++] << 18 )
2523
+ + (_inputBuffer [_inputPtr ++] << 11 )
2524
+ + (_inputBuffer [_inputPtr ++] << 4 );
2525
+ int x = _inputBuffer [_inputPtr ++];
2526
+ i1 += x >> 3 ;
2527
+ int i2 = ((x & 0x7 ) << 21 )
2528
+ + (_inputBuffer [_inputPtr ++] << 14 )
2529
+ + (_inputBuffer [_inputPtr ++] << 7 )
2530
+ + _inputBuffer [_inputPtr ++];
2531
+ // Ok: got our 7 bytes, just need to split, copy
2532
+ result [ptr ++] = (byte )(i1 >> 24 );
2533
+ result [ptr ++] = (byte )(i1 >> 16 );
2534
+ result [ptr ++] = (byte )(i1 >> 8 );
2535
+ result [ptr ++] = (byte )i1 ;
2536
+ result [ptr ++] = (byte )(i2 >> 16 );
2537
+ result [ptr ++] = (byte )(i2 >> 8 );
2538
+ result [ptr ++] = (byte )i2 ;
2539
+ }
2540
+ // and then leftovers: n+1 bytes to decode n bytes
2541
+ int toDecode = (result .length - ptr );
2542
+ if (toDecode > 0 ) {
2543
+ if ((_inputEnd - _inputPtr ) < (toDecode +1 )) {
2544
+ _loadToHaveAtLeast (toDecode +1 );
2545
+ }
2546
+ int value = _inputBuffer [_inputPtr ++];
2547
+ for (int i = 1 ; i < toDecode ; ++i ) {
2548
+ value = (value << 7 ) + _inputBuffer [_inputPtr ++];
2549
+ result [ptr ++] = (byte ) (value >> (7 - i ));
2550
+ }
2551
+ // last byte is different, has remaining 1 - 6 bits, right-aligned
2552
+ value <<= toDecode ;
2553
+ result [ptr ] = (byte ) (value + _inputBuffer [_inputPtr ++]);
2554
+ }
2555
+ return result ;
2556
+ }
2557
+
2548
2558
/*
2549
2559
/**********************************************************
2550
2560
/* Internal methods, skipping
0 commit comments