@@ -34,11 +34,11 @@ class Decoder {
3434
3535 private final CharsetDecoder utfDecoder = UTF_8 .newDecoder ();
3636
37- private final ByteBuffer buffer ;
37+ private final Buffer buffer ;
3838
3939 private final ConcurrentHashMap <Class <?>, CachedConstructor <?>> constructors ;
4040
41- Decoder (NodeCache cache , ByteBuffer buffer , long pointerBase ) {
41+ Decoder (NodeCache cache , Buffer buffer , long pointerBase ) {
4242 this (
4343 cache ,
4444 buffer ,
@@ -49,7 +49,7 @@ class Decoder {
4949
5050 Decoder (
5151 NodeCache cache ,
52- ByteBuffer buffer ,
52+ Buffer buffer ,
5353 long pointerBase ,
5454 ConcurrentHashMap <Class <?>, CachedConstructor <?>> constructors
5555 ) {
@@ -61,7 +61,7 @@ class Decoder {
6161
6262 private final NodeCache .Loader cacheLoader = this ::decode ;
6363
64- <T > T decode (int offset , Class <T > cls ) throws IOException {
64+ <T > T decode (long offset , Class <T > cls ) throws IOException {
6565 if (offset >= this .buffer .capacity ()) {
6666 throw new InvalidDatabaseException (
6767 "The MaxMind DB file's data section contains bad data: "
@@ -73,7 +73,7 @@ <T> T decode(int offset, Class<T> cls) throws IOException {
7373 }
7474
7575 private <T > DecodedValue decode (CacheKey <T > key ) throws IOException {
76- int offset = key .offset ();
76+ long offset = key .offset ();
7777 if (offset >= this .buffer .capacity ()) {
7878 throw new InvalidDatabaseException (
7979 "The MaxMind DB file's data section contains bad data: "
@@ -132,8 +132,8 @@ private <T> DecodedValue decode(Class<T> cls, java.lang.reflect.Type genericType
132132
133133 DecodedValue decodePointer (long pointer , Class <?> cls , java .lang .reflect .Type genericType )
134134 throws IOException {
135- int targetOffset = ( int ) pointer ;
136- int position = buffer .position ();
135+ long targetOffset = pointer ;
136+ long position = buffer .position ();
137137
138138 CacheKey <?> key = new CacheKey <>(targetOffset , cls , genericType );
139139 DecodedValue o = cache .get (key , cacheLoader );
@@ -185,10 +185,10 @@ private <T> Object decodeByType(
185185 }
186186 }
187187
188- private String decodeString (int size ) throws CharacterCodingException {
189- int oldLimit = buffer .limit ();
188+ private String decodeString (long size ) throws CharacterCodingException {
189+ long oldLimit = buffer .limit ();
190190 buffer .limit (buffer .position () + size );
191- String s = utfDecoder .decode (buffer ). toString ( );
191+ String s = buffer .decode (utfDecoder );
192192 buffer .limit (oldLimit );
193193 return s ;
194194 }
@@ -202,9 +202,13 @@ private int decodeInt32(int size) {
202202 }
203203
204204 private long decodeLong (int size ) {
205- long integer = 0 ;
205+ return Decoder .decodeLong (this .buffer , 0 , size );
206+ }
207+
208+ static long decodeLong (Buffer buffer , int base , int size ) {
209+ long integer = base ;
206210 for (int i = 0 ; i < size ; i ++) {
207- integer = (integer << 8 ) | (this . buffer .get () & 0xFF );
211+ integer = (integer << 8 ) | (buffer .get () & 0xFF );
208212 }
209213 return integer ;
210214 }
@@ -221,7 +225,7 @@ private int decodeInteger(int base, int size) {
221225 return Decoder .decodeInteger (this .buffer , base , size );
222226 }
223227
224- static int decodeInteger (ByteBuffer buffer , int base , int size ) {
228+ static int decodeInteger (Buffer buffer , int base , int size ) {
225229 int integer = base ;
226230 for (int i = 0 ; i < size ; i ++) {
227231 integer = (integer << 8 ) | (buffer .get () & 0xFF );
@@ -412,7 +416,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
412416
413417 Integer parameterIndex = parameterIndexes .get (key );
414418 if (parameterIndex == null ) {
415- int offset = this .nextValueOffset (this .buffer .position (), 1 );
419+ long offset = this .nextValueOffset (this .buffer .position (), 1 );
416420 this .buffer .position (offset );
417421 continue ;
418422 }
@@ -485,7 +489,7 @@ private static <T> String getParameterName(
485489 + " is not annotated with MaxMindDbParameter." );
486490 }
487491
488- private int nextValueOffset (int offset , int numberToSkip )
492+ private long nextValueOffset (long offset , int numberToSkip )
489493 throws InvalidDatabaseException {
490494 if (numberToSkip == 0 ) {
491495 return offset ;
@@ -518,7 +522,7 @@ private int nextValueOffset(int offset, int numberToSkip)
518522 return nextValueOffset (offset , numberToSkip - 1 );
519523 }
520524
521- private CtrlData getCtrlData (int offset )
525+ private CtrlData getCtrlData (long offset )
522526 throws InvalidDatabaseException {
523527 if (offset >= this .buffer .capacity ()) {
524528 throw new InvalidDatabaseException (
@@ -566,7 +570,7 @@ private byte[] getByteArray(int length) {
566570 return Decoder .getByteArray (this .buffer , length );
567571 }
568572
569- private static byte [] getByteArray (ByteBuffer buffer , int length ) {
573+ private static byte [] getByteArray (Buffer buffer , int length ) {
570574 byte [] bytes = new byte [length ];
571575 buffer .get (bytes );
572576 return bytes ;
0 commit comments