@@ -948,6 +948,22 @@ public static class OutOfSpaceException extends IOException {
948
948
OutOfSpaceException (String explanationMessage , Throwable cause ) {
949
949
super (MESSAGE + ": " + explanationMessage , cause );
950
950
}
951
+
952
+ OutOfSpaceException (int position , int limit , int length ) {
953
+ this (position , limit , length , null );
954
+ }
955
+
956
+ OutOfSpaceException (int position , int limit , int length , Throwable cause ) {
957
+ this ((long ) position , (long ) limit , length , cause );
958
+ }
959
+
960
+ OutOfSpaceException (long position , long limit , int length ) {
961
+ this (position , limit , length , null );
962
+ }
963
+
964
+ OutOfSpaceException (long position , long limit , int length , Throwable cause ) {
965
+ this (String .format ("Pos: %d, limit: %d, len: %d" , position , limit , length ), cause );
966
+ }
951
967
}
952
968
953
969
/**
@@ -1310,8 +1326,7 @@ public final void write(byte value) throws IOException {
1310
1326
try {
1311
1327
buffer [position ++] = value ;
1312
1328
} catch (IndexOutOfBoundsException e ) {
1313
- throw new OutOfSpaceException (
1314
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ), e );
1329
+ throw new OutOfSpaceException (position , limit , 1 , e );
1315
1330
}
1316
1331
this .position = position ; // Only update position if we stayed within the array bounds.
1317
1332
}
@@ -1339,8 +1354,7 @@ public final void writeUInt32NoTag(int value) throws IOException {
1339
1354
}
1340
1355
}
1341
1356
} catch (IndexOutOfBoundsException e ) {
1342
- throw new OutOfSpaceException (
1343
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ), e );
1357
+ throw new OutOfSpaceException (position , limit , 1 , e );
1344
1358
}
1345
1359
}
1346
1360
@@ -1353,8 +1367,7 @@ public final void writeFixed32NoTag(int value) throws IOException {
1353
1367
buffer [position + 2 ] = (byte ) ((value >> 16 ) & 0xFF );
1354
1368
buffer [position + 3 ] = (byte ) ((value >> 24 ) & 0xFF );
1355
1369
} catch (IndexOutOfBoundsException e ) {
1356
- throw new OutOfSpaceException (
1357
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , FIXED32_SIZE ), e );
1370
+ throw new OutOfSpaceException (position , limit , FIXED32_SIZE , e );
1358
1371
}
1359
1372
// Only update position if we stayed within the array bounds.
1360
1373
this .position = position + FIXED32_SIZE ;
@@ -1384,8 +1397,7 @@ public final void writeUInt64NoTag(long value) throws IOException {
1384
1397
}
1385
1398
}
1386
1399
} catch (IndexOutOfBoundsException e ) {
1387
- throw new OutOfSpaceException (
1388
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ), e );
1400
+ throw new OutOfSpaceException (position , limit , 1 , e );
1389
1401
}
1390
1402
}
1391
1403
}
@@ -1403,8 +1415,7 @@ public final void writeFixed64NoTag(long value) throws IOException {
1403
1415
buffer [position + 6 ] = (byte ) ((int ) (value >> 48 ) & 0xFF );
1404
1416
buffer [position + 7 ] = (byte ) ((int ) (value >> 56 ) & 0xFF );
1405
1417
} catch (IndexOutOfBoundsException e ) {
1406
- throw new OutOfSpaceException (
1407
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , FIXED64_SIZE ), e );
1418
+ throw new OutOfSpaceException (position , limit , FIXED64_SIZE , e );
1408
1419
}
1409
1420
// Only update position if we stayed within the array bounds.
1410
1421
this .position = position + FIXED64_SIZE ;
@@ -1416,8 +1427,7 @@ public final void write(byte[] value, int offset, int length) throws IOException
1416
1427
System .arraycopy (value , offset , buffer , position , length );
1417
1428
position += length ;
1418
1429
} catch (IndexOutOfBoundsException e ) {
1419
- throw new OutOfSpaceException (
1420
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , length ), e );
1430
+ throw new OutOfSpaceException (position , limit , length , e );
1421
1431
}
1422
1432
}
1423
1433
@@ -1433,8 +1443,7 @@ public final void write(ByteBuffer value) throws IOException {
1433
1443
value .get (buffer , position , length );
1434
1444
position += length ;
1435
1445
} catch (IndexOutOfBoundsException e ) {
1436
- throw new OutOfSpaceException (
1437
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , length ), e );
1446
+ throw new OutOfSpaceException (position , limit , length , e );
1438
1447
}
1439
1448
}
1440
1449
@@ -1981,8 +1990,7 @@ void writeMessageNoTag(MessageLite value, Schema schema) throws IOException {
1981
1990
@ Override
1982
1991
public void write (byte value ) throws IOException {
1983
1992
if (position >= limit ) {
1984
- throw new OutOfSpaceException (
1985
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ));
1993
+ throw new OutOfSpaceException (position , limit , 1 );
1986
1994
}
1987
1995
UnsafeUtil .putByte (position ++, value );
1988
1996
}
@@ -2043,8 +2051,7 @@ public void writeUInt32NoTag(int value) throws IOException {
2043
2051
value >>>= 7 ;
2044
2052
}
2045
2053
}
2046
- throw new OutOfSpaceException (
2047
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ));
2054
+ throw new OutOfSpaceException (position , limit , 1 );
2048
2055
}
2049
2056
}
2050
2057
@@ -2053,8 +2060,7 @@ public void writeFixed32NoTag(int value) throws IOException {
2053
2060
try {
2054
2061
buffer .putInt (bufferPos (position ), value );
2055
2062
} catch (IndexOutOfBoundsException e ) {
2056
- throw new OutOfSpaceException (
2057
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , FIXED32_SIZE ), e );
2063
+ throw new OutOfSpaceException (position , limit , FIXED32_SIZE , e );
2058
2064
}
2059
2065
position += FIXED32_SIZE ;
2060
2066
}
@@ -2082,8 +2088,7 @@ public void writeUInt64NoTag(long value) throws IOException {
2082
2088
value >>>= 7 ;
2083
2089
}
2084
2090
}
2085
- throw new OutOfSpaceException (
2086
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , 1 ));
2091
+ throw new OutOfSpaceException (position , limit , 1 );
2087
2092
}
2088
2093
}
2089
2094
@@ -2092,8 +2097,7 @@ public void writeFixed64NoTag(long value) throws IOException {
2092
2097
try {
2093
2098
buffer .putLong (bufferPos (position ), value );
2094
2099
} catch (IndexOutOfBoundsException e ) {
2095
- throw new OutOfSpaceException (
2096
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , FIXED64_SIZE ), e );
2100
+ throw new OutOfSpaceException (position , limit , FIXED64_SIZE , e );
2097
2101
}
2098
2102
position += FIXED64_SIZE ;
2099
2103
}
@@ -2108,8 +2112,7 @@ public void write(byte[] value, int offset, int length) throws IOException {
2108
2112
if (value == null ) {
2109
2113
throw new NullPointerException ("value" );
2110
2114
}
2111
- throw new OutOfSpaceException (
2112
- String .format ("Pos: %d, limit: %d, len: %d" , position , limit , length ));
2115
+ throw new OutOfSpaceException (position , limit , length );
2113
2116
}
2114
2117
2115
2118
UnsafeUtil .copyMemory (value , offset , position , length );
0 commit comments